mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-07-29 16:38:37 +00:00
Add Delete Photo endpoint
This commit is contained in:
parent
084dcf1f75
commit
dc2175d6e4
1 changed files with 15 additions and 0 deletions
|
@ -115,5 +115,20 @@ namespace LBPUnion.ProjectLighthouse.Controllers
|
|||
|
||||
return this.Ok(LbpSerializer.StringElement("photos", response));
|
||||
}
|
||||
|
||||
[HttpPost("deletePhoto/{id:int}")]
|
||||
public async Task<IActionResult> DeletePhoto(int id)
|
||||
{
|
||||
User? user = await this.database.UserFromRequest(this.Request);
|
||||
if (user == null) return this.StatusCode(403, "");
|
||||
|
||||
Photo? photo = await this.database.Photos.FirstOrDefaultAsync(p => p.PhotoId == id);
|
||||
if (photo == null) return this.NotFound();
|
||||
if (photo.CreatorId != user.UserId) return this.StatusCode(401, "");
|
||||
|
||||
this.database.Photos.Remove(photo);
|
||||
await this.database.SaveChangesAsync();
|
||||
return this.Ok();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue