Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX]: TimeSlot conversion 이 get method에서 변경되지 않은 문제 해결 #79

Merged
merged 1 commit into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.springframework.web.bind.annotation.RestController;

import com.talkka.server.common.exception.InvalidTypeException;
import com.talkka.server.common.exception.enums.InvalidTimeSlotEnumException;
import com.talkka.server.oauth.domain.OAuth2UserInfo;
import com.talkka.server.review.dto.BusReviewDto;
import com.talkka.server.review.dto.BusReviewReqDto;
Expand All @@ -38,19 +39,23 @@ public class BusReviewController {
private final BusReviewService busReviewService;

@GetMapping("")
public ResponseEntity<List<BusReviewRespDto>> getBusReviewList(
public ResponseEntity<?> getBusReviewList(
@RequestParam Long routeId,
@RequestParam(required = false) Long busRouteStationId,
@RequestParam(required = false) String timeSlot
) {
List<BusReviewRespDto> reviewData;

if (busRouteStationId != null && timeSlot != null) {
reviewData = busReviewService.getBusReviewList(routeId, busRouteStationId, timeSlot);
} else if (busRouteStationId != null) {
reviewData = busReviewService.getBusReviewList(routeId, busRouteStationId);
} else {
reviewData = busReviewService.getBusReviewList(routeId);
try {
if (busRouteStationId != null && timeSlot != null) {
reviewData = busReviewService.getBusReviewList(routeId, busRouteStationId, timeSlot);
} else if (busRouteStationId != null) {
reviewData = busReviewService.getBusReviewList(routeId, busRouteStationId);
} else {
reviewData = busReviewService.getBusReviewList(routeId);
}
} catch (InvalidTimeSlotEnumException exception) {
return ResponseEntity.badRequest().body(exception.getMessage());
}
return ResponseEntity.ok(reviewData);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import com.talkka.server.bus.dao.BusRouteStationEntity;
import com.talkka.server.bus.dao.BusRouteStationRepository;
import com.talkka.server.common.enums.TimeSlot;
import com.talkka.server.common.util.EnumCodeConverterUtils;
import com.talkka.server.common.exception.enums.InvalidTimeSlotEnumException;
import com.talkka.server.common.validator.ContentAccessValidator;
import com.talkka.server.review.dao.BusReviewEntity;
import com.talkka.server.review.dao.BusReviewRepository;
Expand Down Expand Up @@ -38,9 +38,10 @@ public class BusReviewService {

public List<BusReviewRespDto> getUsersBusReviewList(
Long userId, Long routeId, Long busRouteStationId, String timeSlot
) {
List<BusReviewEntity> reviewList = busReviewRepository.findAllByWriterIdAndRouteIdAndStationIdAndTimeSlotOrderByUpdatedAtDesc(
userId, routeId, busRouteStationId, EnumCodeConverterUtils.fromCode(TimeSlot.class, timeSlot));
) throws InvalidTimeSlotEnumException {
List<BusReviewEntity> reviewList = busReviewRepository
.findAllByWriterIdAndRouteIdAndStationIdAndTimeSlotOrderByUpdatedAtDesc(
userId, routeId, busRouteStationId, TimeSlot.valueOfEnumString(timeSlot));

return reviewList.stream()
.map(BusReviewRespDto::of)
Expand All @@ -62,9 +63,11 @@ public List<BusReviewRespDto> getBusReviewList(Long routeId, Long busRouteStatio
.toList();
}

public List<BusReviewRespDto> getBusReviewList(Long routeId, Long busRouteStationId, String timeSlot) {
List<BusReviewEntity> reviewEntityList = busReviewRepository.findAllByRouteIdAndStationIdAndTimeSlotOrderByCreatedAtDesc(
routeId, busRouteStationId, EnumCodeConverterUtils.fromCode(TimeSlot.class, timeSlot));
public List<BusReviewRespDto> getBusReviewList(Long routeId, Long busRouteStationId, String timeSlot) throws
InvalidTimeSlotEnumException {
List<BusReviewEntity> reviewEntityList = busReviewRepository
.findAllByRouteIdAndStationIdAndTimeSlotOrderByCreatedAtDesc(
routeId, busRouteStationId, TimeSlot.valueOfEnumString(timeSlot));
return reviewEntityList.stream()
.map(BusReviewRespDto::of)
.toList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.talkka.server.bus.dao.BusRouteStationEntity;
import com.talkka.server.bus.dao.BusRouteStationRepository;
import com.talkka.server.common.enums.TimeSlot;
import com.talkka.server.common.exception.enums.InvalidTimeSlotEnumException;
import com.talkka.server.common.validator.ContentAccessValidator;
import com.talkka.server.review.dao.BusReviewEntity;
import com.talkka.server.review.dao.BusReviewRepository;
Expand Down Expand Up @@ -156,11 +157,21 @@ void testGetBusReviewListWithRouteIdAndBusRouteStationIdAndTimeSlot() {
given(busReviewRepository.findAllByRouteIdAndStationIdAndTimeSlotOrderByCreatedAtDesc(anyLong(), anyLong(),
any(TimeSlot.class))).willReturn(reviewEntityList);
// when
busReviewService.getBusReviewList(236000050L, 1L, TimeSlot.T_00_00.getCode());
busReviewService.getBusReviewList(236000050L, 1L, "T_00_00");
// then
verify(busReviewRepository, times(1)).findAllByRouteIdAndStationIdAndTimeSlotOrderByCreatedAtDesc(anyLong(),
anyLong(), any(TimeSlot.class));
}

@Test
@DisplayName("TimeSlot이 잘못된 경우 InvalidTimeSlotEnumException을 발생시킨다.")
void testInvalidTimeSlotEnumException() {
// given
// when
// then
assertThatThrownBy(() -> busReviewService.getBusReviewList(236000050L, 1L, "T_00_00_00"))
.isInstanceOf(InvalidTimeSlotEnumException.class);
}
}

@Nested
Expand Down
Loading