mirror of
https://github.com/Govor-team/Govor.git
synced 2026-11-18 05:15:06 +00:00
Add forwarding, friend controls, and benefits
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.
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
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(); }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user