Files
IM_NEW/ContactService.WebApi/Controllers/FriendController.cs
2026-05-09 17:06:30 +08:00

56 lines
1.8 KiB
C#

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));
}
}
}