排行榜

This commit is contained in:
王炜翔 2025-04-10 16:08:31 +08:00
parent ec75b903ed
commit 5dc30419e1
2 changed files with 42 additions and 16 deletions

View File

@ -467,13 +467,16 @@ public async Task<ActionResult<all_record>> GetAdminUsersV2(string? keyword = nu
{ {
if (this.User.FindAll(ClaimTypes.Role).Any(a => a.Value == "admin")) if (this.User.FindAll(ClaimTypes.Role).Any(a => a.Value == "admin"))
{ {
var ouser = await userManager.FindByIdAsync(userid);
var ouser = await userManager.FindByIdAsync(userid);
ouser.officium = opname; ouser.officium = opname;
if(ouser.joinTime == null) ouser.joinTime = DateTime.Now.ToString();
await userManager.UpdateAsync(ouser); await userManager.UpdateAsync(ouser);
return "成功"; return Ok(new { code = 200, message = "成功" });
} }
else else
{ {

View File

@ -1,11 +1,15 @@
using Manganese.Text; using Manganese.Text;
using Masuit.Tools;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using SharpCompress.Archives;
using System.Data; using System.Data;
using System.Security.Claims; using System.Security.Claims;
using static asg_form.blog; using static asg_form.blog;
using static asg_form.Controllers.user_form;
using static System.Runtime.InteropServices.JavaScript.JSType;
namespace asg_form.Controllers namespace asg_form.Controllers
{ {
@ -189,26 +193,45 @@ namespace asg_form.Controllers
public string joinTime { get; set; } public string joinTime { get; set; }
} }
public class userRanking
{
public long userId { get; set; }
public string username { get; set; }
public string joinTime { get; set; }
}
/// <summary> /// <summary>
/// 职位时间设置接口 /// 解说排行榜
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
[Authorize] [Route("api/v1/user/ranking")]
[Route("api/v1/user/settime")] [HttpGet]
[HttpPost] public async Task<ActionResult<object>> rankingList(short page = 1, short limit = 10)
public async Task<ActionResult<object>> settime([FromBody] timeSet msg)
{ {
try
string userId = this.User.FindFirst(ClaimTypes.NameIdentifier)!.Value;
var user = await userManager.FindByIdAsync(userId);
if(user.officium != "Commentator")
{ {
return Ok(new { code = 200, message = "你不是解说,不参与排名!" }); DateTime currentTime = DateTime.Now;
var rankings = userManager.Users
.Where(u => u.joinTime != null && u.officium == "Commentator")
.OrderByDescending(u => (currentTime - u.joinTime.ToDateTime()).TotalSeconds)
.Skip((page - 1) * limit)
.Take(limit)
.Select(u => new userRanking
{
userId = u.Id,
username = u.chinaname,
joinTime = u.joinTime,
})
.ToList();
return Ok(new { code = 200, message = "", rankings });
} }
user.joinTime = msg.joinTime; catch (Exception ex)
await userManager.UpdateAsync(user); {
return Ok(new { code = 200, message = "你成功修改了自己加入ASG的时间" }); return StatusCode(500, new { code = 500, message = "获取排行榜失败", error = ex.Message });
}
} }
} }