feat: add delete functionality for pastes with authorization check

This commit is contained in:
2025-12-30 11:19:33 -05:00
parent f578b58780
commit 3015f97ff9
+16
View File
@@ -64,6 +64,7 @@ namespace SharpbinV3.Server.Controllers
paste.Syntax, paste.Syntax,
paste.Visibility, paste.Visibility,
paste.ExpiresAt, paste.ExpiresAt,
paste.EditedAt,
Author = paste.User != null && paste.User.Visibility == 0 ? new Author = paste.User != null && paste.User.Visibility == 0 ? new
{ {
paste.User.UID, paste.User.UID,
@@ -157,6 +158,21 @@ namespace SharpbinV3.Server.Controllers
} }
}); });
} }
[HttpDelete]
[Route("{id}")]
[Authorize]
public async Task<IActionResult> DeletePaste(string id)
{
var paste = await _pasteService.Get(id);
if (paste == null) return NotFound();
var httpUser = HttpContext.User;
var userUUID = httpUser?.FindFirst("UUID")?.Value;
if (userUUID == null || paste.AuthorUUID != Guid.Parse(userUUID))
return Forbid();
bool result = await _pasteService.Delete(paste);
if (!result) return NotFound();
return Ok(new { message = "Paste deleted successfully." });
}
[HttpGet] [HttpGet]
[Route("create/options")] [Route("create/options")]