public async Task <IActionResult> GetProductRatings( [FromRoute] int productId, [FromQuery] GetAllRatingsQuery query, [FromQuery] PaginationQuery paginationQuery, [FromQuery] SortQuery sortQuery) { var filter = mapper.Map <GetAllRatingsFilter>(query); var sortingFilter = sortingService.GetRatingSortingFilters(sortQuery); var paginationFilter = mapper.Map <PaginationFilter>(paginationQuery); var productQuery = new GetRatingsQuery { ProductId = productId, Filter = filter, Pagination = paginationFilter, Sorting = sortingFilter }; var result = await mediator.Send(productQuery).ConfigureAwait(false); return(Ok(paginationService.CreateProductRatingsPaginatedResponse(productId, paginationFilter, filter, sortingFilter, result))); }
public async Task Handle_ReturnsCorrectNumberOfRatingModels() { var query = new GetAllRatingsQuery(); var handler = new GetAllRatingsQuery.GetAllRatingsQueryHandler(dbContext, mapper); var result = await handler.Handle(query, CancellationToken.None); Assert.NotNull(result); Assert.Single(result); }
public async Task <IEnumerable <RatingModel> > Handle(GetAllRatingsQuery request, CancellationToken cancellationToken) { var ratingEntities = await _dbContext.Rating.ToListAsync(); return(_mapper.Map <IEnumerable <RatingModel> >(ratingEntities)); }