63 lines
2.2 KiB
C#
63 lines
2.2 KiB
C#
using IdentityService.Infrastructure;
|
|
using IdentityService.WebApi.Applications.Dtos.Common;
|
|
using IdentityService.WebApi.Applications.User;
|
|
using IM.ASPNETCore;
|
|
using IM.Commons;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using System.Security.Claims;
|
|
|
|
namespace IdentityService.WebApi.Controllers.User
|
|
{
|
|
[Authorize]
|
|
[UnitOfWork(typeof(UserDbContext))]
|
|
[Route("api/[controller]/[action]")]
|
|
[ApiController]
|
|
public class UserController : ControllerBase
|
|
{
|
|
private readonly UserService userService;
|
|
public UserController(UserService userService)
|
|
{
|
|
this.userService = userService;
|
|
}
|
|
|
|
[HttpGet]
|
|
[ProducesDefaultResponseType(typeof(Result<UserResponse?>))]
|
|
public async Task<IActionResult> Me()
|
|
{
|
|
var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
|
var res = await userService.GetUserInfoAsync(Guid.Parse(userId));
|
|
return Ok(res);
|
|
}
|
|
|
|
[HttpGet]
|
|
[ProducesDefaultResponseType(typeof(Result<UserResponse?>))]
|
|
public async Task<IActionResult> Find(Guid userId)
|
|
{
|
|
return Ok(await userService.GetUserInfoAsync(userId));
|
|
}
|
|
[HttpGet]
|
|
[ProducesDefaultResponseType(typeof(Result<UserResponse?>))]
|
|
public async Task<IActionResult> FindByUname(string username)
|
|
{
|
|
return Ok(await userService.GetUserInfoByUnameAsync(username));
|
|
}
|
|
|
|
[HttpPost]
|
|
[ProducesDefaultResponseType(typeof(Result<UserResponse>))]
|
|
public async Task<IActionResult> Update([FromBody] UserUpdateRequest request)
|
|
{
|
|
var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
|
var res = await userService.UpdateAsync(new UserUpdateCommand(Guid.Parse(userId), request.NickName, request.Region, request.Avatar, request.Description));
|
|
return Ok(res);
|
|
}
|
|
|
|
[HttpPost]
|
|
[ProducesDefaultResponseType(typeof(Result<List<UserResponse>>))]
|
|
public async Task<IActionResult> GetUsersByIds([FromBody] List<Guid> ids)
|
|
{
|
|
return Ok(await userService.GetUsersByIdsAsync(ids));
|
|
}
|
|
}
|
|
}
|