Skip to content

Commit

Permalink
[RSN-59] - Created EventsController (#59)
Browse files Browse the repository at this point in the history
* feat: add jwt and exceptions handlers

Simplify the logic on the controllers' side, custom exceptions and
a library for validation were added. The implemented handlers are
allow to catch those exceptions and return the corresponding
statuses and detailed response.

Additionally, mappers have been created to more easily convert
entities into the corresponding DTOs, fixed enum conversion
when it comes to UserRole and export postgres port on the
development environment.

* test: add unit tests for jwt, handlers and validators

* feat: add placeholders for endpoints

* chore: add missing controllers placeholders

* Created EventsController

* Little Updates

* Updated controllers

* Update adding and updating image in eventController

* Updated eventcontroller logic

* Updated EventsController

* Fixed build issues

* updated eventscontroller

* fixed build issue

addedscope for address service

* Update EventServicesTest.cs

* Update EventsController.cs

* syntax update

* updated models

changed removing tags and params that are not attached to any event, thay will be hold in database

* Update EventServicesTest.cs

* Updated EventController

* updated events controller

added returnign empty list if image for event is not found, filtered get all events to not return waiting for aproval events

* updated logic in getallaevenst

it wont return events where status is receted canceled and panding aproval

* fixes and updates

* Fixes and cleanup after rebase and confilts

* Update EventService.cs

* updates

* Updated logic with slag on creation

* Update EventValidatorTests.cs

* Update EventValidatorTests.cs

---------

Co-authored-by: raczu <[email protected]>
  • Loading branch information
bilimig and raczu authored Jun 23, 2024
1 parent f42c647 commit ad1d209
Show file tree
Hide file tree
Showing 22 changed files with 683 additions and 194 deletions.
12 changes: 5 additions & 7 deletions Server/ReasnAPI/ReasnAPI.Tests/Services/EventServicesTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public void UpdateEvent_EventExists_EventUpdated()
var eventDto = new EventDto()
{
Name = "name1",
AddressId = 1,
Description = "description2",
OrganizerId = 1,
StartAt = DateTime.Now,
Expand Down Expand Up @@ -82,7 +81,7 @@ public void UpdateEvent_EventExists_EventUpdated()
mockContext.Setup(c => c.Parameters).ReturnsDbSet(new List<Parameter>());
mockContext.Setup(c => c.Comments).ReturnsDbSet(new List<Comment>());
mockContext.Setup(c => c.Participants).ReturnsDbSet(new List<Participant>());
var eventService = new EventService(mockContext.Object, new ParameterService(mockContext.Object), new TagService(mockContext.Object), new CommentService(mockContext.Object));
var eventService = new EventService(mockContext.Object, new ParameterService(mockContext.Object), new TagService(mockContext.Object), new CommentService(mockContext.Object), new AddressService(mockContext.Object), new ImageService(mockContext.Object));

var result = eventService.UpdateEvent(1, eventDto);
Assert.AreEqual("name1", result.Name);
Expand All @@ -102,7 +101,6 @@ public void UpdateEvent_EventDoesNotExist_NullReturned()
var eventDto = new EventDto()
{
Name = "name1",
AddressId = 1,
Description = "description2",
OrganizerId = 1,
StartAt = DateTime.Now,
Expand Down Expand Up @@ -144,7 +142,7 @@ public void UpdateEvent_EventDoesNotExist_NullReturned()
UpdatedAt =DateTime.Now
}});

var eventService = new EventService(mockContext.Object, new ParameterService(mockContext.Object), new TagService(mockContext.Object), new CommentService(mockContext.Object));
var eventService = new EventService(mockContext.Object, new ParameterService(mockContext.Object), new TagService(mockContext.Object), new CommentService(mockContext.Object), new AddressService(mockContext.Object), new ImageService(mockContext.Object));

Assert.ThrowsException<NotFoundException>(() => eventService.UpdateEvent(1, eventDto));
}
Expand Down Expand Up @@ -205,7 +203,7 @@ public void GetEventById_EventExists_EventReturned()
UpdatedAt =DateTime.Now }});


var eventService = new EventService(mockContext.Object, new ParameterService(mockContext.Object), new TagService(mockContext.Object), new CommentService(mockContext.Object));
var eventService = new EventService(mockContext.Object, new ParameterService(mockContext.Object), new TagService(mockContext.Object), new CommentService(mockContext.Object), new AddressService(mockContext.Object), new ImageService(mockContext.Object));

var result = eventService.GetEventById(1);
Assert.IsNotNull(result);
Expand Down Expand Up @@ -250,7 +248,7 @@ public void GetEventById_EventDoesNotExist_NullReturned()
}});


var eventService = new EventService(mockContext.Object, new ParameterService(mockContext.Object), new TagService(mockContext.Object), new CommentService(mockContext.Object));
var eventService = new EventService(mockContext.Object, new ParameterService(mockContext.Object), new TagService(mockContext.Object), new CommentService(mockContext.Object), new AddressService(mockContext.Object), new ImageService(mockContext.Object));

Assert.ThrowsException<NotFoundException>(() => eventService.GetEventById(1));
}
Expand Down Expand Up @@ -320,7 +318,7 @@ public void DeleteEvent_EventExists_EventDeleted()
mockContext.Setup(c => c.Comments).ReturnsDbSet(new List<Comment>());
mockContext.Setup(c => c.Participants).ReturnsDbSet(new List<Participant>());

var eventService = new EventService(mockContext.Object, new ParameterService(mockContext.Object), new TagService(mockContext.Object), new CommentService(mockContext.Object));
var eventService = new EventService(mockContext.Object, new ParameterService(mockContext.Object), new TagService(mockContext.Object), new CommentService(mockContext.Object), new AddressService(mockContext.Object), new ImageService(mockContext.Object));

eventService.DeleteEvent(1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,19 +119,23 @@ public void Validate_WhenStartAtIsAfterEndAt_ShouldReturnFalse()
}

[TestMethod]
public void Validate_WhenSlugIsEmpty_ShouldReturnFalse()
public void Validate_WhenSlugIsEmpty_ShouldReturnTrue()
{
var eventDto = new EventDto
{
Name = "Event",
Description = "Description",
StartAt = DateTime.UtcNow,
EndAt = DateTime.UtcNow.AddDays(1),
CreatedAt = DateTime.UtcNow,
UpdatedAt = DateTime.UtcNow,
Status = EventStatus.Approved,
Slug = ""
};

var result = _validator.Validate(eventDto);

Assert.IsFalse(result.IsValid);
Assert.IsTrue(result.Errors.Exists(
e => e.ErrorMessage == "'Slug' must not be empty."
));
Assert.IsTrue(result.IsValid);
}

[TestMethod]
Expand Down
Loading

0 comments on commit ad1d209

Please sign in to comment.