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))] public async Task 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 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 Block([FromQuery] Guid friendId) { var userId = User.FindFirstValue(ClaimTypes.NameIdentifier); return Ok(await service.BlockFriendAsync(Guid.Parse(userId), friendId)); } [HttpGet] public async Task CheckFriend(Guid userId, Guid targetId) { return Ok(await service.CheckFriendAsync(userId, targetId)); } } }