mirror of
https://github.com/Govor-team/Govor.git
synced 2026-11-16 20:56:03 +00:00
632ac04b56
Add message forwarding and reply lookup, friend removal and blocking endpoints, and database-backed Govor+ privileges with customizable profile tags. Include migrations, integration tests, and updated API and operations documentation.
31 lines
1.2 KiB
C#
31 lines
1.2 KiB
C#
using Govor.Application.Friends;
|
|
using Govor.Application.Infrastructure.Extensions;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace Govor.API.Controllers.Friends;
|
|
|
|
[ApiController]
|
|
[Authorize]
|
|
[Route("api/friends/{userId:guid}")]
|
|
public sealed class FriendManagementController(IFriendshipService friends, IFriendsBlockService blocks,
|
|
ICurrentUserService currentUser) : ControllerBase
|
|
{
|
|
[HttpDelete]
|
|
public Task<IActionResult> Remove(Guid userId) => Execute(() => friends.RemoveFriendAsync(userId, currentUser.GetCurrentUserId()));
|
|
|
|
[HttpPut("block")]
|
|
public Task<IActionResult> Block(Guid userId) => Execute(() => blocks.BlockFriendRequestAsync(userId, currentUser.GetCurrentUserId()));
|
|
|
|
[HttpDelete("block")]
|
|
public Task<IActionResult> Unblock(Guid userId) => Execute(() => blocks.UnblockFriendRequestAsync(userId, currentUser.GetCurrentUserId()));
|
|
|
|
private async Task<IActionResult> Execute(Func<Task> action)
|
|
{
|
|
try { await action(); return NoContent(); }
|
|
catch (ArgumentException ex) { return BadRequest(new { error = ex.Message }); }
|
|
catch (KeyNotFoundException) { return NotFound(); }
|
|
catch (UnauthorizedAccessException) { return Forbid(); }
|
|
}
|
|
}
|