diff --git a/ProjectLighthouse/Controllers/PhotosController.cs b/ProjectLighthouse/Controllers/PhotosController.cs index 7255fc6c..d5559365 100644 --- a/ProjectLighthouse/Controllers/PhotosController.cs +++ b/ProjectLighthouse/Controllers/PhotosController.cs @@ -115,5 +115,20 @@ namespace LBPUnion.ProjectLighthouse.Controllers return this.Ok(LbpSerializer.StringElement("photos", response)); } + + [HttpPost("deletePhoto/{id:int}")] + public async Task 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(); + } } } \ No newline at end of file