diff --git a/backend/src/main/java/autoever2/cartag/domain/car/CarDefaultDto.java b/backend/src/main/java/autoever2/cartag/domain/car/CarDefaultDto.java index 340b6b2..977da9a 100644 --- a/backend/src/main/java/autoever2/cartag/domain/car/CarDefaultDto.java +++ b/backend/src/main/java/autoever2/cartag/domain/car/CarDefaultDto.java @@ -13,13 +13,8 @@ @Builder @Schema(description = "차량 Default value를 반환하는 dto") public class CarDefaultDto { - @Schema(description = "선택 차량의 타입", example = "펠리세이드") - private String carType; - @Schema(description = "선택 차량의 트림 명", example = "Le Blanc") - private String trim; - @Schema(description = "선택된 차량 트림의 기본 가격") - private int carDefaultPrice; - + @Schema(description = "powerTrain의 id") + private int powerTrainId; @Schema(description = "기본 powerTrain의 이름", example = "디젤 2.2") private String powerTrainName; @Schema(description = "기본 powerTrain의 이미지 url") @@ -27,6 +22,8 @@ public class CarDefaultDto { @Schema(description = "기본 powerTrain의 가격") private Long powerTrainPrice; + @Schema(description = "bodyType의 id") + private int bodyTypeId; @Schema(description = "기본 bodyType의 이름", example = "7인승") private String bodyTypeName; @Schema(description = "기본 bodyType의 이미지 url") @@ -34,6 +31,8 @@ public class CarDefaultDto { @Schema(description = "기본 bodyType의 가격") private Long bodyTypePrice; + @Schema(description = "operation의 id") + private int operationId; @Schema(description = "기본 operation의 이름", example = "2WD") private String operationName; @Schema(description = "기본 operation의 이미지 url") @@ -58,17 +57,17 @@ public class CarDefaultDto { @Schema(description = "기본 내장색상 이름") private String colorInnerImageName; - public static CarDefaultDto toDefault(CarDefaultInfoDto carDefaultInfoDto, OuterColorDto outerColorDto, InnerColorDto innerColorDto, List modelDefaultDto, String colorCarOuterImage) { + public static CarDefaultDto toDefault(OuterColorDto outerColorDto, InnerColorDto innerColorDto, List modelDefaultDto, String colorCarOuterImage) { return CarDefaultDto.builder() - .carType(carDefaultInfoDto.getCarType()) - .trim(carDefaultInfoDto.getTrim()) - .carDefaultPrice(carDefaultInfoDto.getCarDefaultPrice()) + .powerTrainId(modelDefaultDto.get(0).getModelId()) .powerTrainName(modelDefaultDto.get(0).getModelName()) .powerTrainImage(modelDefaultDto.get(0).getModelImage()) .powerTrainPrice(modelDefaultDto.get(0).getModelPrice()) + .bodyTypeId(modelDefaultDto.get(1).getModelId()) .bodyTypeName(modelDefaultDto.get(1).getModelName()) .bodyTypeImage(modelDefaultDto.get(1).getModelImage()) .bodyTypePrice(modelDefaultDto.get(1).getModelPrice()) + .operationId(modelDefaultDto.get(2).getModelId()) .operationName(modelDefaultDto.get(2).getModelName()) .operationImage(modelDefaultDto.get(2).getModelImage()) .operationPrice(modelDefaultDto.get(2).getModelPrice()) diff --git a/backend/src/main/java/autoever2/cartag/domain/car/CarDefaultInfoDto.java b/backend/src/main/java/autoever2/cartag/domain/car/CarDefaultInfoDto.java deleted file mode 100644 index 5887e3b..0000000 --- a/backend/src/main/java/autoever2/cartag/domain/car/CarDefaultInfoDto.java +++ /dev/null @@ -1,16 +0,0 @@ -package autoever2.cartag.domain.car; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Builder; -import lombok.Getter; - -@Getter -@Builder -public class CarDefaultInfoDto { - @Schema(description = "선택 차량의 타입", example = "펠리세이드") - private String carType; - @Schema(description = "선택 차량의 트림 명", example = "Le Blanc") - private String trim; - @Schema(description = "선택된 차량 트림의 기본 가격") - private int carDefaultPrice; -} diff --git a/backend/src/main/java/autoever2/cartag/domain/car/CarPriceDto.java b/backend/src/main/java/autoever2/cartag/domain/car/CarPriceDto.java new file mode 100644 index 0000000..7fc8c63 --- /dev/null +++ b/backend/src/main/java/autoever2/cartag/domain/car/CarPriceDto.java @@ -0,0 +1,10 @@ +package autoever2.cartag.domain.car; + +import lombok.Getter; +import lombok.Setter; + +@Getter @Setter +public class CarPriceDto { + private int price; + private int count; +} diff --git a/backend/src/main/java/autoever2/cartag/domain/model/ModelDefaultDto.java b/backend/src/main/java/autoever2/cartag/domain/model/ModelDefaultDto.java index ced4671..8f39f33 100644 --- a/backend/src/main/java/autoever2/cartag/domain/model/ModelDefaultDto.java +++ b/backend/src/main/java/autoever2/cartag/domain/model/ModelDefaultDto.java @@ -8,12 +8,14 @@ @Getter @Setter @NoArgsConstructor public class ModelDefaultDto { + private int modelId; private String modelName; private Long modelPrice; private String modelImage; @Builder - public ModelDefaultDto(String modelName, Long modelPrice, String modelImage) { + public ModelDefaultDto(int modelId, String modelName, Long modelPrice, String modelImage) { + this.modelId = modelId; this.modelName = modelName; this.modelPrice = modelPrice; this.modelImage = modelImage; diff --git a/backend/src/main/java/autoever2/cartag/repository/CarRepository.java b/backend/src/main/java/autoever2/cartag/repository/CarRepository.java index a8545ef..3ce5b40 100644 --- a/backend/src/main/java/autoever2/cartag/repository/CarRepository.java +++ b/backend/src/main/java/autoever2/cartag/repository/CarRepository.java @@ -1,7 +1,5 @@ package autoever2.cartag.repository; -import autoever2.cartag.domain.car.CarDefaultDto; -import autoever2.cartag.domain.car.CarDefaultInfoDto; import autoever2.cartag.domain.car.CarInfoDto; import org.springframework.dao.DataAccessException; import org.springframework.dao.support.DataAccessUtils; @@ -47,28 +45,8 @@ public Optional findCarBoughtCountByCarId(int carId) { return Optional.ofNullable(DataAccessUtils.singleResult(template.query(sql, param, (rs, rowNum) -> rs.getLong("bought_count")))); } - public Optional findCarDefaultByCarId(int carId) { - String sql = "select car_type_name, trim, car_default_price " + - "from Car as c inner join CarType as ct " + - "on c.car_type_id = ct.car_type_id where c.car_id = :carId"; - try { - SqlParameterSource param = new MapSqlParameterSource() - .addValue("carId", carId); - return Optional.of(template.queryForObject(sql, param, carDefaultRowMapper())); - } catch (DataAccessException e) { - return Optional.empty(); - } - } - private RowMapper carDefaultRowMapper(){ - return (rs, rowNum) -> - CarDefaultInfoDto - .builder() - .carType(rs.getString("car_type_name")) - .trim(rs.getString("trim")) - .carDefaultPrice(rs.getInt("car_default_price")) - .build(); - } + } diff --git a/backend/src/main/java/autoever2/cartag/repository/ModelRepository.java b/backend/src/main/java/autoever2/cartag/repository/ModelRepository.java index b498079..9e85e77 100644 --- a/backend/src/main/java/autoever2/cartag/repository/ModelRepository.java +++ b/backend/src/main/java/autoever2/cartag/repository/ModelRepository.java @@ -39,7 +39,7 @@ public List findAllModelTypeData(int carId) { } public List findModelDefaultDtoByCarId(int carId) { - String sql = "select model_name, model_price, model_image from ModelCarMapper as mcm " + + String sql = "select m.model_id, model_name, model_price, model_image from ModelCarMapper as mcm " + "inner join Model as m on mcm.model_id = m.model_id where car_id = :carId and is_default_model = 1"; SqlParameterSource param = new MapSqlParameterSource() diff --git a/backend/src/main/java/autoever2/cartag/service/CarService.java b/backend/src/main/java/autoever2/cartag/service/CarService.java index 3123172..68b74ba 100644 --- a/backend/src/main/java/autoever2/cartag/service/CarService.java +++ b/backend/src/main/java/autoever2/cartag/service/CarService.java @@ -1,7 +1,6 @@ package autoever2.cartag.service; import autoever2.cartag.domain.car.CarDefaultDto; -import autoever2.cartag.domain.car.CarDefaultInfoDto; import autoever2.cartag.domain.car.CarDto; import autoever2.cartag.domain.car.CarInfoDto; import autoever2.cartag.domain.color.InnerColorDto; @@ -45,11 +44,10 @@ public List findCarByCarType(int carType) { } public CarDefaultDto findCarDefaultDtoByCarId(int carId) { - Optional carDefaultDto = carRepository.findCarDefaultByCarId(carId); List outerColorList = colorRepository.findOuterColorCarByCarId(carId); List innerColorList = colorRepository.findInnerColorCarByCarId(carId); List modelList = modelRepository.findModelDefaultDtoByCarId(carId); - if (carDefaultDto.isEmpty() || outerColorList.isEmpty() || innerColorList.isEmpty() || modelList.isEmpty()) { + if (outerColorList.isEmpty() || innerColorList.isEmpty() || modelList.isEmpty()) { throw new EmptyDataException(ErrorCode.RESOURCE_NOT_FOUND); } int colorId = outerColorList.get(0).getColorId(); @@ -60,7 +58,7 @@ public CarDefaultDto findCarDefaultDtoByCarId(int carId) { String value = colorCarOuterImage.get(); String outerImageUrl = value.substring(0, value.indexOf("*")) + 1 + value.substring(value.indexOf("*") + 1, value.length()); - return CarDefaultDto.toDefault(carDefaultDto.get(), outerColorList.get(0), innerColorList.get(0), modelList, outerImageUrl); + return CarDefaultDto.toDefault(outerColorList.get(0), innerColorList.get(0), modelList, outerImageUrl); } } diff --git a/backend/src/test/java/autoever2/cartag/integration/DefaultTest.java b/backend/src/test/java/autoever2/cartag/integration/DefaultTest.java index edfbefc..80dbf31 100644 --- a/backend/src/test/java/autoever2/cartag/integration/DefaultTest.java +++ b/backend/src/test/java/autoever2/cartag/integration/DefaultTest.java @@ -25,7 +25,6 @@ public class DefaultTest { @DisplayName("차량 기본 정보들을 반환") void defaultCarInfos(){ CarDefaultDto carDefaultDto = controller.carDefaultDto(1); - assertEquals("르블랑", carDefaultDto.getTrim()); assertEquals("디젤2.2", carDefaultDto.getPowerTrainName()); assertEquals("2WD", carDefaultDto.getBodyTypeName()); assertEquals(0, carDefaultDto.getOperationPrice()); diff --git a/backend/src/test/java/autoever2/cartag/repository/CarRepositoryTest.java b/backend/src/test/java/autoever2/cartag/repository/CarRepositoryTest.java index a678c46..92ac316 100644 --- a/backend/src/test/java/autoever2/cartag/repository/CarRepositoryTest.java +++ b/backend/src/test/java/autoever2/cartag/repository/CarRepositoryTest.java @@ -1,8 +1,8 @@ package autoever2.cartag.repository; -import autoever2.cartag.domain.car.CarDefaultInfoDto; import autoever2.cartag.domain.car.CarInfoDto; -import org.junit.jupiter.api.*; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.jdbc.JdbcTest; import org.springframework.test.context.ActiveProfiles; @@ -10,9 +10,8 @@ import javax.sql.DataSource; import java.util.List; -import java.util.Optional; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; @JdbcTest @ActiveProfiles("test") @@ -48,14 +47,4 @@ void findCarBoughtCountByCarId() { } - @Test - @DisplayName("차량의 기본 정보들을 반환합니다.") - void finDefaultInfos(){ - CarDefaultInfoDto carDefaultInfoDto = carRepository.findCarDefaultByCarId(1).get(); - assertEquals("Le Blanc", carDefaultInfoDto.getTrim()); - assertEquals(40000000, carDefaultInfoDto.getCarDefaultPrice()); - - Optional defaults = carRepository.findCarDefaultByCarId(5); - assertEquals(Optional.empty(), defaults); - } } \ No newline at end of file