This commit is contained in:
王炜翔 2025-04-10 18:46:01 +08:00
parent 5dc30419e1
commit 56e210d9c0
3 changed files with 22 additions and 48 deletions

View File

@ -467,16 +467,13 @@ 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 Ok(new { code = 200, message = "成功" }); return "成功";
} }
else else
{ {

View File

@ -1,15 +1,14 @@
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; <<<<<<< HEAD
=======
using System.Data; using System.Data;
>>>>>>> parent of 5dc3041 ()
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
{ {
@ -188,52 +187,31 @@ namespace asg_form.Controllers
} }
public class timeSet
{
public string joinTime { get; set; }
}
public class userRanking
{
public long userId { get; set; }
public string username { get; set; }
public string joinTime { get; set; }
}
<<<<<<< HEAD
=======
/// <summary> /// <summary>
/// 解说排行榜 /// 职位时间设置接口
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
[Route("api/v1/user/ranking")] [Authorize]
[HttpGet] [Route("api/v1/user/settime")]
public async Task<ActionResult<object>> rankingList(short page = 1, short limit = 10) [HttpPost]
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")
{ {
DateTime currentTime = DateTime.Now; return Ok(new { code = 200, message = "你不是解说,不参与排名!" });
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 });
} }
catch (Exception ex) user.joinTime = msg.joinTime;
{ await userManager.UpdateAsync(user);
return StatusCode(500, new { code = 500, message = "获取排行榜失败", error = ex.Message }); return Ok(new { code = 200, message = "你成功修改了自己加入ASG的时间" });
} >>>>>>> parent of 5dc3041 ()
} }
}
} }

View File

@ -29,7 +29,6 @@ namespace asg_form
//public List<string>? Roles { get; set; } //public List<string>? Roles { get; set; }
public string? roleListName { get; set; } public string? roleListName { get; set; }
public string? roleListCode { get; set; } public string? roleListCode { get; set; }
public string? joinTime { get; set; }
} }
public class Role : IdentityRole<long> public class Role : IdentityRole<long>