添加项目文件。
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user