添加项目文件。
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
using GroupService.Infrastructure;
|
||||
using GroupService.WebApi.Application.Dtos;
|
||||
using GroupService.WebApi.Application.Group;
|
||||
using IM.ASPNETCore;
|
||||
using IM.Commons;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Security.Claims;
|
||||
|
||||
namespace GroupService.WebApi.Controllers.Group
|
||||
{
|
||||
[Route("api/[controller]/[action]")]
|
||||
[Authorize]
|
||||
[ApiController]
|
||||
public class GroupController : ControllerBase
|
||||
{
|
||||
private readonly Application.Group.GroupService service;
|
||||
|
||||
public GroupController(Application.Group.GroupService service)
|
||||
{
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[ProducesDefaultResponseType(typeof(Result<List<GroupResponse>>))]
|
||||
public async Task<IActionResult> GetAll()
|
||||
{
|
||||
var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
return Ok(await service.GetAllAsync(Guid.Parse(userId)));
|
||||
}
|
||||
[HttpGet("~/api/[controller]/{userId}")]
|
||||
[ProducesDefaultResponseType(typeof(Result<GroupResponse>))]
|
||||
public async Task<IActionResult> GetOne([FromRoute] Guid userId)
|
||||
{
|
||||
return Ok(await service.GetByIdAsync(userId));
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[UnitOfWork(typeof(GroupDbContext))]
|
||||
public async Task<IActionResult> Create(GroupCreateRequest request)
|
||||
{
|
||||
var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
return Ok(await service.CreateAsync(new GroupCreateCommand(Guid.Parse(userId), request.Name)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using FluentValidation;
|
||||
|
||||
namespace GroupService.WebApi.Controllers.Group
|
||||
{
|
||||
public class GroupCreateRequest
|
||||
{
|
||||
public string? Name { get; set; }
|
||||
}
|
||||
|
||||
public class GroupCreateRequestValidator : AbstractValidator<GroupCreateRequest>
|
||||
{
|
||||
public GroupCreateRequestValidator()
|
||||
{
|
||||
RuleFor(r => r.Name)
|
||||
.MaximumLength(20);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
using GroupService.Infrastructure;
|
||||
using GroupService.WebApi.Application.GroupInvitation;
|
||||
using IM.ASPNETCore;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Security.Claims;
|
||||
|
||||
namespace GroupService.WebApi.Controllers.GroupInvitation
|
||||
{
|
||||
[Authorize]
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class GroupInvitationController : ControllerBase
|
||||
{
|
||||
private readonly GroupInvitationService service;
|
||||
|
||||
public GroupInvitationController(GroupInvitationService service)
|
||||
{
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[UnitOfWork(typeof(GroupDbContext))]
|
||||
public async Task<IActionResult> Send([FromBody] GroupInvitationRequest request)
|
||||
{
|
||||
var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
return Ok(await service.CreateAsync(Guid.Parse(userId), request.UserId, request.GroupId));
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> Get([FromQuery] Guid invitationId)
|
||||
{
|
||||
var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
return Ok(await service.GetByIdAsync(invitationId, Guid.Parse(userId)));
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[UnitOfWork(typeof(GroupDbContext))]
|
||||
public async Task<IActionResult> Handle([FromQuery] Guid invitationId, [FromQuery] GroupInvitationAction action)
|
||||
{
|
||||
var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
return Ok(await service.HandleAsync(new GroupInvitationHandleCommand(invitationId, Guid.Parse(userId), action)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using FluentValidation;
|
||||
|
||||
namespace GroupService.WebApi.Controllers.GroupInvitation
|
||||
{
|
||||
public class GroupInvitationRequest
|
||||
{
|
||||
public Guid GroupId { get; set; }
|
||||
public Guid UserId { get; set; }
|
||||
}
|
||||
|
||||
public class GroupInvitationRequestValidator : AbstractValidator<GroupInvitationRequest>
|
||||
{
|
||||
public GroupInvitationRequestValidator()
|
||||
{
|
||||
RuleFor(r => r.UserId)
|
||||
.NotNull()
|
||||
.NotEmpty();
|
||||
|
||||
RuleFor(r => r.GroupId)
|
||||
.NotEmpty()
|
||||
.NotNull();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
using GroupService.Infrastructure;
|
||||
using GroupService.WebApi.Application.GroupMember;
|
||||
using IM.ASPNETCore;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Security.Claims;
|
||||
|
||||
namespace GroupService.WebApi.Controllers.GroupMember
|
||||
{
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class GroupMemberController : ControllerBase
|
||||
{
|
||||
private readonly GroupMemberService service;
|
||||
|
||||
public GroupMemberController(GroupMemberService service)
|
||||
{
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> CheckMember(Guid userId, Guid groupId)
|
||||
{
|
||||
return Ok(await service.CheckMemberAsync(groupId, userId));
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> List(Guid groupId)
|
||||
{
|
||||
return Ok(await service.GetByGroupIdAsync(groupId));
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[UnitOfWork(typeof(GroupDbContext))]
|
||||
public async Task<IActionResult> Delete([FromQuery] Guid memberId)
|
||||
{
|
||||
var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
return Ok(await service.DeleteAsync(memberId, Guid.Parse(userId)));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
using GroupService.Infrastructure;
|
||||
using GroupService.WebApi.Application.GroupRequest;
|
||||
using IM.ASPNETCore;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Security.Claims;
|
||||
|
||||
namespace GroupService.WebApi.Controllers.GroupRequest
|
||||
{
|
||||
[Authorize]
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class GroupRequestController : ControllerBase
|
||||
{
|
||||
private readonly GroupRequestService service;
|
||||
|
||||
public GroupRequestController(GroupRequestService service)
|
||||
{
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[UnitOfWork(typeof(GroupDbContext))]
|
||||
public async Task<IActionResult> Send([FromBody] GroupRequestRequest request)
|
||||
{
|
||||
var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
return Ok(await service.CreateAsync(request.GroupId, Guid.Parse(userId), request.Desc));
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[UnitOfWork(typeof(GroupDbContext))]
|
||||
public async Task<IActionResult> Handle([FromQuery] Guid requestId, [FromQuery] RequestHandleAction action)
|
||||
{
|
||||
var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
return Ok(await service.HandleAsync(new RequestHandleCommand(requestId, Guid.Parse(userId), action)));
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> Find([FromQuery] Guid id)
|
||||
{
|
||||
var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
return Ok(await service.GetByIdAsync(id, Guid.Parse(userId)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using FluentValidation;
|
||||
|
||||
namespace GroupService.WebApi.Controllers.GroupRequest
|
||||
{
|
||||
public class GroupRequestRequest
|
||||
{
|
||||
public Guid GroupId { get; set; }
|
||||
public string? Desc { get; set; }
|
||||
}
|
||||
|
||||
public class GroupRequestRequestValidator : AbstractValidator<GroupRequestRequest>
|
||||
{
|
||||
public GroupRequestRequestValidator()
|
||||
{
|
||||
RuleFor(r => r.GroupId)
|
||||
.NotEmpty()
|
||||
.NotNull();
|
||||
|
||||
RuleFor(r => r.Desc)
|
||||
.MaximumLength(20)
|
||||
.WithMessage("入群描述不可超过20字符")
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user