-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from endless-horses/feature#24-wheel-api
타이어 휠 모양 목록 조회 API 구현 close #24
- Loading branch information
Showing
4 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
src/main/java/com/endlesshorses/oot/custom/wheel/controller/WheelController.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,53 @@ | ||
package com.endlesshorses.oot.custom.wheel.controller; | ||
|
||
import com.endlesshorses.oot.custom.wheel.dto.WheelListResponseDto; | ||
import com.endlesshorses.oot.custom.wheel.service.WheelService; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponses; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.List; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@Tag(name = "Wheel", description = "휠 모양 관련 API") | ||
@RequestMapping("/wheels") | ||
public class WheelController { | ||
private final WheelService wheelService; | ||
|
||
@GetMapping | ||
@Operation(summary = "Wheel 목록 조회 메서드", description = "클라이언트가 요청한 휠 모양 목록 정보를 조회하기 위한 메서드") | ||
@ApiResponses({ | ||
@ApiResponse(responseCode = "200", description = "휠 모양 목록 조회 성공"), | ||
}) | ||
public ResponseEntity<List<WheelListResponseDto>> list() { | ||
List<WheelListResponseDto> wheelList = wheelService.list(); | ||
|
||
return ResponseEntity.ok().body(wheelList); | ||
} | ||
|
||
/* | ||
@GetMapping | ||
@Operation(summary = "Wheel 목록 조회 메서드", description = "클라이언트가 요청한 휠 모양 목록 정보를 조회하기 위한 메서드") | ||
@ApiResponses({ | ||
@ApiResponse(responseCode = "200", description = "휠 모양 목록 조회 성공"), | ||
@ApiResponse(responseCode = "400(403)", description = "휠 모양 목록 조회 실패"), | ||
}) | ||
public ResponseEntity<Message> listWheel(HttpServletRequest request) { | ||
WheelResponseDto wheelResponseDto = (WheelResponseDto) wheelService.list(); | ||
return ResponseEntity.ok( | ||
SuccessMessage.builder() | ||
.path(request.getRequestURI()) | ||
.data(wheelResponseDto) | ||
.build()); | ||
} | ||
*/ | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/com/endlesshorses/oot/custom/wheel/dto/WheelListResponseDto.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,24 @@ | ||
package com.endlesshorses.oot.custom.wheel.dto; | ||
|
||
import com.endlesshorses.oot.custom.wheel.entity.Wheel; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
public class WheelListResponseDto { | ||
|
||
private String name; | ||
private Long price; | ||
private String imageUrl; | ||
private String explanation; | ||
|
||
@Builder | ||
public WheelListResponseDto(Wheel wheel) { | ||
this.name = wheel.getName(); | ||
this.price = wheel.getPrice(); | ||
this.imageUrl = wheel.getImageUrl(); | ||
this.explanation = wheel.getExplanation(); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/endlesshorses/oot/custom/wheel/repository/WheelRepository.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,10 @@ | ||
package com.endlesshorses.oot.custom.wheel.repository; | ||
|
||
import com.endlesshorses.oot.custom.wheel.entity.Wheel; | ||
import org.springframework.data.domain.Example; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.List; | ||
|
||
public interface WheelRepository extends JpaRepository<Wheel, Long> { | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/com/endlesshorses/oot/custom/wheel/service/WheelService.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,24 @@ | ||
package com.endlesshorses.oot.custom.wheel.service; | ||
|
||
import com.endlesshorses.oot.custom.wheel.dto.WheelListResponseDto; | ||
import com.endlesshorses.oot.custom.wheel.repository.WheelRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class WheelService { | ||
private final WheelRepository wheelRepository; | ||
|
||
// 휠 모양 전체 목록 조회 | ||
@Transactional(readOnly = true) | ||
public List<WheelListResponseDto> list() { | ||
return wheelRepository.findAll().stream() | ||
.map(WheelListResponseDto::new) | ||
.collect(Collectors.toList()); | ||
} | ||
} |