diff --git a/backend/src/main/java/corea/room/domain/RoomSortStrategy.java b/backend/src/main/java/corea/room/domain/RoomSortStrategy.java index 6c7a94ac..99baa1f1 100644 --- a/backend/src/main/java/corea/room/domain/RoomSortStrategy.java +++ b/backend/src/main/java/corea/room/domain/RoomSortStrategy.java @@ -13,6 +13,13 @@ public enum RoomSortStrategy { private final String property; private final Sort.Direction direction; + public static RoomSortStrategy from(RoomStatus status) { + if (status.isClosed()) { + return RoomSortStrategy.REVIEW_DEADLINE_DESC; + } + return RoomSortStrategy.RECRUITMENT_DEADLINE_DESC; + } + public Sort toSort() { return Sort.by(direction, property); } diff --git a/backend/src/main/java/corea/room/domain/RoomSortStrategyFactory.java b/backend/src/main/java/corea/room/domain/RoomSortStrategyFactory.java deleted file mode 100644 index 206e6516..00000000 --- a/backend/src/main/java/corea/room/domain/RoomSortStrategyFactory.java +++ /dev/null @@ -1,14 +0,0 @@ -package corea.room.domain; - -import org.springframework.stereotype.Component; - -@Component -public class RoomSortStrategyFactory { - - public RoomSortStrategy getRoomSortStrategy(RoomStatus status) { - if (status.isClosed()) { - return RoomSortStrategy.REVIEW_DEADLINE_DESC; - } - return RoomSortStrategy.RECRUITMENT_DEADLINE_DESC; - } -} diff --git a/backend/src/main/java/corea/room/service/RoomInquiryService.java b/backend/src/main/java/corea/room/service/RoomInquiryService.java index 9c18f7b5..e141f6b5 100644 --- a/backend/src/main/java/corea/room/service/RoomInquiryService.java +++ b/backend/src/main/java/corea/room/service/RoomInquiryService.java @@ -31,11 +31,10 @@ public class RoomInquiryService { private final RoomRepository roomRepository; private final ParticipationRepository participationRepository; private final RoomMatchReader roomMatchReader; - private final RoomSortStrategyFactory roomSortStrategyFactory; public RoomSearchResponses search(long memberId, RoomStatus status, RoomClassification classification, String keywordTitle) { Specification spec = getSearchSpecification(status, classification, keywordTitle); - RoomSortStrategy roomSortStrategy = roomSortStrategyFactory.getRoomSortStrategy(status); + RoomSortStrategy roomSortStrategy = RoomSortStrategy.from(status); List rooms = roomReader.findAll(spec, roomSortStrategy); List roomResponses = getRoomResponses(rooms, memberId); @@ -60,7 +59,7 @@ public RoomResponses findRoomsWithRoomStatus(long memberId, int pageNumber, Stri private Page getPaginatedRooms(int pageNumber, String expression, RoomStatus status) { RoomClassification classification = RoomClassification.from(expression); - RoomSortStrategy roomSortStrategy = roomSortStrategyFactory.getRoomSortStrategy(status); + RoomSortStrategy roomSortStrategy = RoomSortStrategy.from(status); PageRequest pageRequest = PageRequest.of(pageNumber, PAGE_DISPLAY_SIZE, roomSortStrategy.toSort()); if (classification.isAll()) { @@ -78,7 +77,7 @@ private List getRoomResponses(List rooms, long memberId) { private RoomResponse getRoomResponse(Room room, long memberId) { boolean isPublic = roomMatchReader.isPublicRoom(room); return participationRepository.findByRoomIdAndMemberId(room.getId(), memberId) - .map(participation -> RoomResponse.of(room, participation,isPublic)) - .orElseGet(() -> RoomResponse.of(room, MemberRole.NONE, ParticipationStatus.NOT_PARTICIPATED,isPublic)); + .map(participation -> RoomResponse.of(room, participation, isPublic)) + .orElseGet(() -> RoomResponse.of(room, MemberRole.NONE, ParticipationStatus.NOT_PARTICIPATED, isPublic)); } } diff --git a/backend/src/test/java/corea/room/domain/RoomSortStrategyFactoryTest.java b/backend/src/test/java/corea/room/domain/RoomSortStrategyTest.java similarity index 62% rename from backend/src/test/java/corea/room/domain/RoomSortStrategyFactoryTest.java rename to backend/src/test/java/corea/room/domain/RoomSortStrategyTest.java index a5821b36..c922580b 100644 --- a/backend/src/test/java/corea/room/domain/RoomSortStrategyFactoryTest.java +++ b/backend/src/test/java/corea/room/domain/RoomSortStrategyTest.java @@ -6,15 +6,13 @@ import static org.assertj.core.api.Assertions.assertThat; -class RoomSortStrategyFactoryTest { +class RoomSortStrategyTest { @ParameterizedTest @CsvSource(value = {"OPEN, RECRUITMENT_DEADLINE_DESC", "CLOSE, REVIEW_DEADLINE_DESC"}) @DisplayName("방 상태에 따라 방 정렬 방식을 얻을 수 있다.") - void getRoomSortStrategy(RoomStatus status, RoomSortStrategy expected) { - RoomSortStrategyFactory roomSortStrategyFactory = new RoomSortStrategyFactory(); - - RoomSortStrategy actual = roomSortStrategyFactory.getRoomSortStrategy(status); + void from(RoomStatus status, RoomSortStrategy expected) { + RoomSortStrategy actual = RoomSortStrategy.from(status); assertThat(actual).isEqualTo(expected); }