Skip to content

Commit

Permalink
Merge pull request #348 from softeerbootcamp-2nd/dev
Browse files Browse the repository at this point in the history
main merge
  • Loading branch information
dydwo0740 authored Aug 20, 2023
2 parents 3e57dad + 14414ec commit 74cfa5c
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,26 @@
@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")
private String powerTrainImage;
@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")
private String bodyTypeImage;
@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")
Expand All @@ -58,17 +57,17 @@ public class CarDefaultDto {
@Schema(description = "기본 내장색상 이름")
private String colorInnerImageName;

public static CarDefaultDto toDefault(CarDefaultInfoDto carDefaultInfoDto, OuterColorDto outerColorDto, InnerColorDto innerColorDto, List<ModelDefaultDto> modelDefaultDto, String colorCarOuterImage) {
public static CarDefaultDto toDefault(OuterColorDto outerColorDto, InnerColorDto innerColorDto, List<ModelDefaultDto> 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())
Expand Down

This file was deleted.

10 changes: 10 additions & 0 deletions backend/src/main/java/autoever2/cartag/domain/car/CarPriceDto.java
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -47,28 +45,8 @@ public Optional<Long> findCarBoughtCountByCarId(int carId) {
return Optional.ofNullable(DataAccessUtils.singleResult(template.query(sql, param, (rs, rowNum) -> rs.getLong("bought_count"))));
}

public Optional<CarDefaultInfoDto> 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<CarDefaultInfoDto> carDefaultRowMapper(){
return (rs, rowNum) ->
CarDefaultInfoDto
.builder()
.carType(rs.getString("car_type_name"))
.trim(rs.getString("trim"))
.carDefaultPrice(rs.getInt("car_default_price"))
.build();
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public List<ModelShortMappedDto> findAllModelTypeData(int carId) {
}

public List<ModelDefaultDto> 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()
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -45,11 +44,10 @@ public List<CarDto> findCarByCarType(int carType) {
}

public CarDefaultDto findCarDefaultDtoByCarId(int carId) {
Optional<CarDefaultInfoDto> carDefaultDto = carRepository.findCarDefaultByCarId(carId);
List<OuterColorDto> outerColorList = colorRepository.findOuterColorCarByCarId(carId);
List<InnerColorDto> innerColorList = colorRepository.findInnerColorCarByCarId(carId);
List<ModelDefaultDto> 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();
Expand All @@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
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;
import org.springframework.test.context.jdbc.Sql;

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")
Expand Down Expand Up @@ -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<CarDefaultInfoDto> defaults = carRepository.findCarDefaultByCarId(5);
assertEquals(Optional.empty(), defaults);
}
}

0 comments on commit 74cfa5c

Please sign in to comment.