Skip to content

Commit

Permalink
Merge pull request #26 from endless-horses/feature#24-wheel-api
Browse files Browse the repository at this point in the history
타이어 휠 모양 목록 조회 API 구현 close #24
  • Loading branch information
byeon22 authored Jan 24, 2024
2 parents c0da7c5 + 866f3f5 commit 6588db7
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 0 deletions.
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());
}
*/

}
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();
}
}
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> {
}
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());
}
}

0 comments on commit 6588db7

Please sign in to comment.