From 1514fd16fdb0a1263e7e9374bdee0d0f1c080127 Mon Sep 17 00:00:00 2001 From: asesidaa <1061472754@qq.com> Date: Sat, 16 Mar 2024 22:53:05 +0800 Subject: [PATCH] Cleanup services --- TaikoLocalServer/Services/AiDatumService.cs | 51 ------------------- .../Services/DanScoreDatumService.cs | 28 ---------- .../Services/Extentions/ServiceExtensions.cs | 1 - .../Services/Interfaces/IAiDatumService.cs | 14 ----- .../Interfaces/IDanScoreDatumService.cs | 6 --- .../Interfaces/ISongBestDatumService.cs | 6 --- .../Interfaces/ISongPlayDatumService.cs | 2 - .../Services/Interfaces/IUserDatumService.cs | 8 --- .../Services/SongBestDatumService.cs | 28 ---------- .../Services/SongPlayDatumService.cs | 6 --- TaikoLocalServer/Services/UserDatumService.cs | 31 ----------- 11 files changed, 181 deletions(-) delete mode 100644 TaikoLocalServer/Services/AiDatumService.cs delete mode 100644 TaikoLocalServer/Services/Interfaces/IAiDatumService.cs diff --git a/TaikoLocalServer/Services/AiDatumService.cs b/TaikoLocalServer/Services/AiDatumService.cs deleted file mode 100644 index 2d716e7..0000000 --- a/TaikoLocalServer/Services/AiDatumService.cs +++ /dev/null @@ -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> GetAllAiScoreById(uint baid) - { - return await context.AiScoreData.Where(datum => datum.Baid == baid) - .Include(datum => datum.AiSectionScoreData) - .ToListAsync(); - } - - public async Task 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(); - } -} \ No newline at end of file diff --git a/TaikoLocalServer/Services/DanScoreDatumService.cs b/TaikoLocalServer/Services/DanScoreDatumService.cs index 3f77113..860dfb3 100644 --- a/TaikoLocalServer/Services/DanScoreDatumService.cs +++ b/TaikoLocalServer/Services/DanScoreDatumService.cs @@ -18,32 +18,4 @@ public class DanScoreDatumService : IDanScoreDatumService .Include(datum => datum.DanStageScoreData) .ToListAsync(); } - - public async Task 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); - } - - } \ No newline at end of file diff --git a/TaikoLocalServer/Services/Extentions/ServiceExtensions.cs b/TaikoLocalServer/Services/Extentions/ServiceExtensions.cs index 09d459f..22d9c9f 100644 --- a/TaikoLocalServer/Services/Extentions/ServiceExtensions.cs +++ b/TaikoLocalServer/Services/Extentions/ServiceExtensions.cs @@ -10,7 +10,6 @@ public static class ServiceExtensions services.AddScoped(); services.AddScoped(); services.AddScoped(); - services.AddScoped(); return services; } diff --git a/TaikoLocalServer/Services/Interfaces/IAiDatumService.cs b/TaikoLocalServer/Services/Interfaces/IAiDatumService.cs deleted file mode 100644 index 5525034..0000000 --- a/TaikoLocalServer/Services/Interfaces/IAiDatumService.cs +++ /dev/null @@ -1,14 +0,0 @@ -using GameDatabase.Entities; - -namespace TaikoLocalServer.Services.Interfaces; - -public interface IAiDatumService -{ - public Task> GetAllAiScoreById(uint baid); - - public Task GetSongAiScore(uint baid, uint songId, Difficulty difficulty); - - public Task UpdateSongAiScore(AiScoreDatum datum); - - public Task InsertSongAiScore(AiScoreDatum datum); -} \ No newline at end of file diff --git a/TaikoLocalServer/Services/Interfaces/IDanScoreDatumService.cs b/TaikoLocalServer/Services/Interfaces/IDanScoreDatumService.cs index 465b87d..ea7af1d 100644 --- a/TaikoLocalServer/Services/Interfaces/IDanScoreDatumService.cs +++ b/TaikoLocalServer/Services/Interfaces/IDanScoreDatumService.cs @@ -5,10 +5,4 @@ namespace TaikoLocalServer.Services.Interfaces; public interface IDanScoreDatumService { public Task> GetDanScoreDataList(uint baid, DanType danType); - - public Task GetSingleDanScoreDatum(uint baid, uint danId, DanType danType); - - public Task InsertOrUpdateDanScoreDatum(DanScoreDatum datum); - - public void TrackDanStageData(DanStageScoreDatum datum); } \ No newline at end of file diff --git a/TaikoLocalServer/Services/Interfaces/ISongBestDatumService.cs b/TaikoLocalServer/Services/Interfaces/ISongBestDatumService.cs index 55db620..d0b83c5 100644 --- a/TaikoLocalServer/Services/Interfaces/ISongBestDatumService.cs +++ b/TaikoLocalServer/Services/Interfaces/ISongBestDatumService.cs @@ -7,11 +7,5 @@ public interface ISongBestDatumService { public Task> GetAllSongBestData(uint baid); - public Task GetSongBestData(uint baid, uint songId, Difficulty difficulty); - - public Task UpdateSongBestData(SongBestDatum datum); - - public Task InsertSongBestData(SongBestDatum datum); - public Task> GetAllSongBestAsModel(uint baid); } \ No newline at end of file diff --git a/TaikoLocalServer/Services/Interfaces/ISongPlayDatumService.cs b/TaikoLocalServer/Services/Interfaces/ISongPlayDatumService.cs index c179951..e5ea537 100644 --- a/TaikoLocalServer/Services/Interfaces/ISongPlayDatumService.cs +++ b/TaikoLocalServer/Services/Interfaces/ISongPlayDatumService.cs @@ -5,6 +5,4 @@ namespace TaikoLocalServer.Services.Interfaces; public interface ISongPlayDatumService { public Task> GetSongPlayDatumByBaid(uint baid); - - public Task AddSongPlayDatum(SongPlayDatum datum); } \ No newline at end of file diff --git a/TaikoLocalServer/Services/Interfaces/IUserDatumService.cs b/TaikoLocalServer/Services/Interfaces/IUserDatumService.cs index 5074012..6adf869 100644 --- a/TaikoLocalServer/Services/Interfaces/IUserDatumService.cs +++ b/TaikoLocalServer/Services/Interfaces/IUserDatumService.cs @@ -6,14 +6,6 @@ public interface IUserDatumService { public Task GetFirstUserDatumOrNull(uint baid); - public Task GetFirstUserDatumOrDefault(uint baid); - - public Task> GetAllUserData(); - - public Task UpdateOrInsertUserDatum(UserDatum userDatum); - - public Task InsertUserDatum(UserDatum userDatum); - public Task UpdateUserDatum(UserDatum userDatum); public Task DeleteUser(uint baid); diff --git a/TaikoLocalServer/Services/SongBestDatumService.cs b/TaikoLocalServer/Services/SongBestDatumService.cs index d868398..1f879df 100644 --- a/TaikoLocalServer/Services/SongBestDatumService.cs +++ b/TaikoLocalServer/Services/SongBestDatumService.cs @@ -20,34 +20,6 @@ public class SongBestDatumService : ISongBestDatumService return await context.SongBestData.Where(datum => datum.Baid == baid).ToListAsync(); } - public async Task 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> GetAllSongBestAsModel(uint baid) { var songbestDbData = await context.SongBestData.Where(datum => datum.Baid == baid) diff --git a/TaikoLocalServer/Services/SongPlayDatumService.cs b/TaikoLocalServer/Services/SongPlayDatumService.cs index e456e14..1e79f1f 100644 --- a/TaikoLocalServer/Services/SongPlayDatumService.cs +++ b/TaikoLocalServer/Services/SongPlayDatumService.cs @@ -16,10 +16,4 @@ class SongPlayDatumService : ISongPlayDatumService { return await context.SongPlayData.Where(datum => datum.Baid == baid).ToListAsync(); } - - public async Task AddSongPlayDatum(SongPlayDatum datum) - { - context.SongPlayData.Add(datum); - await context.SaveChangesAsync(); - } } \ No newline at end of file diff --git a/TaikoLocalServer/Services/UserDatumService.cs b/TaikoLocalServer/Services/UserDatumService.cs index e3c9030..a852df9 100644 --- a/TaikoLocalServer/Services/UserDatumService.cs +++ b/TaikoLocalServer/Services/UserDatumService.cs @@ -23,37 +23,6 @@ public class UserDatumService : IUserDatumService .FirstOrDefaultAsync(d => d.Baid == baid); } - public async Task GetFirstUserDatumOrDefault(uint baid) - { - return await context.UserData - .Include(d => d.Tokens) - .FirstOrDefaultAsync(d => d.Baid == baid) ?? new UserDatum(); - } - - public async Task> 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) { context.Update(userDatum);