[backend/api] Add block and unblock user endpoints

This commit is contained in:
pancakes 2025-02-23 15:31:24 +10:00 committed by Laura Hausmann
parent b3a190c431
commit 158fe10696
No known key found for this signature in database
GPG key ID: D044E84C5BE01605

View file

@ -117,6 +117,48 @@ public class UserController(
await biteSvc.BiteAsync(user, target);
}
[HttpPost("{id}/block")]
[Authenticate]
[Authorize]
[ProducesResults(HttpStatusCode.OK)]
[ProducesErrors(HttpStatusCode.BadRequest, HttpStatusCode.NotFound)]
public async Task BlockUser(string id)
{
var user = HttpContext.GetUserOrFail();
if (user.Id == id)
throw GracefulException.BadRequest("You cannot block yourself");
var blockee = await db.Users
.Where(p => p.Id == id)
.IncludeCommonProperties()
.PrecomputeRelationshipData(user)
.FirstOrDefaultAsync()
?? throw GracefulException.RecordNotFound();
await userSvc.BlockUserAsync(user, blockee);
}
[HttpPost("{id}/unblock")]
[Authenticate]
[Authorize]
[ProducesResults(HttpStatusCode.OK)]
[ProducesErrors(HttpStatusCode.BadRequest, HttpStatusCode.NotFound)]
public async Task UnblockUser(string id)
{
var user = HttpContext.GetUserOrFail();
if (user.Id == id)
throw GracefulException.BadRequest("You cannot unblock yourself");
var blockee = await db.Users
.Where(p => p.Id == id)
.IncludeCommonProperties()
.PrecomputeRelationshipData(user)
.FirstOrDefaultAsync()
?? throw GracefulException.RecordNotFound();
await userSvc.UnblockUserAsync(user, blockee);
}
[HttpPost("{id}/follow")]
[Authenticate]
[Authorize]