This commit is contained in:
王炜翔 2024-10-11 21:28:37 +08:00
parent 3fd3bf346b
commit 19ad65b51a

View File

@ -3,10 +3,12 @@ using Masuit.Tools;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Abstractions;
using Microsoft.EntityFrameworkCore;
using System;
using System.Security.Claims;
using System.Text.Json;
using System.Threading.Tasks;
namespace asg_form.Controllers
{
@ -46,7 +48,7 @@ namespace asg_form.Controllers
[Route("api/v1/Invite")]
[HttpPost]
[Authorize]
public async Task<ActionResult<object>> GetReferee([FromBody] inv msg)
public async Task<ActionResult<object>> Toinvite([FromBody] inv msg)
{
string Invitorid = this.User.FindFirst(ClaimTypes.NameIdentifier)!.Value;
var user = await userManager.FindByIdAsync(Invitorid);
@ -117,5 +119,83 @@ namespace asg_form.Controllers
}
}
public class idToString
{
public string invitedName { get; set; }
public string matchName { get; set; }
}
[Route("api/v1/myInvitation")]
[HttpGet]
[Authorize]
public async Task<ActionResult<object>> GetMyInvitor([FromQuery]short page = 1, short limit = 6)
{
string Forid = this.User.FindFirst(ClaimTypes.NameIdentifier)!.Value;
var user = await userManager.FindByIdAsync(Forid);
long userId = user.Id;
using (TestDbContext sub = new TestDbContext())
{
try
{
var query = sub.T_Invitation.FirstOrDefault(c => c.user_id == userId);
if (query != null)
{
List<idRequest> existingPairs = JsonSerializer.Deserialize<List<idRequest>>(json: query.my_request);
var TotalRecords = existingPairs.Count;
int skip = (page - 1) * limit;
List<idToString> Invintors = new List<idToString>();
var queryForMatchName = sub.team_Games;
idToString dataAdd=new idToString();
foreach (var pair in existingPairs)
{
var userInvited = await userManager.Users.FirstOrDefaultAsync(x => x.Id ==pair.invited_id);
dataAdd.invitedName = userInvited.chinaname;
var matchFind = queryForMatchName.FirstOrDefault(c => c.id == pair.match_id);
dataAdd.matchName = matchFind.team1_name + "VS" + matchFind.team2_name + " " + matchFind.opentime.ToString();
Invintors.Add(dataAdd);
}
Invintors
.Skip(skip)
.Take(limit)
.ToList();
var result = new
{
rows = Invintors,
total = TotalRecords,
};
return Ok(new
{
code = 200,
message = "成功获取邀请",
result
});
}
return Ok(new { code = 200, message = "没有收到邀请" });
}
catch (Exception ex)
{
return Ok(new { code = 500, message = "服务器错误", details = ex.Message});
}
}
}
[Route("api/v1/toInvite")]
[HttpGet]
[Authorize]
public async Task<ActionResult<object>> ToInvite()
{
string Myid = this.User.FindFirst(ClaimTypes.NameIdentifier)!.Value;
var user = await userManager.FindByIdAsync(Myid);
long userId = user.Id;
return Ok(new { code = 200, message = "没有完成的功能" });
}
}
}