求求你不要报错了排行榜大人
This commit is contained in:
parent
5dd42a3918
commit
2b15e68017
@ -461,14 +461,15 @@ public async Task<ActionResult<all_record>> GetAdminUsersV2(string? keyword = nu
|
|||||||
|
|
||||||
//管理员设置用户的职位
|
//管理员设置用户的职位
|
||||||
[Route("api/v1/admin/setop")]
|
[Route("api/v1/admin/setop")]
|
||||||
[HttpPost]
|
[HttpGet]
|
||||||
[Authorize]
|
[Authorize]
|
||||||
public async Task<ActionResult<string>> setrole(string userid, string opname)
|
public async Task<ActionResult<string>> setrole(string userid, string opname)
|
||||||
{
|
{
|
||||||
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.joinTime = (DateTime.Now.ToString());
|
||||||
ouser.officium = opname;
|
ouser.officium = opname;
|
||||||
await userManager.UpdateAsync(ouser);
|
await userManager.UpdateAsync(ouser);
|
||||||
|
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
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 System.Buffers.Text;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
using System.Security.Claims;
|
using System.Security.Claims;
|
||||||
using static asg_form.blog;
|
using static asg_form.blog;
|
||||||
@ -182,28 +184,51 @@ namespace asg_form.Controllers
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class userRanking
|
||||||
|
{
|
||||||
|
public long userId { get; set; }
|
||||||
|
public string username { get; set; }
|
||||||
|
public string joinTime { get; set; }
|
||||||
|
public string base64 { get; set; }
|
||||||
|
public int count { 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")
|
||||||
|
.AsEnumerable()
|
||||||
|
.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,
|
||||||
|
base64 = u.UserBase64,
|
||||||
|
//count = (int)((currentTime - u.joinTime.ToDateTime()).TotalSeconds/ 86400),
|
||||||
|
})
|
||||||
|
.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 });
|
||||||
} */
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,7 @@ 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>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user