添加项目文件。
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
using ContactService.Infrastructure;
|
||||
using ContactService.WebApi.Application.Dtos;
|
||||
using ContactService.WebApi.Application.Friend;
|
||||
using IM.ASPNETCore;
|
||||
using IM.Commons;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Security.Claims;
|
||||
|
||||
namespace ContactService.WebApi.Controllers
|
||||
{
|
||||
[Authorize]
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class FriendController : ControllerBase
|
||||
{
|
||||
private readonly FriendService service;
|
||||
|
||||
public FriendController(FriendService service)
|
||||
{
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[ProducesDefaultResponseType(typeof(Result<FriendResonse>))]
|
||||
public async Task<IActionResult> List()
|
||||
{
|
||||
var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
var friends = await service.GetFriendsByOwnerIdAsync(Guid.Parse(userId));
|
||||
return Ok(friends);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[UnitOfWork(typeof(ContactDbContext))]
|
||||
public async Task<IActionResult> Delete([FromQuery] Guid friendId)
|
||||
{
|
||||
var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
return Ok(await service.DeleteFriendAsync(Guid.Parse(userId), friendId));
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[UnitOfWork(typeof(ContactDbContext))]
|
||||
public async Task<IActionResult> Block([FromQuery] Guid friendId)
|
||||
{
|
||||
var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
return Ok(await service.BlockFriendAsync(Guid.Parse(userId), friendId));
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> CheckFriend(Guid userId, Guid targetId)
|
||||
{
|
||||
return Ok(await service.CheckFriendAsync(userId, targetId));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using FluentValidation;
|
||||
|
||||
namespace ContactService.WebApi.Controllers
|
||||
{
|
||||
public class FriendRequestAddRequest
|
||||
{
|
||||
public Guid TargetId { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public string? RemarkName { get; set; }
|
||||
|
||||
}
|
||||
|
||||
public class FriendRequestAddRequestValidator : AbstractValidator<FriendRequestAddRequest>
|
||||
{
|
||||
public FriendRequestAddRequestValidator()
|
||||
{
|
||||
RuleFor(r => r.TargetId)
|
||||
.NotEmpty()
|
||||
.NotNull()
|
||||
;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
using ContactService.Infrastructure;
|
||||
using ContactService.WebApi.Application.Dtos;
|
||||
using ContactService.WebApi.Application.FriendRequest;
|
||||
using IM.ASPNETCore;
|
||||
using IM.Commons;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Security.Claims;
|
||||
|
||||
namespace ContactService.WebApi.Controllers
|
||||
{
|
||||
[Authorize]
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class FriendRequestController : ControllerBase
|
||||
{
|
||||
private readonly FriendRequestService service;
|
||||
|
||||
public FriendRequestController(FriendRequestService service)
|
||||
{
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[UnitOfWork(typeof(ContactDbContext))]
|
||||
[ProducesDefaultResponseType(typeof(Result<FriendRequestResponse?>))]
|
||||
public async Task<IActionResult> Add(FriendRequestAddRequest request)
|
||||
{
|
||||
var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
return Ok(await service.CreateAsync(new CreateFriendRequestCommand(Guid.Parse(userId), request.TargetId, request.Description, request.RemarkName)));
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[UnitOfWork(typeof(ContactDbContext))]
|
||||
public async Task<IActionResult> Handle(FriendRequestHandleRequest request)
|
||||
{
|
||||
var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
return Ok(await service.UpdateStatusAsync(new FriendRequestHandleCommand(Guid.Parse(userId), request.RequestId, request.Action,request.RemarkName)));
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> List()
|
||||
{
|
||||
var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
return Ok(await service.GetByTargetIdOrOwnerIdAsync(Guid.Parse(userId)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
using ContactService.WebApi.Application.FriendRequest;
|
||||
using FluentValidation;
|
||||
|
||||
namespace ContactService.WebApi.Controllers
|
||||
{
|
||||
public class FriendRequestHandleRequest
|
||||
{
|
||||
public Guid RequestId { get; set; }
|
||||
public FriendRequestAction Action { get; set; }
|
||||
public string? RemarkName { get; set; }
|
||||
}
|
||||
|
||||
public class FriendRequestHandleRequestValidator : AbstractValidator<FriendRequestHandleRequest>
|
||||
{
|
||||
public FriendRequestHandleRequestValidator()
|
||||
{
|
||||
RuleFor(r => r.RequestId)
|
||||
.NotEmpty()
|
||||
.NotNull();
|
||||
|
||||
When(w => w.Action == FriendRequestAction.Accpet, () =>
|
||||
{
|
||||
RuleFor(r => r.RemarkName)
|
||||
.NotEmpty()
|
||||
.NotNull();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user