Skip to content

Commit 58b4905

Browse files
committed
fix: Handle the null exception
1 parent 97fad32 commit 58b4905

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

apps/jobboard-backend/src/main/java/org/bounswe/jobboardbackend/exception/ErrorCode.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public enum ErrorCode {
3131

3232
WORKPLACE_NOT_FOUND(HttpStatus.NOT_FOUND),
3333
WORKPLACE_ALREADY_EXISTS(HttpStatus.CONFLICT),
34+
REVIEW_ALREADY_EXISTS(HttpStatus.CONFLICT),
3435

3536
VALIDATION_ERROR(HttpStatus.BAD_REQUEST),
3637

apps/jobboard-backend/src/main/java/org/bounswe/jobboardbackend/workplace/service/ReviewService.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
import org.springframework.security.access.AccessDeniedException;
1818
import org.springframework.stereotype.Service;
1919
import org.springframework.transaction.annotation.Transactional;
20+
import org.bounswe.jobboardbackend.exception.HandleException;
21+
import org.bounswe.jobboardbackend.exception.ErrorCode;
2022

2123
import java.util.*;
2224
import java.util.stream.Collectors;
@@ -50,7 +52,7 @@ public ReviewResponse createReview(Long workplaceId, ReviewCreateRequest req, Us
5052

5153
boolean alreadyReviewed = reviewRepository.existsByWorkplace_IdAndUser_Id(workplaceId, currentUser.getId());
5254
if (alreadyReviewed) {
53-
throw new IllegalStateException("You have already submitted a review for this workplace.");
55+
throw new HandleException(ErrorCode.REVIEW_ALREADY_EXISTS, "You have already submitted a review for this workplace.");
5456
}
5557

5658
currentUser = userRepository.findById(currentUser.getId())

apps/jobboard-backend/src/main/java/org/bounswe/jobboardbackend/workplace/service/WorkplaceService.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -280,14 +280,17 @@ public void softDelete(Long id, User currentUser) {
280280

281281
private Pageable buildSort(int page, int size, String sortBy) {
282282
if (sortBy == null || sortBy.isBlank()) {
283-
return PageRequest.of(page, size, Sort.by(Sort.Order.asc("companyName").with(Sort.NullHandling.NULLS_LAST)));
283+
return PageRequest.of(page, size, Sort.by("companyName"));
284284
}
285285

286286
return switch (sortBy) {
287-
case "nameDesc" -> PageRequest.of(page, size, Sort.by(Sort.Order.desc("companyName").with(Sort.NullHandling.NULLS_LAST)));
288-
case "reviewCount" -> PageRequest.of(page, size, Sort.by(Sort.Order.desc("reviewCount").with(Sort.NullHandling.NULLS_LAST), Sort.Order.asc("companyName").with(Sort.NullHandling.NULLS_LAST)));
287+
case "nameDesc" -> PageRequest.of(page, size, Sort.by(Sort.Direction.DESC, "companyName"));
288+
289+
case "reviewCount" -> PageRequest.of(page, size, Sort.by(Sort.Direction.DESC, "reviewCount").and(Sort.by("companyName")));
290+
289291
case "rating" -> PageRequest.of(page, size);
290-
default -> PageRequest.of(page, size, Sort.by(Sort.Order.asc("companyName").with(Sort.NullHandling.NULLS_LAST)));
292+
293+
default -> PageRequest.of(page, size, Sort.by("companyName"));
291294
};
292295
}
293296

0 commit comments

Comments
 (0)