wabbajack/Wabbajack.Server/DataLayer/AuthoredFiles.cs

76 lines
3.0 KiB
C#
Raw Normal View History

2020-05-09 22:16:16 +00:00
using System;
2020-05-10 01:35:42 +00:00
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
2020-05-09 22:16:16 +00:00
using System.Linq;
using System.Threading.Tasks;
using Dapper;
2020-05-10 01:35:42 +00:00
using Microsoft.AspNetCore.Mvc.Infrastructure;
using Wabbajack.BuildServer.Controllers;
2020-05-09 22:16:16 +00:00
using Wabbajack.Common;
using Wabbajack.Lib.AuthorApi;
2020-05-10 01:35:42 +00:00
using Wabbajack.Server.DTOs;
2020-05-09 22:16:16 +00:00
namespace Wabbajack.Server.DataLayer
{
public partial class SqlService
{
public async Task TouchAuthoredFile(CDNFileDefinition definition)
{
await using var conn = await Open();
await conn.ExecuteAsync("UPDATE AuthoredFiles SET LastTouched = GETUTCDATE() WHERE ServerAssignedUniqueId = @Uid",
new {
Uid = definition.ServerAssignedUniqueId
});
}
public async Task<CDNFileDefinition> CreateAuthoredFile(CDNFileDefinition definition, string login)
{
definition.Author = login;
var uid = Guid.NewGuid().ToString();
await using var conn = await Open();
definition.ServerAssignedUniqueId = uid;
await conn.ExecuteAsync("INSERT INTO dbo.AuthoredFiles (ServerAssignedUniqueId, LastTouched, CDNFileDefinition) VALUES (@Uid, GETUTCDATE(), @CdnFile)",
new {
Uid = uid,
CdnFile = definition
});
return definition;
}
public async Task Finalize(CDNFileDefinition definition)
{
await using var conn = await Open();
await conn.ExecuteAsync("UPDATE AuthoredFiles SET LastTouched = GETUTCDATE(), Finalized = GETUTCDATE() WHERE ServerAssignedUniqueId = @Uid",
new {
Uid = definition.ServerAssignedUniqueId
});
}
public async Task<CDNFileDefinition> GetCDNFileDefinition(string serverAssignedUniqueId)
{
await using var conn = await Open();
return (await conn.QueryAsync<CDNFileDefinition>(
"SELECT CDNFileDefinition FROM dbo.AuthoredFiles WHERE ServerAssignedUniqueID = @Uid",
new {Uid = serverAssignedUniqueId})).First();
}
public async Task<CDNFileDefinition> DeleteFileDefinition(CDNFileDefinition definition)
{
await using var conn = await Open();
return (await conn.QueryAsync<CDNFileDefinition>(
"DELETE FROM dbo.AuthoredFiles WHERE ServerAssignedUniqueID = @Uid",
new {Uid = definition.ServerAssignedUniqueId})).First();
}
2020-05-10 01:35:42 +00:00
public async Task<IEnumerable<AuthoredFilesSummary>> AllAuthoredFiles()
{
await using var conn = await Open();
var results = await conn.QueryAsync<AuthoredFilesSummary>("SELECT CONVERT(NVARCHAR(50), ServerAssignedUniqueId) as ServerAssignedUniqueId, Size, OriginalFileName, Author, LastTouched, Finalized, MungedName from dbo.AuthoredFilesSummaries ORDER BY LastTouched DESC");
return results;
}
2020-05-09 22:16:16 +00:00
}
}