1
0
mirror of synced 2024-11-14 18:38:06 +01:00

Fixes and added a new api that retrieves all userSettings for admins

This commit is contained in:
S-Sebb 2024-05-26 21:25:24 +01:00
parent 2069681390
commit 0939a0e045
17 changed files with 136 additions and 29 deletions

View File

@ -4,6 +4,8 @@ namespace SharedProject.Models;
public class UserSetting
{
public uint Baid { get; set; }
public uint ToneId { get; set; }
public bool IsDisplayAchievement { get; set; }

View File

@ -7,14 +7,93 @@ using TaikoLocalServer.Settings;
namespace TaikoLocalServer.Controllers.Api;
[ApiController]
[Route("/api/[controller]/{baid}")]
[Route("/api/[controller]")]
public class UserSettingsController(IUserDatumService userDatumService, IAuthService authService,
IOptions<AuthSettings> settings) : BaseController<UserSettingsController>
{
private readonly AuthSettings authSettings = settings.Value;
[HttpGet]
[ServiceFilter(typeof(AuthorizeIfRequiredAttribute))]
public async Task<ActionResult<List<UserSetting>>> GetAllUserSetting()
{
if (authSettings.LoginRequired)
{
var tokenInfo = authService.ExtractTokenInfo(HttpContext);
if (tokenInfo is null)
{
return Unauthorized();
}
if (!tokenInfo.Value.isAdmin)
{
return Forbid();
}
}
var users = await userDatumService.GetAllUserDatum();
var response = new List<UserSetting>();
foreach (var user in users)
{
List<List<uint>> costumeUnlockData =
[user.UnlockedKigurumi, user.UnlockedHead, user.UnlockedBody, user.UnlockedFace, user.UnlockedPuchi];
var unlockedTitle = user.TitleFlgArray
.ToList();
for (var i = 0; i < 5; i++)
{
if (!costumeUnlockData[i].Contains(0))
{
costumeUnlockData[i].Add(0);
}
}
var userSetting = new UserSetting
{
Baid = user.Baid,
AchievementDisplayDifficulty = user.AchievementDisplayDifficulty,
IsDisplayAchievement = user.DisplayAchievement,
IsDisplayDanOnNamePlate = user.DisplayDan,
DifficultySettingCourse = user.DifficultySettingCourse,
DifficultySettingStar = user.DifficultySettingStar,
DifficultySettingSort = user.DifficultySettingSort,
IsVoiceOn = user.IsVoiceOn,
IsSkipOn = user.IsSkipOn,
NotesPosition = user.NotesPosition,
PlaySetting = PlaySettingConverter.ShortToPlaySetting(user.OptionSetting),
ToneId = user.SelectedToneId,
MyDonName = user.MyDonName,
MyDonNameLanguage = user.MyDonNameLanguage,
Title = user.Title,
TitlePlateId = user.TitlePlateId,
Kigurumi = user.CurrentKigurumi,
Head = user.CurrentHead,
Body = user.CurrentBody,
Face = user.CurrentFace,
Puchi = user.CurrentPuchi,
UnlockedKigurumi = costumeUnlockData[0],
UnlockedHead = costumeUnlockData[1],
UnlockedBody = costumeUnlockData[2],
UnlockedFace = costumeUnlockData[3],
UnlockedPuchi = costumeUnlockData[4],
UnlockedTitle = unlockedTitle,
BodyColor = user.ColorBody,
FaceColor = user.ColorFace,
LimbColor = user.ColorLimb,
LastPlayDateTime = user.LastPlayDatetime
};
response.Add(userSetting);
}
return Ok(response);
}
[HttpGet("{baid}")]
[ServiceFilter(typeof(AuthorizeIfRequiredAttribute))]
public async Task<ActionResult<UserSetting>> GetUserSetting(uint baid)
{
if (authSettings.LoginRequired)
@ -54,6 +133,7 @@ public class UserSettingsController(IUserDatumService userDatumService, IAuthSer
var response = new UserSetting
{
Baid = user.Baid,
AchievementDisplayDifficulty = user.AchievementDisplayDifficulty,
IsDisplayAchievement = user.DisplayAchievement,
IsDisplayDanOnNamePlate = user.DisplayDan,
@ -88,7 +168,7 @@ public class UserSettingsController(IUserDatumService userDatumService, IAuthSer
return Ok(response);
}
[HttpPost]
[HttpPost("{baid}")]
[ServiceFilter(typeof(AuthorizeIfRequiredAttribute))]
public async Task<IActionResult> SaveUserSetting(uint baid, UserSetting userSetting)
{

View File

@ -18,7 +18,7 @@ public class UpdatePlayResultCommandHandler(TaikoDbContext context, ILogger<Upda
var user = await context.UserData.FindAsync([request.Baid], cancellationToken);
if (user is null)
{
logger.LogWarning("Game uploading a non exisiting user with baid {Baid}", request.Baid);
logger.LogWarning("Game uploading a non existing user with baid {Baid}", request.Baid);
return 1;
}
@ -29,6 +29,11 @@ public class UpdatePlayResultCommandHandler(TaikoDbContext context, ILogger<Upda
var playMode = (PlayMode)playResultData.PlayMode;
if (playMode is PlayMode.DanMode or PlayMode.GaidenMode)
{
if (playResultData.IsNotRecordedDan)
{
return 1;
}
var danType = playMode == PlayMode.DanMode ? DanType.Normal : DanType.Gaiden;
var danPlayData = await context.DanScoreData
.Include(datum => datum.DanStageScoreData)

View File

@ -40,8 +40,6 @@ public class GameDataService(IOptions<DataSettings> dataSettings) : IGameDataSer
private List<uint> musicWithUraUniqueIdList = [];
private List<uint> lockedSongsList = [];
private List<uint> lockedUraSongsList = [];
private readonly Dictionary<uint, MusicDetail> musicDetailDictionary = new();
@ -113,11 +111,6 @@ public class GameDataService(IOptions<DataSettings> dataSettings) : IGameDataSer
return lockedSongsList;
}
public List<uint> GetLockedUraSongsList()
{
return lockedUraSongsList;
}
public Dictionary<uint, MusicDetail> GetMusicDetailDictionary()
{
return musicDetailDictionary;
@ -383,7 +376,6 @@ public class GameDataService(IOptions<DataSettings> dataSettings) : IGameDataSer
{
lockedSongsData.ThrowIfNull("Shouldn't happen!");
lockedSongsList = lockedSongsData["songNo"].ToList();
lockedUraSongsList = lockedSongsData["uraSongNo"].ToList();
}
private void InitializeMusicDetails(MusicInfos? musicInfoData, MusicOrder? musicOrderData, WordList? wordlistData)

View File

@ -27,8 +27,6 @@ public interface IGameDataService
public List<uint> GetLockedSongsList();
public List<uint> GetLockedUraSongsList();
public Dictionary<uint, MusicDetail> GetMusicDetailDictionary();
public List<Costume> GetCostumeList();

View File

@ -2,6 +2,8 @@
public interface IUserDatumService
{
public Task<List<UserDatum>> GetAllUserDatum();
public Task<UserDatum?> GetFirstUserDatumOrNull(uint baid);
public Task UpdateUserDatum(UserDatum userDatum);

View File

@ -5,6 +5,11 @@ namespace TaikoLocalServer.Services;
public class UserDatumService(TaikoDbContext context) : IUserDatumService
{
public async Task<List<UserDatum>> GetAllUserDatum()
{
return await context.UserData.Include(d => d.Tokens).ToListAsync();
}
public async Task<UserDatum?> GetFirstUserDatumOrNull(uint baid)
{
return await context.UserData

View File

@ -7,7 +7,7 @@
<MudText Typo="Typo.h6">@Localizer["Play History"]</MudText>
</MudItem>
<MudItem xs="12" md="8">
<MudText Typo="Typo.h6">@Localizer["Total Plays"]:@Items.Count</MudText>
<MudText Typo="Typo.h6">@Localizer["Total Credits Played"]:@Items.Count</MudText>
</MudItem>
</MudGrid>
</MudCardHeader>

View File

@ -13,9 +13,9 @@
<MudCardHeader>
<CardHeaderContent>
<div style="display:flex;flex-wrap:wrap;align-items:center;gap:5px;">
@if (userSetting is not null)
@if (UserSetting is not null)
{
<MudText Typo="Typo.h6" Style="font-weight:bold;word-break:break-all">@userSetting?.MyDonName</MudText>
<MudText Typo="Typo.h6" Style="font-weight:bold;word-break:break-all">@UserSetting?.MyDonName</MudText>
} else
{
<MudSkeleton Width="35%" Height="32px" />
@ -137,13 +137,13 @@
@code {
[Parameter] public User? User { get; set; }
private UserSetting? userSetting;
[Parameter] public UserSetting? UserSetting { get; set; }
protected override async Task OnInitializedAsync()
{
if (User is not null)
{
userSetting = await Client.GetFromJsonAsync<UserSetting>($"api/UserSettings/{User.Baid}");
UserSetting = await Client.GetFromJsonAsync<UserSetting>($"api/UserSettings/{User.Baid}");
}
}

View File

@ -815,6 +815,15 @@ namespace TaikoWebUI.Localization {
}
}
/// <summary>
/// Looks up a localized string similar to .
/// </summary>
internal static string Total_Credits_Played {
get {
return ResourceManager.GetString("Total Credits Played", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to .
/// </summary>

View File

@ -192,7 +192,7 @@
<data name="Last Played" xml:space="preserve">
<value>Last Played</value>
</data>
<data name="Total Plays" xml:space="preserve">
<data name="Total Credits Played" xml:space="preserve">
<value>Total Plays</value>
</data>
<data name="Total Clears" xml:space="preserve">

View File

@ -192,7 +192,7 @@
<data name="Last Played" xml:space="preserve">
<value>ラストプレイ</value>
</data>
<data name="Total Plays" xml:space="preserve">
<data name="Total Credits Played" xml:space="preserve">
<value>プレイ回数</value>
</data>
<data name="Total Clears" xml:space="preserve">

View File

@ -387,4 +387,7 @@
<data name="Rows Per Page:" xml:space="preserve">
<value />
</data>
<data name="Total Credits Played" xml:space="preserve">
<value />
</data>
</root>

View File

@ -192,7 +192,7 @@
<data name="Last Played" xml:space="preserve">
<value>最后游玩时间</value>
</data>
<data name="Total Plays" xml:space="preserve">
<data name="Total Credits Played" xml:space="preserve">
<value>总游玩次数</value>
</data>
<data name="Total Clears" xml:space="preserve">

View File

@ -192,7 +192,7 @@
<data name="Last Played" xml:space="preserve">
<value>最後遊玩時間</value>
</data>
<data name="Total Plays" xml:space="preserve">
<data name="Total Credits Played" xml:space="preserve">
<value>總遊玩次數</value>
</data>
<data name="Total Clears" xml:space="preserve">

View File

@ -9,7 +9,7 @@
<MudText Typo="Typo.h4">@Localizer["Users"]</MudText>
<MudGrid Class="my-8">
@if (!AuthService.LoginRequired || (AuthService.LoginRequired && AuthService.IsAdmin)) {
if (users == null) {
if (usersWithSettings == null) {
// Loading...
for (uint i = 0; i < 6; i++) {
<MudItem xs="12" md="6" lg="4">
@ -28,11 +28,11 @@
</MudCard>
</MudItem>
}
} else if (users.Count > 0) {
foreach (var user in users)
} else if (usersWithSettings.Count > 0) {
foreach (var (user, userSetting) in usersWithSettings)
{
<MudItem xs="12" md="6" lg="4">
<UserCard User="user" />
<UserCard User="user" UserSetting="userSetting" />
</MudItem>
}
} else { // No users in the database

View File

@ -2,7 +2,8 @@
public partial class Users
{
private List<User>? users;
// Tuple of User and UserSetting
private List<(User, UserSetting)>? usersWithSettings;
protected override async Task OnInitializedAsync()
{
@ -14,7 +15,17 @@ public partial class Users
if (AuthService.IsAdmin || !AuthService.LoginRequired)
{
users = await Client.GetFromJsonAsync<List<User>>("api/Users");
var users = await Client.GetFromJsonAsync<List<User>>("api/Users");
var userSettings = await Client.GetFromJsonAsync<List<UserSetting>>("api/UserSettings");
if (users != null && userSettings != null)
{
// Combine User and UserSetting with the same Baid
usersWithSettings = users.Join(userSettings,
user => user.Baid,
setting => setting.Baid,
(user, setting) => (user, setting))
.ToList();
}
}
}
}