File tree Expand file tree Collapse file tree 5 files changed +56
-3
lines changed
src/main/java/com/sopkathon Expand file tree Collapse file tree 5 files changed +56
-3
lines changed Original file line number Diff line number Diff line change @@ -25,13 +25,11 @@ repositories {
2525
2626dependencies {
2727 implementation ' org.springframework.boot:spring-boot-starter-data-jpa'
28- implementation ' org.springframework.boot:spring-boot-starter-security'
2928 implementation ' org.springframework.boot:spring-boot-starter-web'
3029 compileOnly ' org.projectlombok:lombok'
3130 runtimeOnly ' com.mysql:mysql-connector-j'
3231 annotationProcessor ' org.projectlombok:lombok'
3332 testImplementation ' org.springframework.boot:spring-boot-starter-test'
34- testImplementation ' org.springframework.security:spring-security-test'
3533 testRuntimeOnly ' org.junit.platform:junit-platform-launcher'
3634
3735 // validation
Original file line number Diff line number Diff line change 11package com .sopkathon .domain .subway .controller ;
22
3+ import com .sopkathon .domain .subway .dto .SubwayListRes ;
4+ import com .sopkathon .domain .subway .service .SubwayService ;
5+ import com .sopkathon .global .error .code .SuccessCode ;
6+ import com .sopkathon .global .error .dto .SuccessResponse ;
7+ import org .springframework .http .ResponseEntity ;
8+ import org .springframework .web .bind .annotation .GetMapping ;
9+ import org .springframework .web .bind .annotation .RequestMapping ;
310import org .springframework .web .bind .annotation .RestController ;
411
512@ RestController
13+ @ RequestMapping ("/api/v1" )
614public class SubwayController {
15+ private final SubwayService subwayService ;
16+
17+ public SubwayController (SubwayService subwayService ) {
18+ this .subwayService = subwayService ;
19+ }
20+
21+ @ GetMapping ("/subways" )
22+ public ResponseEntity <SuccessResponse <SubwayListRes >> getSubwayList () {
23+ SubwayListRes subwayListRes = subwayService .getSubwayList ();
24+
25+ return ResponseEntity .ok (SuccessResponse .of (SuccessCode .SUCCESS_SUBWAY_LIST , subwayListRes ));
26+ }
727}
Original file line number Diff line number Diff line change 1+ package com .sopkathon .domain .subway .dto ;
2+
3+ import com .sopkathon .domain .subway .entity .SubwayEntity ;
4+
5+ import java .util .List ;
6+
7+ public record SubwayListRes (
8+ List <String > subways
9+ ) {
10+ public static SubwayListRes from (List <String > subways ) {
11+ return new SubwayListRes (subways );
12+ }
13+ }
Original file line number Diff line number Diff line change 11package com .sopkathon .domain .subway .service ;
22
3+ import com .sopkathon .domain .subway .dto .SubwayListRes ;
4+ import com .sopkathon .domain .subway .entity .SubwayEntity ;
5+ import com .sopkathon .domain .subway .repository .SubwayRepository ;
6+ import lombok .RequiredArgsConstructor ;
37import org .springframework .stereotype .Service ;
8+ import org .springframework .transaction .annotation .Transactional ;
9+
10+ import java .util .List ;
11+ import java .util .stream .Collectors ;
412
513@ Service
14+ @ Transactional
15+ @ RequiredArgsConstructor
616public class SubwayService {
17+ private final SubwayRepository subwayRepository ;
18+
19+ @ Transactional (readOnly = true )
20+ public SubwayListRes getSubwayList () {
21+ List <String > list = subwayRepository .findAll ()
22+ .stream ()
23+ .map (SubwayEntity ::getSubwayName )
24+ .collect (Collectors .toList ());
25+
26+ return SubwayListRes .from (list );
27+ }
728}
Original file line number Diff line number Diff line change @@ -18,7 +18,8 @@ public enum SuccessCode {
1818 SUCCESS_LOGIN (HttpStatus .OK , "로그인 성공했습니다" ),
1919 SUCCESS_WITHDRAW (HttpStatus .OK , "회원탈퇴에 성공했습니다" ),
2020 SUCCESS_REDIRECT (HttpStatus .PERMANENT_REDIRECT , "Redirect에 성공하였습니다" ),
21- SUCCESS_LOGOUT (HttpStatus .OK , "로그아웃에 성공했습니다" );
21+ SUCCESS_LOGOUT (HttpStatus .OK , "로그아웃에 성공했습니다" ),
22+ SUCCESS_SUBWAY_LIST (HttpStatus .OK , "지하철역 리스트가 성공적으로 조회었습니다." );
2223
2324 private final HttpStatus httpStatus ;
2425 private final String message ;
You can’t perform that action at this time.
0 commit comments