Skip to content

Commit

Permalink
Fix TryCatchLearn#5: Delete unapproved photo not working
Browse files Browse the repository at this point in the history
  • Loading branch information
rewgoes committed Feb 15, 2021
1 parent 49b4d34 commit f3c276d
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion API/Controllers/UsersController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ public async Task<ActionResult> SetMainPhoto(int photoId)
[HttpDelete("delete-photo/{photoId}")]
public async Task<ActionResult> DeletePhoto(int photoId)
{
var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync(User.GetUsername());
var user = await _unitOfWork.UserRepository.GetUserByPhotoId(photoId);

if (user.UserName != User.GetUsername()) return Unauthorized("You cannot delete this photo");

var photo = user.Photos.FirstOrDefault(x => x.Id == photoId);

Expand Down

0 comments on commit f3c276d

Please sign in to comment.