Merge branch 'Refactor' into new-songs-ui
This commit is contained in:
commit
9144dacf8d
@ -1,51 +0,0 @@
|
|||||||
using GameDatabase.Context;
|
|
||||||
using GameDatabase.Entities;
|
|
||||||
using Throw;
|
|
||||||
|
|
||||||
namespace TaikoLocalServer.Services;
|
|
||||||
|
|
||||||
public class AiDatumService : IAiDatumService
|
|
||||||
{
|
|
||||||
private readonly TaikoDbContext context;
|
|
||||||
|
|
||||||
public AiDatumService(TaikoDbContext context)
|
|
||||||
{
|
|
||||||
this.context = context;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<List<AiScoreDatum>> GetAllAiScoreById(uint baid)
|
|
||||||
{
|
|
||||||
return await context.AiScoreData.Where(datum => datum.Baid == baid)
|
|
||||||
.Include(datum => datum.AiSectionScoreData)
|
|
||||||
.ToListAsync();
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<AiScoreDatum?> GetSongAiScore(uint baid, uint songId, Difficulty difficulty)
|
|
||||||
{
|
|
||||||
return await context.AiScoreData.Where(datum => datum.Baid == baid &&
|
|
||||||
datum.SongId == songId &&
|
|
||||||
datum.Difficulty == difficulty)
|
|
||||||
.Include(datum => datum.AiSectionScoreData)
|
|
||||||
.FirstOrDefaultAsync();
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task UpdateSongAiScore(AiScoreDatum datum)
|
|
||||||
{
|
|
||||||
var existing = await context.AiScoreData.FindAsync(datum.Baid, datum.SongId, datum.Difficulty);
|
|
||||||
existing.ThrowIfNull("Cannot update a non-existing ai score!");
|
|
||||||
|
|
||||||
context.AiScoreData.Update(datum);
|
|
||||||
await context.SaveChangesAsync();
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task InsertSongAiScore(AiScoreDatum datum)
|
|
||||||
{
|
|
||||||
var existing = await context.AiScoreData.FindAsync(datum.Baid, datum.SongId, datum.Difficulty);
|
|
||||||
if (existing is not null)
|
|
||||||
{
|
|
||||||
throw new ArgumentException("Ai score already exists!", nameof(datum));
|
|
||||||
}
|
|
||||||
context.AiScoreData.Add(datum);
|
|
||||||
await context.SaveChangesAsync();
|
|
||||||
}
|
|
||||||
}
|
|
@ -18,32 +18,4 @@ public class DanScoreDatumService : IDanScoreDatumService
|
|||||||
.Include(datum => datum.DanStageScoreData)
|
.Include(datum => datum.DanStageScoreData)
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<DanScoreDatum?> GetSingleDanScoreDatum(uint baid, uint danId, DanType danType)
|
|
||||||
{
|
|
||||||
return await context.DanScoreData.Include(datum => datum.DanStageScoreData)
|
|
||||||
.FirstOrDefaultAsync(datum => datum.Baid == baid &&
|
|
||||||
datum.DanId == danId &&
|
|
||||||
datum.DanType == danType);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task InsertOrUpdateDanScoreDatum(DanScoreDatum datum)
|
|
||||||
{
|
|
||||||
var existing = await context.DanScoreData.FindAsync(datum.Baid, datum.DanId, datum.DanType);
|
|
||||||
if (existing is null)
|
|
||||||
{
|
|
||||||
context.DanScoreData.Add(datum);
|
|
||||||
await context.SaveChangesAsync();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
context.DanScoreData.Update(datum);
|
|
||||||
await context.SaveChangesAsync();
|
|
||||||
}
|
|
||||||
public void TrackDanStageData(DanStageScoreDatum datum)
|
|
||||||
{
|
|
||||||
context.DanStageScoreData.Add(datum);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -10,7 +10,6 @@ public static class ServiceExtensions
|
|||||||
services.AddScoped<ISongPlayDatumService, SongPlayDatumService>();
|
services.AddScoped<ISongPlayDatumService, SongPlayDatumService>();
|
||||||
services.AddScoped<ISongBestDatumService, SongBestDatumService>();
|
services.AddScoped<ISongBestDatumService, SongBestDatumService>();
|
||||||
services.AddScoped<IDanScoreDatumService, DanScoreDatumService>();
|
services.AddScoped<IDanScoreDatumService, DanScoreDatumService>();
|
||||||
services.AddScoped<IAiDatumService, AiDatumService>();
|
|
||||||
|
|
||||||
return services;
|
return services;
|
||||||
}
|
}
|
||||||
|
@ -1,14 +0,0 @@
|
|||||||
using GameDatabase.Entities;
|
|
||||||
|
|
||||||
namespace TaikoLocalServer.Services.Interfaces;
|
|
||||||
|
|
||||||
public interface IAiDatumService
|
|
||||||
{
|
|
||||||
public Task<List<AiScoreDatum>> GetAllAiScoreById(uint baid);
|
|
||||||
|
|
||||||
public Task<AiScoreDatum?> GetSongAiScore(uint baid, uint songId, Difficulty difficulty);
|
|
||||||
|
|
||||||
public Task UpdateSongAiScore(AiScoreDatum datum);
|
|
||||||
|
|
||||||
public Task InsertSongAiScore(AiScoreDatum datum);
|
|
||||||
}
|
|
@ -5,10 +5,4 @@ namespace TaikoLocalServer.Services.Interfaces;
|
|||||||
public interface IDanScoreDatumService
|
public interface IDanScoreDatumService
|
||||||
{
|
{
|
||||||
public Task<List<DanScoreDatum>> GetDanScoreDataList(uint baid, DanType danType);
|
public Task<List<DanScoreDatum>> GetDanScoreDataList(uint baid, DanType danType);
|
||||||
|
|
||||||
public Task<DanScoreDatum?> GetSingleDanScoreDatum(uint baid, uint danId, DanType danType);
|
|
||||||
|
|
||||||
public Task InsertOrUpdateDanScoreDatum(DanScoreDatum datum);
|
|
||||||
|
|
||||||
public void TrackDanStageData(DanStageScoreDatum datum);
|
|
||||||
}
|
}
|
@ -7,11 +7,5 @@ public interface ISongBestDatumService
|
|||||||
{
|
{
|
||||||
public Task<List<SongBestDatum>> GetAllSongBestData(uint baid);
|
public Task<List<SongBestDatum>> GetAllSongBestData(uint baid);
|
||||||
|
|
||||||
public Task<SongBestDatum?> GetSongBestData(uint baid, uint songId, Difficulty difficulty);
|
|
||||||
|
|
||||||
public Task UpdateSongBestData(SongBestDatum datum);
|
|
||||||
|
|
||||||
public Task InsertSongBestData(SongBestDatum datum);
|
|
||||||
|
|
||||||
public Task<List<SongBestData>> GetAllSongBestAsModel(uint baid);
|
public Task<List<SongBestData>> GetAllSongBestAsModel(uint baid);
|
||||||
}
|
}
|
@ -5,6 +5,4 @@ namespace TaikoLocalServer.Services.Interfaces;
|
|||||||
public interface ISongPlayDatumService
|
public interface ISongPlayDatumService
|
||||||
{
|
{
|
||||||
public Task<List<SongPlayDatum>> GetSongPlayDatumByBaid(uint baid);
|
public Task<List<SongPlayDatum>> GetSongPlayDatumByBaid(uint baid);
|
||||||
|
|
||||||
public Task AddSongPlayDatum(SongPlayDatum datum);
|
|
||||||
}
|
}
|
@ -6,14 +6,6 @@ public interface IUserDatumService
|
|||||||
{
|
{
|
||||||
public Task<UserDatum?> GetFirstUserDatumOrNull(uint baid);
|
public Task<UserDatum?> GetFirstUserDatumOrNull(uint baid);
|
||||||
|
|
||||||
public Task<UserDatum> GetFirstUserDatumOrDefault(uint baid);
|
|
||||||
|
|
||||||
public Task<List<UserDatum>> GetAllUserData();
|
|
||||||
|
|
||||||
public Task UpdateOrInsertUserDatum(UserDatum userDatum);
|
|
||||||
|
|
||||||
public Task InsertUserDatum(UserDatum userDatum);
|
|
||||||
|
|
||||||
public Task UpdateUserDatum(UserDatum userDatum);
|
public Task UpdateUserDatum(UserDatum userDatum);
|
||||||
|
|
||||||
public Task<bool> DeleteUser(uint baid);
|
public Task<bool> DeleteUser(uint baid);
|
||||||
|
@ -20,34 +20,6 @@ public class SongBestDatumService : ISongBestDatumService
|
|||||||
return await context.SongBestData.Where(datum => datum.Baid == baid).ToListAsync();
|
return await context.SongBestData.Where(datum => datum.Baid == baid).ToListAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<SongBestDatum?> GetSongBestData(uint baid, uint songId, Difficulty difficulty)
|
|
||||||
{
|
|
||||||
return await context.SongBestData.Where(datum => datum.Baid == baid &&
|
|
||||||
datum.SongId == songId &&
|
|
||||||
datum.Difficulty == difficulty)
|
|
||||||
.FirstOrDefaultAsync();
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task UpdateSongBestData(SongBestDatum datum)
|
|
||||||
{
|
|
||||||
var existing = await context.SongBestData.FindAsync(datum.Baid, datum.SongId, datum.Difficulty);
|
|
||||||
existing.ThrowIfNull("Cannot update a non-existing best data!");
|
|
||||||
|
|
||||||
context.SongBestData.Update(datum);
|
|
||||||
await context.SaveChangesAsync();
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task InsertSongBestData(SongBestDatum datum)
|
|
||||||
{
|
|
||||||
var existing = await context.SongBestData.FindAsync(datum.Baid, datum.SongId, datum.Difficulty);
|
|
||||||
if (existing is not null)
|
|
||||||
{
|
|
||||||
throw new ArgumentException("Best data already exists!", nameof(datum));
|
|
||||||
}
|
|
||||||
context.SongBestData.Add(datum);
|
|
||||||
await context.SaveChangesAsync();
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<List<SongBestData>> GetAllSongBestAsModel(uint baid)
|
public async Task<List<SongBestData>> GetAllSongBestAsModel(uint baid)
|
||||||
{
|
{
|
||||||
var songbestDbData = await context.SongBestData.Where(datum => datum.Baid == baid)
|
var songbestDbData = await context.SongBestData.Where(datum => datum.Baid == baid)
|
||||||
|
@ -16,10 +16,4 @@ class SongPlayDatumService : ISongPlayDatumService
|
|||||||
{
|
{
|
||||||
return await context.SongPlayData.Where(datum => datum.Baid == baid).ToListAsync();
|
return await context.SongPlayData.Where(datum => datum.Baid == baid).ToListAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task AddSongPlayDatum(SongPlayDatum datum)
|
|
||||||
{
|
|
||||||
context.SongPlayData.Add(datum);
|
|
||||||
await context.SaveChangesAsync();
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -23,37 +23,6 @@ public class UserDatumService : IUserDatumService
|
|||||||
.FirstOrDefaultAsync(d => d.Baid == baid);
|
.FirstOrDefaultAsync(d => d.Baid == baid);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<UserDatum> GetFirstUserDatumOrDefault(uint baid)
|
|
||||||
{
|
|
||||||
return await context.UserData
|
|
||||||
.Include(d => d.Tokens)
|
|
||||||
.FirstOrDefaultAsync(d => d.Baid == baid) ?? new UserDatum();
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<List<UserDatum>> GetAllUserData()
|
|
||||||
{
|
|
||||||
return await context.UserData.ToListAsync();
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task UpdateOrInsertUserDatum(UserDatum userDatum)
|
|
||||||
{
|
|
||||||
if (await context.UserData.AnyAsync(datum => datum.Baid == userDatum.Baid))
|
|
||||||
{
|
|
||||||
context.UserData.Add(userDatum);
|
|
||||||
await context.SaveChangesAsync();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
context.Update(userDatum);
|
|
||||||
await context.SaveChangesAsync();
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task InsertUserDatum(UserDatum userDatum)
|
|
||||||
{
|
|
||||||
context.UserData.Add(userDatum);
|
|
||||||
await context.SaveChangesAsync();
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task UpdateUserDatum(UserDatum userDatum)
|
public async Task UpdateUserDatum(UserDatum userDatum)
|
||||||
{
|
{
|
||||||
context.Update(userDatum);
|
context.Update(userDatum);
|
||||||
|
Loading…
Reference in New Issue
Block a user