-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## 작업내용 #59 - 지하철 혼잡도 컨트롤러 구현 - 지하철 혼잡도 서비스 리팩토링 - Exception 처리 변경
- Loading branch information
Showing
8 changed files
with
245 additions
and
58 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
server/src/main/java/com/talkka/server/subway/controller/SubwayConfusionController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.talkka.server.subway.controller; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Repository; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
|
||
import com.talkka.server.common.exception.InvalidTypeException; | ||
import com.talkka.server.subway.exception.ConfusionNotFoundException; | ||
import com.talkka.server.subway.exception.StationNotFoundException; | ||
import com.talkka.server.subway.service.SubwayConfusionService; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@Repository | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/subway/confusion") | ||
public class SubwayConfusionController { | ||
|
||
private final SubwayConfusionService confusionService; | ||
|
||
@GetMapping("/{stationId}") | ||
public ResponseEntity<?> getConfusion( | ||
@PathVariable Long stationId, | ||
@RequestParam String dayType, | ||
@RequestParam String updown, | ||
@RequestParam String timeSlot | ||
) { | ||
ResponseEntity<?> response; | ||
try { | ||
response = ResponseEntity.ok( | ||
confusionService.getConfusion(stationId, dayType, updown, timeSlot)); | ||
} catch (StationNotFoundException | InvalidTypeException exception) { | ||
response = ResponseEntity.badRequest().body(exception.getMessage()); | ||
} catch (ConfusionNotFoundException exception) { | ||
response = ResponseEntity.status(HttpStatus.NOT_FOUND).body(exception.getMessage()); | ||
} | ||
return response; | ||
} | ||
|
||
@GetMapping("/{stationId}/list") | ||
public ResponseEntity<?> getConfusionList( | ||
@PathVariable Long stationId, | ||
@RequestParam String dayType, | ||
@RequestParam String updown, | ||
@RequestParam(required = false, defaultValue = "0") String startTimeSlot, | ||
@RequestParam(required = false, defaultValue = "47") String endTimeSlot | ||
) { | ||
ResponseEntity<?> response; | ||
try { | ||
response = ResponseEntity.ok( | ||
confusionService.getConfusionList(stationId, dayType, updown, startTimeSlot, endTimeSlot) | ||
); | ||
} catch (StationNotFoundException | InvalidTypeException exception) { | ||
response = ResponseEntity.badRequest().body(exception.getMessage()); | ||
} | ||
return response; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 11 additions & 6 deletions
17
server/src/main/java/com/talkka/server/subway/dto/SubwayConfusionRespDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
server/src/main/java/com/talkka/server/subway/exception/ConfusionNotFoundException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.talkka.server.subway.exception; | ||
|
||
public class ConfusionNotFoundException extends RuntimeException { | ||
private static final String MESSAGE = "조회 가능한 혼잡도 정보가 없습니다."; | ||
|
||
public ConfusionNotFoundException() { | ||
super(MESSAGE); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.