-
-
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.
(#30) add endpoint for getting event rating
- Loading branch information
Showing
6 changed files
with
76 additions
and
3 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
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
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(); | ||
} | ||
|
||
} | ||
} |