From 6f6f24a315705b1dbd1351f0cc6bfd710cb2509c Mon Sep 17 00:00:00 2001 From: Can Date: Wed, 15 Nov 2023 15:22:37 +0300 Subject: [PATCH] review char limit fix --- .../dto/request/review/CreateReviewRequestDto.java | 2 +- .../request/review/GetAllReviewsFilterRequestDto.java | 5 +++++ .../com/app/gamereview/service/ReviewService.java | 11 ++++++++--- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/app/backend/src/main/java/com/app/gamereview/dto/request/review/CreateReviewRequestDto.java b/app/backend/src/main/java/com/app/gamereview/dto/request/review/CreateReviewRequestDto.java index 94e2aff5..03336f29 100644 --- a/app/backend/src/main/java/com/app/gamereview/dto/request/review/CreateReviewRequestDto.java +++ b/app/backend/src/main/java/com/app/gamereview/dto/request/review/CreateReviewRequestDto.java @@ -8,7 +8,7 @@ @Setter public class CreateReviewRequestDto { - @Size(max = 150, message = "Description must be at most 150 characters long") + @Size(max = 300, message = "Description must be at most 300 characters long") private String reviewDescription = null; @Max(value=5, message = "Rating cannot be more than 5") diff --git a/app/backend/src/main/java/com/app/gamereview/dto/request/review/GetAllReviewsFilterRequestDto.java b/app/backend/src/main/java/com/app/gamereview/dto/request/review/GetAllReviewsFilterRequestDto.java index 45e9dd6e..cdbb8535 100644 --- a/app/backend/src/main/java/com/app/gamereview/dto/request/review/GetAllReviewsFilterRequestDto.java +++ b/app/backend/src/main/java/com/app/gamereview/dto/request/review/GetAllReviewsFilterRequestDto.java @@ -1,5 +1,7 @@ package com.app.gamereview.dto.request.review; +import com.app.gamereview.enums.SortDirection; +import com.app.gamereview.util.validation.annotation.ValidSortDirection; import lombok.Getter; import lombok.Setter; @@ -11,4 +13,7 @@ public class GetAllReviewsFilterRequestDto { private String reviewedBy; private Boolean withDeleted = false; + + @ValidSortDirection(allowedValues = {SortDirection.ASCENDING, SortDirection.DESCENDING}) + private String sortDirection = SortDirection.DESCENDING.name(); } diff --git a/app/backend/src/main/java/com/app/gamereview/service/ReviewService.java b/app/backend/src/main/java/com/app/gamereview/service/ReviewService.java index a1de5e63..b80da399 100644 --- a/app/backend/src/main/java/com/app/gamereview/service/ReviewService.java +++ b/app/backend/src/main/java/com/app/gamereview/service/ReviewService.java @@ -23,9 +23,7 @@ import org.springframework.data.mongodb.core.query.Update; import org.springframework.stereotype.Service; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; +import java.util.*; @Service public class ReviewService { @@ -76,6 +74,13 @@ public List getAllReviews(GetAllReviewsFilterRequestDt List filteredReviews = mongoTemplate.find(query, Review.class); + if(filter.getSortDirection().equals("DESCENDING")){ + Collections.sort(filteredReviews, Comparator.comparing(Review::getCreatedAt).reversed()); + } + else{ + Collections.sort(filteredReviews, Comparator.comparing(Review::getCreatedAt)); + } + List reviewDtos = new ArrayList<>(); for(Review review : filteredReviews){