🧱 Localization infrastructure

This commit is contained in:
2025-05-08 01:55:32 +08:00
parent ee7dc31b20
commit 891dbfb255
19 changed files with 815 additions and 9 deletions

View File

@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using NodaTime;
using NodaTime.Extensions;
namespace DysonNetwork.Sphere.Account;
@ -261,6 +262,46 @@ public class AccountController(
return NoContent();
}
[HttpGet("me/check-in")]
[Authorize]
public async Task<ActionResult<CheckInResult>> GetCheckInResult()
{
if (HttpContext.Items["CurrentUser"] is not Account currentUser) return Unauthorized();
var userId = currentUser.Id;
var today = SystemClock.Instance.GetCurrentInstant().InUtc().Date;
var localTime = new TimeOnly(0, 0);
var startOfDay = today.ToDateOnly().ToDateTime(localTime).ToInstant();
var endOfDay = today.PlusDays(1).ToDateOnly().ToDateTime(localTime).ToInstant();
var result = await db.AccountCheckInResults
.Where(x => x.AccountId == userId)
.Where(x => x.CreatedAt >= startOfDay && x.CreatedAt < endOfDay)
.OrderByDescending(x => x.CreatedAt)
.FirstOrDefaultAsync();
return result is null ? NotFound() : Ok(result);
}
[HttpPost("me/check-in")]
[Authorize]
public async Task<ActionResult<CheckInResult>> DoCheckIn([FromBody] string? captchaToken)
{
if (HttpContext.Items["CurrentUser"] is not Account currentUser) return Unauthorized();
var isAvailable = await events.CheckInDailyIsAvailable(currentUser);
if (!isAvailable)
return BadRequest("Check-in is not available for today.");
var needsCaptcha = events.CheckInDailyDoAskCaptcha(currentUser);
if (needsCaptcha && string.IsNullOrWhiteSpace(captchaToken))
return StatusCode(423, "Captcha is required for this check-in.");
if (!await auth.ValidateCaptcha(captchaToken!))
return BadRequest("Invalid captcha token.");
return await events.CheckInDaily(currentUser);
}
[HttpGet("search")]
public async Task<List<Account>> Search([FromQuery] string query, [FromQuery] int take = 20)
{