-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #147 from SaintAngeLs/events_service
Events service update - new GetStudentEvents functionality
- Loading branch information
Showing
16 changed files
with
196 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
...ace.Services.Events/src/MiniSpace.Services.Events.Application/Commands/CancelRateEvent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System; | ||
using Convey.CQRS.Commands; | ||
|
||
namespace MiniSpace.Services.Events.Application.Commands | ||
{ | ||
public class CancelRateEvent: ICommand | ||
{ | ||
public Guid EventId { get; set; } | ||
public Guid StudentId { get; set; } | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...nts/src/MiniSpace.Services.Events.Application/Commands/Handlers/CancelRateEventHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Convey.CQRS.Commands; | ||
using MiniSpace.Services.Events.Application.Exceptions; | ||
using MiniSpace.Services.Events.Core.Repositories; | ||
|
||
namespace MiniSpace.Services.Events.Application.Commands.Handlers | ||
{ | ||
public class CancelRateEventHandler : ICommandHandler<CancelRateEvent> | ||
{ | ||
private readonly IEventRepository _eventRepository; | ||
|
||
public CancelRateEventHandler(IEventRepository eventRepository) | ||
{ | ||
_eventRepository = eventRepository; | ||
} | ||
|
||
public async Task HandleAsync(CancelRateEvent command, CancellationToken cancellationToken) | ||
{ | ||
var @event = await _eventRepository.GetAsync(command.EventId); | ||
if (@event is null) | ||
{ | ||
throw new EventNotFoundException(command.EventId); | ||
} | ||
|
||
@event.CancelRate(command.StudentId); | ||
await _eventRepository.UpdateAsync(@event); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
MiniSpace.Services.Events/src/MiniSpace.Services.Events.Application/DTO/EventRatingDto.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System; | ||
|
||
namespace MiniSpace.Services.Events.Application.DTO | ||
{ | ||
public class EventRatingDto | ||
{ | ||
public Guid EventId { get; set; } | ||
public int TotalRatings { get; set; } | ||
public double AverageRating { get; set; } | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...Space.Services.Events/src/MiniSpace.Services.Events.Application/Queries/GetEventRating.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System; | ||
using Convey.CQRS.Queries; | ||
using MiniSpace.Services.Events.Application.DTO; | ||
|
||
namespace MiniSpace.Services.Events.Application.Queries | ||
{ | ||
public class GetEventRating : IQuery<EventRatingDto> | ||
{ | ||
public Guid EventId { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 0 additions & 18 deletions
18
...Events/src/MiniSpace.Services.Events.Core/Exceptions/StudentAlreadyRatedEventException.cs
This file was deleted.
Oops, something went wrong.
18 changes: 18 additions & 0 deletions
18
...ces.Events/src/MiniSpace.Services.Events.Core/Exceptions/StudentNotRatedEventException.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System; | ||
|
||
namespace MiniSpace.Services.Events.Core.Exceptions | ||
{ | ||
public class StudentNotRatedEventException : DomainException | ||
{ | ||
public override string Code { get; } = "student_not_rated_event"; | ||
public Guid EventId { get; } | ||
public Guid StudentId { get; } | ||
|
||
public StudentNotRatedEventException(Guid eventId, Guid studentId) | ||
: base($"Student with ID: '{studentId}' has not rated event with ID: '{eventId}'.") | ||
{ | ||
EventId = eventId; | ||
StudentId = studentId; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
.../MiniSpace.Services.Events.Infrastructure/Mongo/Queries/Handlers/GetEventRatingHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Convey.CQRS.Queries; | ||
using Convey.Persistence.MongoDB; | ||
using MiniSpace.Services.Events.Application; | ||
using MiniSpace.Services.Events.Application.DTO; | ||
using MiniSpace.Services.Events.Application.Queries; | ||
using MiniSpace.Services.Events.Infrastructure.Mongo.Documents; | ||
|
||
namespace MiniSpace.Services.Events.Infrastructure.Mongo.Queries.Handlers | ||
{ | ||
public class GetEventRatingHandler : IQueryHandler<GetEventRating, EventRatingDto> | ||
{ | ||
private readonly IMongoRepository<EventDocument, Guid> _eventRepository; | ||
private readonly IAppContext _appContext; | ||
|
||
public GetEventRatingHandler(IMongoRepository<EventDocument, Guid> eventRepository, | ||
IAppContext appContext) | ||
{ | ||
_eventRepository = eventRepository; | ||
_appContext = appContext; | ||
} | ||
|
||
public async Task<EventRatingDto> HandleAsync(GetEventRating query, CancellationToken cancellationToken) | ||
{ | ||
var document = await _eventRepository.GetAsync(p => p.Id == query.EventId); | ||
if(document is null) | ||
{ | ||
return null; | ||
} | ||
var identity = _appContext.Identity; | ||
if(identity.IsAuthenticated && identity.Id != document.Organizer.Id && !identity.IsAdmin) | ||
{ | ||
return null; | ||
} | ||
|
||
return document.AsRatingDto(); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters