Use mapper for SongPlayDatum database models
This commit is contained in:
parent
d8dd7e741b
commit
cb41c29970
@ -1,7 +1,6 @@
|
||||
using GameDatabase.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SharedProject.Utils;
|
||||
using SharedProject.Entities;
|
||||
|
||||
namespace GameDatabase.Context
|
||||
{
|
||||
|
@ -1,7 +1,6 @@
|
||||
using GameDatabase.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SharedProject.Enums;
|
||||
using SharedProject.Entities;
|
||||
|
||||
namespace GameDatabase.Context;
|
||||
|
||||
|
@ -1,5 +1,4 @@
|
||||
using SharedProject.Enums;
|
||||
using SharedProject.Entities;
|
||||
|
||||
namespace GameDatabase.Entities;
|
||||
|
||||
|
@ -1,6 +1,4 @@
|
||||
using SharedProject.Entities;
|
||||
|
||||
namespace GameDatabase.Entities
|
||||
namespace GameDatabase.Entities
|
||||
{
|
||||
public partial class Card
|
||||
{
|
||||
|
@ -1,6 +1,4 @@
|
||||
using SharedProject.Entities;
|
||||
|
||||
namespace GameDatabase.Entities
|
||||
namespace GameDatabase.Entities
|
||||
{
|
||||
public partial class Credential
|
||||
{
|
||||
|
@ -1,5 +1,4 @@
|
||||
using SharedProject.Enums;
|
||||
using SharedProject.Entities;
|
||||
|
||||
namespace GameDatabase.Entities;
|
||||
|
||||
|
@ -1,5 +1,4 @@
|
||||
using SharedProject.Enums;
|
||||
using SharedProject.Entities;
|
||||
|
||||
namespace GameDatabase.Entities
|
||||
{
|
||||
|
28
GameDatabase/Entities/SongPlayDatum.cs
Normal file
28
GameDatabase/Entities/SongPlayDatum.cs
Normal file
@ -0,0 +1,28 @@
|
||||
using SharedProject.Enums;
|
||||
|
||||
namespace GameDatabase.Entities;
|
||||
|
||||
public partial class SongPlayDatum
|
||||
{
|
||||
public long Id { get; set; }
|
||||
public uint Baid { get; set; }
|
||||
|
||||
public uint SongNumber { get; set; }
|
||||
|
||||
public uint SongId { get; set; }
|
||||
public Difficulty Difficulty { get; set; }
|
||||
public CrownType Crown { get; set; }
|
||||
public uint Score { get; set; }
|
||||
public uint ScoreRate { get; set; }
|
||||
public ScoreRank ScoreRank { get; set; }
|
||||
public uint GoodCount { get; set; }
|
||||
public uint OkCount { get; set; }
|
||||
public uint MissCount { get; set; }
|
||||
public uint ComboCount { get; set; }
|
||||
public uint HitCount { get; set; }
|
||||
public uint DrumrollCount { get; set; }
|
||||
public bool Skipped { get; set; }
|
||||
public DateTime PlayTime { get; set; }
|
||||
|
||||
public virtual UserDatum? Ba { get; set; }
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
namespace SharedProject.Entities;
|
||||
namespace GameDatabase.Entities;
|
||||
|
||||
public class Token
|
||||
{
|
37
GameDatabase/Entities/UserDatum.cs
Normal file
37
GameDatabase/Entities/UserDatum.cs
Normal file
@ -0,0 +1,37 @@
|
||||
using SharedProject.Enums;
|
||||
|
||||
namespace GameDatabase.Entities;
|
||||
|
||||
public partial class UserDatum
|
||||
{
|
||||
public uint Baid { get; set; }
|
||||
public string MyDonName { get; set; } = string.Empty;
|
||||
public uint MyDonNameLanguage { get; set; }
|
||||
public string Title { get; set; } = string.Empty;
|
||||
public uint TitlePlateId { get; set; }
|
||||
public string FavoriteSongsArray { get; set; } = "[]";
|
||||
public string ToneFlgArray { get; set; } = "[]";
|
||||
public string TitleFlgArray { get; set; } = "[]";
|
||||
public string CostumeFlgArray { get; set; } = "[[],[],[],[],[]]";
|
||||
public string GenericInfoFlgArray { get; set; } = "[]";
|
||||
public short OptionSetting { get; set; }
|
||||
public int NotesPosition { get; set; }
|
||||
public bool IsVoiceOn { get; set; }
|
||||
public bool IsSkipOn { get; set; }
|
||||
public string DifficultyPlayedArray { get; set; } = "[]";
|
||||
public string DifficultySettingArray { get; set; } = "[]";
|
||||
public uint SelectedToneId { get; set; }
|
||||
public DateTime LastPlayDatetime { get; set; }
|
||||
public uint LastPlayMode { get; set; }
|
||||
public uint ColorBody { get; set; }
|
||||
public uint ColorFace { get; set; }
|
||||
public uint ColorLimb { get; set; }
|
||||
public string CostumeData { get; set; } = "[]";
|
||||
public bool DisplayDan { get; set; }
|
||||
public bool DisplayAchievement { get; set; }
|
||||
public Difficulty AchievementDisplayDifficulty { get; set; }
|
||||
public int AiWinCount { get; set; }
|
||||
public List<Token> Tokens { get; set; } = new();
|
||||
public string UnlockedSongIdList { get; set; } = "[]";
|
||||
public bool IsAdmin { get; set; }
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
using SharedProject.Enums;
|
||||
|
||||
namespace SharedProject.Entities
|
||||
{
|
||||
public partial class UserDatum
|
||||
{
|
||||
public uint Baid { get; set; }
|
||||
public string MyDonName { get; set; } = string.Empty;
|
||||
public uint MyDonNameLanguage { get; set; }
|
||||
public string Title { get; set; } = string.Empty;
|
||||
public uint TitlePlateId { get; set; }
|
||||
public string FavoriteSongsArray { get; set; } = "[]";
|
||||
public string ToneFlgArray { get; set; } = "[]";
|
||||
public string TitleFlgArray { get; set; } = "[]";
|
||||
public string CostumeFlgArray { get; set; } = "[[],[],[],[],[]]";
|
||||
public string GenericInfoFlgArray { get; set; } = "[]";
|
||||
public short OptionSetting { get; set; }
|
||||
public int NotesPosition { get; set; }
|
||||
public bool IsVoiceOn { get; set; }
|
||||
public bool IsSkipOn { get; set; }
|
||||
public string DifficultyPlayedArray { get; set; } = "[]";
|
||||
public string DifficultySettingArray { get; set; } = "[]";
|
||||
public uint SelectedToneId { get; set; }
|
||||
public DateTime LastPlayDatetime { get; set; }
|
||||
public uint LastPlayMode { get; set; }
|
||||
public uint ColorBody { get; set; }
|
||||
public uint ColorFace { get; set; }
|
||||
public uint ColorLimb { get; set; }
|
||||
public string CostumeData { get; set; } = "[]";
|
||||
public bool DisplayDan { get; set; }
|
||||
public bool DisplayAchievement { get; set; }
|
||||
public Difficulty AchievementDisplayDifficulty { get; set; }
|
||||
public int AiWinCount { get; set; }
|
||||
public List<Token> Tokens { get; set; } = new();
|
||||
public string UnlockedSongIdList { get; set; } = "[]";
|
||||
public bool IsAdmin { get; set; }
|
||||
}
|
||||
}
|
@ -1,5 +1,4 @@
|
||||
using SharedProject.Enums;
|
||||
using SharedProject.Entities;
|
||||
|
||||
namespace SharedProject.Models;
|
||||
|
||||
@ -48,5 +47,5 @@ public class SongBestData
|
||||
|
||||
public bool ShowAiData { get; set; }
|
||||
|
||||
public List<SongPlayDatum> RecentPlayData { get; set; } = new();
|
||||
public List<SongPlayDatumDto> RecentPlayData { get; set; } = new();
|
||||
}
|
@ -1,14 +1,10 @@
|
||||
using SharedProject.Enums;
|
||||
|
||||
namespace SharedProject.Entities
|
||||
namespace SharedProject.Models
|
||||
{
|
||||
public partial class SongPlayDatum
|
||||
public class SongPlayDatumDto
|
||||
{
|
||||
public long Id { get; set; }
|
||||
public uint Baid { get; set; }
|
||||
|
||||
public uint SongNumber { get; set; }
|
||||
|
||||
public uint SongId { get; set; }
|
||||
public Difficulty Difficulty { get; set; }
|
||||
public CrownType Crown { get; set; }
|
||||
@ -23,7 +19,5 @@ namespace SharedProject.Entities
|
||||
public uint DrumrollCount { get; set; }
|
||||
public bool Skipped { get; set; }
|
||||
public DateTime PlayTime { get; set; }
|
||||
|
||||
public virtual UserDatum? Ba { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
using SharedProject.Entities;
|
||||
using GameDatabase.Entities;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace TaikoLocalServer.Common.Utils;
|
||||
|
@ -1,61 +1,75 @@
|
||||
using SharedProject.Models.Responses;
|
||||
using Riok.Mapperly.Abstractions;
|
||||
using SharedProject.Models.Responses;
|
||||
using SharedProject.Models;
|
||||
using GameDatabase.Entities;
|
||||
|
||||
namespace TaikoLocalServer.Controllers.Api;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class PlayDataController : BaseController<PlayDataController>
|
||||
namespace TaikoLocalServer.Controllers.Api
|
||||
{
|
||||
private readonly IUserDatumService userDatumService;
|
||||
|
||||
private readonly ISongBestDatumService songBestDatumService;
|
||||
|
||||
private readonly ISongPlayDatumService songPlayDatumService;
|
||||
|
||||
public PlayDataController(IUserDatumService userDatumService, ISongBestDatumService songBestDatumService,
|
||||
ISongPlayDatumService songPlayDatumService)
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class PlayDataController : BaseController<PlayDataController>
|
||||
{
|
||||
this.userDatumService = userDatumService;
|
||||
this.songBestDatumService = songBestDatumService;
|
||||
this.songPlayDatumService = songPlayDatumService;
|
||||
private readonly IUserDatumService userDatumService;
|
||||
private readonly ISongBestDatumService songBestDatumService;
|
||||
private readonly ISongPlayDatumService songPlayDatumService;
|
||||
private readonly SongBestResponseMapper _songBestResponseMapper; // Inject SongBestResponseMapper
|
||||
|
||||
public PlayDataController(IUserDatumService userDatumService, ISongBestDatumService songBestDatumService,
|
||||
ISongPlayDatumService songPlayDatumService, SongBestResponseMapper songBestResponseMapper)
|
||||
{
|
||||
this.userDatumService = userDatumService;
|
||||
this.songBestDatumService = songBestDatumService;
|
||||
this.songPlayDatumService = songPlayDatumService;
|
||||
_songBestResponseMapper = songBestResponseMapper; // Assign the injected mapper
|
||||
}
|
||||
|
||||
[HttpGet("{baid}")]
|
||||
public async Task<ActionResult<SongBestResponse>> GetSongBestRecords(uint baid)
|
||||
{
|
||||
{
|
||||
var user = await userDatumService.GetFirstUserDatumOrNull(baid);
|
||||
if (user is null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
var songBestRecords = await songBestDatumService.GetAllSongBestAsModel(baid);
|
||||
var songPlayData = await songPlayDatumService.GetSongPlayDatumByBaid(baid);
|
||||
foreach (var songBestData in songBestRecords)
|
||||
{
|
||||
var songPlayLogs = songPlayData.Where(datum => datum.SongId == songBestData.SongId &&
|
||||
datum.Difficulty == songBestData.Difficulty).ToList();
|
||||
songBestData.PlayCount = songPlayLogs.Count;
|
||||
songBestData.ClearCount = songPlayLogs.Count(datum => datum.Crown >= CrownType.Clear);
|
||||
songBestData.FullComboCount = songPlayLogs.Count(datum => datum.Crown >= CrownType.Gold);
|
||||
songBestData.PerfectCount = songPlayLogs.Count(datum => datum.Crown >= CrownType.Dondaful);
|
||||
}
|
||||
var favoriteSongs = await userDatumService.GetFavoriteSongIds(baid);
|
||||
var favoriteSet = favoriteSongs.ToHashSet();
|
||||
foreach (var songBestRecord in songBestRecords.Where(songBestRecord => favoriteSet.Contains(songBestRecord.SongId)))
|
||||
{
|
||||
songBestRecord.IsFavorite = true;
|
||||
}
|
||||
|
||||
foreach (var songBestRecord in songBestRecords)
|
||||
{
|
||||
songBestRecord.RecentPlayData = songPlayData
|
||||
.Where(datum => datum.SongId == songBestRecord.SongId && datum.Difficulty == songBestRecord.Difficulty)
|
||||
.Select(SongBestResponseMapper.MapToDto)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
return Ok(new SongBestResponse
|
||||
{
|
||||
SongBestData = songBestRecords
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("{baid}")]
|
||||
public async Task<ActionResult<SongBestResponse>> GetSongBestRecords(uint baid)
|
||||
[Mapper(EnumMappingStrategy = EnumMappingStrategy.ByName)]
|
||||
public partial class SongBestResponseMapper
|
||||
{
|
||||
var user = await userDatumService.GetFirstUserDatumOrNull(baid);
|
||||
if (user is null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
var songBestRecords = await songBestDatumService.GetAllSongBestAsModel(baid);
|
||||
var playLogs = await songPlayDatumService.GetSongPlayDatumByBaid(baid);
|
||||
foreach (var songBestData in songBestRecords)
|
||||
{
|
||||
var songPlayLogs = playLogs.Where(datum => datum.SongId == songBestData.SongId &&
|
||||
datum.Difficulty == songBestData.Difficulty).ToList();
|
||||
songBestData.PlayCount = songPlayLogs.Count;
|
||||
songBestData.ClearCount = songPlayLogs.Count(datum => datum.Crown >= CrownType.Clear);
|
||||
songBestData.FullComboCount = songPlayLogs.Count(datum => datum.Crown >= CrownType.Gold);
|
||||
songBestData.PerfectCount = songPlayLogs.Count(datum => datum.Crown >= CrownType.Dondaful);
|
||||
}
|
||||
var favoriteSongs = await userDatumService.GetFavoriteSongIds(baid);
|
||||
var favoriteSet = favoriteSongs.ToHashSet();
|
||||
foreach (var songBestRecord in songBestRecords.Where(songBestRecord => favoriteSet.Contains(songBestRecord.SongId)))
|
||||
{
|
||||
songBestRecord.IsFavorite = true;
|
||||
}
|
||||
|
||||
foreach (var songBestRecord in songBestRecords)
|
||||
{
|
||||
songBestRecord.RecentPlayData = playLogs.Where(datum => datum.SongId == songBestRecord.SongId)
|
||||
.OrderByDescending(datum => datum.PlayTime).Take(10).ToList();
|
||||
}
|
||||
|
||||
return Ok(new SongBestResponse
|
||||
{
|
||||
SongBestData = songBestRecords
|
||||
});
|
||||
public static partial SongPlayDatumDto MapToDto(SongPlayDatum entity);
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
using System.Text.Json;
|
||||
using SharedProject.Entities;
|
||||
using GameDatabase.Entities;
|
||||
using Throw;
|
||||
|
||||
namespace TaikoLocalServer.Controllers.Game;
|
||||
|
@ -1,5 +1,5 @@
|
||||
using System.Text.Json;
|
||||
using SharedProject.Entities;
|
||||
using GameDatabase.Entities;
|
||||
using Throw;
|
||||
|
||||
namespace TaikoLocalServer.Controllers.Game;
|
||||
|
@ -1,5 +1,4 @@
|
||||
using GameDatabase.Entities;
|
||||
using SharedProject.Entities;
|
||||
|
||||
namespace TaikoLocalServer.Controllers.Game;
|
||||
|
||||
|
@ -1,5 +1,4 @@
|
||||
using GameDatabase.Entities;
|
||||
using SharedProject.Entities;
|
||||
using System.Globalization;
|
||||
using System.Text.Json;
|
||||
using Throw;
|
||||
|
@ -11,6 +11,7 @@ using TaikoLocalServer.Settings;
|
||||
using Throw;
|
||||
using Serilog;
|
||||
using SharedProject.Utils;
|
||||
using TaikoLocalServer.Controllers.Api;
|
||||
|
||||
Log.Logger = new LoggerConfiguration()
|
||||
.WriteTo.Console()
|
||||
@ -88,6 +89,7 @@ try
|
||||
});
|
||||
});
|
||||
builder.Services.AddTaikoDbServices();
|
||||
builder.Services.AddSingleton<SongBestResponseMapper>();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
using SharedProject.Entities;
|
||||
using GameDatabase.Entities;
|
||||
|
||||
namespace TaikoLocalServer.Services.Interfaces;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
using SharedProject.Entities;
|
||||
using GameDatabase.Entities;
|
||||
|
||||
namespace TaikoLocalServer.Services.Interfaces;
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
using GameDatabase.Context;
|
||||
using GameDatabase.Entities;
|
||||
using SharedProject.Entities;
|
||||
using SharedProject.Models;
|
||||
using Swan.Mapping;
|
||||
using Throw;
|
||||
|
@ -1,5 +1,5 @@
|
||||
using GameDatabase.Context;
|
||||
using SharedProject.Entities;
|
||||
using GameDatabase.Entities;
|
||||
|
||||
namespace TaikoLocalServer.Services;
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
using GameDatabase.Context;
|
||||
using SharedProject.Entities;
|
||||
using GameDatabase.Entities;
|
||||
using System.Text.Json;
|
||||
using Throw;
|
||||
|
||||
|
@ -24,6 +24,7 @@
|
||||
</PackageReference>
|
||||
<PackageReference Include="protobuf-net" Version="3.2.26" />
|
||||
<PackageReference Include="protobuf-net.AspNetCore" Version="3.2.12" />
|
||||
<PackageReference Include="Riok.Mapperly" Version="3.4.0" ExcludeAssets="runtime" PrivateAssets="all" />
|
||||
<PackageReference Include="Serilog.AspNetCore" Version="7.0.0" />
|
||||
<PackageReference Include="Serilog.Expressions" Version="4.0.0-dev-00137" />
|
||||
<PackageReference Include="Serilog.Sinks.File.Header" Version="1.0.2" />
|
||||
|
@ -1,5 +1,4 @@
|
||||
@using TaikoWebUI.Utilities;
|
||||
@using SharedProject.Entities;
|
||||
|
||||
<MudCard Outlined="true" Elevation="0">
|
||||
<MudCardHeader>
|
||||
@ -54,6 +53,6 @@
|
||||
</MudCard>
|
||||
|
||||
@code {
|
||||
[Parameter] public List<SongPlayDatum> Items { get; set; } = new List<SongPlayDatum>();
|
||||
[Parameter] public List<SongPlayDatumDto> Items { get; set; } = new List<SongPlayDatumDto>();
|
||||
private const string IconStyle = "width:25px; height:25px;";
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user