72 lines
3.0 KiB
C#
72 lines
3.0 KiB
C#
using IM_API.Dtos;
|
|
using IM_API.Dtos.Group;
|
|
using IM_API.Interface.Services;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using System.Security.Claims;
|
|
|
|
namespace IM_API.Controllers
|
|
{
|
|
[Authorize]
|
|
[Route("api/[controller]/[action]")]
|
|
[ApiController]
|
|
public class GroupController : ControllerBase
|
|
{
|
|
private readonly IGroupService _groupService;
|
|
private readonly ILogger<GroupController> _logger;
|
|
public GroupController(IGroupService groupService, ILogger<GroupController> logger)
|
|
{
|
|
_groupService = groupService;
|
|
_logger = logger;
|
|
}
|
|
[HttpGet]
|
|
[ProducesResponseType(typeof(BaseResponse<List<GroupInfoDto>>) ,StatusCodes.Status200OK)]
|
|
public async Task<IActionResult> GetGroups(int page = 1, int limit = 100, bool desc = false)
|
|
{
|
|
var userIdStr = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
|
var list = await _groupService.GetGroupListAsync(int.Parse(userIdStr), page, limit, desc);
|
|
var res = new BaseResponse<List<GroupInfoDto>>(list);
|
|
return Ok(res);
|
|
}
|
|
|
|
[HttpPost]
|
|
[ProducesResponseType(typeof(BaseResponse<GroupInfoDto>), StatusCodes.Status200OK)]
|
|
public async Task<IActionResult> CreateGroup([FromBody]GroupCreateDto groupCreateDto)
|
|
{
|
|
var userIdStr = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
|
var groupInfo = await _groupService.CreateGroupAsync(int.Parse(userIdStr), groupCreateDto);
|
|
var res = new BaseResponse<GroupInfoDto>(groupInfo);
|
|
return Ok(res);
|
|
}
|
|
|
|
[HttpPost]
|
|
[ProducesResponseType(typeof(BaseResponse<object?>), StatusCodes.Status200OK)]
|
|
public async Task<IActionResult> HandleGroupInvite([FromBody]HandleGroupInviteDto dto)
|
|
{
|
|
string userIdStr = User.FindFirstValue(ClaimTypes.NameIdentifier)!;
|
|
await _groupService.HandleGroupInviteAsync(int.Parse(userIdStr), dto);
|
|
var res = new BaseResponse<object?>();
|
|
return Ok(res);
|
|
}
|
|
[HttpPost]
|
|
[ProducesResponseType(typeof(BaseResponse<object?>), StatusCodes.Status200OK)]
|
|
public async Task<IActionResult> HandleGroupRequest([FromBody]HandleGroupRequestDto dto)
|
|
{
|
|
string userIdStr = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
|
await _groupService.HandleGroupRequestAsync(int.Parse(userIdStr),dto);
|
|
var res = new BaseResponse<object?>();
|
|
return Ok(res);
|
|
}
|
|
[HttpPost]
|
|
[ProducesResponseType(typeof(BaseResponse<object?>), StatusCodes.Status200OK)]
|
|
public async Task<IActionResult> InviteUser([FromBody]GroupInviteUserDto dto)
|
|
{
|
|
string userIdStr = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
|
await _groupService.InviteUsersAsync(int.Parse(userIdStr), dto.GroupId, dto.Ids);
|
|
var res = new BaseResponse<object?>();
|
|
return Ok(res);
|
|
}
|
|
}
|
|
}
|