[backend/api] Add block and unblock user endpoints
This commit is contained in:
parent
b3a190c431
commit
158fe10696
1 changed files with 42 additions and 0 deletions
|
@ -117,6 +117,48 @@ public class UserController(
|
||||||
await biteSvc.BiteAsync(user, target);
|
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")]
|
[HttpPost("{id}/follow")]
|
||||||
[Authenticate]
|
[Authenticate]
|
||||||
[Authorize]
|
[Authorize]
|
||||||
|
|
Loading…
Add table
Reference in a new issue