From 9bb1ca6ccc2980d65ad4e0e18074faf936a2e5b3 Mon Sep 17 00:00:00 2001 From: Owczarek Kamil Date: Thu, 13 Jun 2024 01:21:10 +0200 Subject: [PATCH] changes --- .../ReasnAPI/ReasnAPI/Services/EventService.cs | 2 +- .../ReasnAPI/ReasnAPI/Services/ImageService.cs | 16 ++++++++-------- Server/ReasnAPI/ReasnAPI/Services/TagService.cs | 7 ++++++- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/Server/ReasnAPI/ReasnAPI/Services/EventService.cs b/Server/ReasnAPI/ReasnAPI/Services/EventService.cs index 261467ee..a086f868 100644 --- a/Server/ReasnAPI/ReasnAPI/Services/EventService.cs +++ b/Server/ReasnAPI/ReasnAPI/Services/EventService.cs @@ -219,7 +219,7 @@ public IEnumerable GetEventParticipantsBySlug(string slug) public IEnumerable GetEventCommentsBySlug(string slug) { var eventToReturn = context.Events.Include(e => e.Comments) - .Include(e => e.Participants).FirstOrDefault(e => e.Slug == slug); + .FirstOrDefault(e => e.Slug == slug); if (eventToReturn is null) { throw new NotFoundException("Event not found"); diff --git a/Server/ReasnAPI/ReasnAPI/Services/ImageService.cs b/Server/ReasnAPI/ReasnAPI/Services/ImageService.cs index 5d1d769a..b5b651b4 100644 --- a/Server/ReasnAPI/ReasnAPI/Services/ImageService.cs +++ b/Server/ReasnAPI/ReasnAPI/Services/ImageService.cs @@ -105,7 +105,7 @@ public void UpdateImageForUser(int userId, ImageDto imageDto) } var image = context.Images.FirstOrDefault(i => i.ObjectType == ObjectType.User && i.ObjectId == userId); - if (image == null) + if (image is null) { throw new NotFoundException("Image not found"); } @@ -130,23 +130,23 @@ public void DeleteImageById(int id) public void DeleteImageRelatedToEvent(int id, string slug) { - var @event = context.Events.FirstOrDefault(r => r.Slug == slug); - if (@event is null) + var relatedEvent = context.Events.FirstOrDefault(r => r.Slug == slug); + if (relatedEvent is null) { throw new NotFoundException("Event not found"); } - if (@event.Id != id) - { - throw new NotFoundException("Image is not related with this event"); - } - var image = context.Images.FirstOrDefault(r => r.Id == id); if (image is null) { throw new NotFoundException("Image not found"); } + if (image.ObjectId != relatedEvent.Id || image.ObjectType != ObjectType.Event) + { + throw new NotFoundException("This image is not related with this event"); + } + context.Images.Remove(image); context.SaveChanges(); } diff --git a/Server/ReasnAPI/ReasnAPI/Services/TagService.cs b/Server/ReasnAPI/ReasnAPI/Services/TagService.cs index b2bf30b8..f9f13f89 100644 --- a/Server/ReasnAPI/ReasnAPI/Services/TagService.cs +++ b/Server/ReasnAPI/ReasnAPI/Services/TagService.cs @@ -40,6 +40,11 @@ public TagDto UpdateTag(int tagId, TagDto tagDto) public void AddTagsFromList(List tagsToAdd) { + if (tagsToAdd is null) + { + throw new ArgumentException("No tag provided"); + } + var existingTagsInDb = context.Tags .Where(tag => tagsToAdd.Any(newTag => newTag.Name == tag.Name)) .ToList(); @@ -56,7 +61,7 @@ public void DeleteTag(int tagId) { var tag = context.Tags.FirstOrDefault(r => r.Id == tagId); - if (tag == null) + if (tag is null) { throw new NotFoundException("Tag not found"); }