Skip to content

Commit

Permalink
[REFACTOR] #419: Model 리팩토링 관련 Repository 테스트 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
tank3a committed Aug 23, 2023
1 parent 27fc65a commit 8180dd7
Show file tree
Hide file tree
Showing 13 changed files with 92 additions and 140 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public List<CarVo> getCarDtoByCarType(int carType) {
public CarDefaultDto getCarDefaultDtoByCarId(int carId) {
List<OuterColorDto> outerColorList = colorRepository.findOuterColorCarByCarId(carId);
List<InnerColorDto> innerColorList = colorRepository.findInnerColorCarByCarId(carId);
List<ModelDefaultDto> modelList = modelRepository.findModelDefaultDtoByCarId(carId);
List<ModelDefaultDto> modelList = modelRepository.findDefaultModelListByCarId(carId);
if (outerColorList.isEmpty() || innerColorList.isEmpty() || modelList.isEmpty()) {
throw new EmptyDataException(ErrorCode.DATA_NOT_EXISTS);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public HistoryShortDto getRecommendedList(@RequestBody QuoteDataDto quoteDataDto
@ApiResponse(responseCode = "200", description = "조회 성공", content = @Content(schema = @Schema(implementation = BoughtCarDto.class))),
})
@GetMapping("bought/infos")
@Cacheable(value = "boughtList")
public List<BoughtCarDto> getAllHistorySum(@RequestParam("carid") int carId) {
return quoteService.findAllBoughtInfos(carId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
@Getter
@Setter
@NoArgsConstructor
//@RedisHash(value = "test")
@Schema(description = "구매된 차량의 가격과 그에 따른 갯수 반환 DTO")
public class BoughtCarDto {
private Long totalPrice;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,17 @@ public static QuoteInfoDto toInfoDto(TrimInfoDto trimInfoDto, OuterColorDto oute
.powerTrainName(modelDefaultDto.get(0).getModelName())
.powerTrainImage(modelDefaultDto.get(0).getModelImage())
.powerTrainPrice(modelDefaultDto.get(0).getModelPrice())
.powerTrainTitle(modelDefaultDto.get(0).getModelTitle())
.powerTrainTitle(modelDefaultDto.get(0).getModelTypeName())
.operationId(modelDefaultDto.get(1).getModelId())
.operationName(modelDefaultDto.get(1).getModelName())
.operationImage(modelDefaultDto.get(1).getModelImage())
.operationPrice(modelDefaultDto.get(1).getModelPrice())
.operationTitle(modelDefaultDto.get(1).getModelTitle())
.operationTitle(modelDefaultDto.get(1).getModelTypeName())
.bodyTypeId(modelDefaultDto.get(2).getModelId())
.bodyTypeName(modelDefaultDto.get(2).getModelName())
.bodyTypeImage(modelDefaultDto.get(2).getModelImage())
.bodyTypePrice(modelDefaultDto.get(2).getModelPrice())
.bodyTypeTitle(modelDefaultDto.get(2).getModelTitle())
.bodyTypeTitle(modelDefaultDto.get(2).getModelTypeName())
.colorOuterId(outerColorDto.getColorId())
.colorOuterImage(outerColorDto.getColorImage())
.colorCarOuterImage(colorCarOuterImage)
Expand Down
20 changes: 10 additions & 10 deletions backend/src/main/java/autoever2/cartag/models/ModelRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ public ModelRepository(DataSource dataSource) {
this.template = new NamedParameterJdbcTemplate(dataSource);
}

public List<ModelShortMappedDto> findAllModelTypeData(int carId) {
String sql = "select m.model_id, m.model_name, t.model_type_id, t.model_type_name, m.model_price, m.model_image, mm.model_bought_count, mm.is_default_model, pd.max_ps, pd.max_kgfm " +
public List<ModelShortMappedDto> findAllModelTypeDataByCarId(int carId) {
String sql = "select m.model_id, m.model_name, t.model_type_id, t.model_type_name, m.model_price, m.model_image, mm.model_bought_count, pd.max_ps, pd.max_kgfm " +
"from ModelCarMapper mm " +
"inner join Model m on mm.model_id = m.model_id " +
"inner join ModelType t on m.model_type_id = t.model_type_id " +
Expand All @@ -39,7 +39,7 @@ public List<ModelShortMappedDto> findAllModelTypeData(int carId) {
return template.query(sql, param, modelShortRowMapper());
}

public Optional<ModelDetailMappedDto> findModelDetailData(int modelId) {
public Optional<ModelDetailMappedDto> findModelDetailDataMyModelId(int modelId) {
String sql = "select mt.model_type_name, m.model_name, m.option_description, m.model_image " +
"from Model m " +
"inner join ModelType mt on m.model_type_id = mt.model_type_id " +
Expand All @@ -63,7 +63,7 @@ public Optional<ModelEfficiencyDataDto> findEfficiencyData(int powerTrainId, int
return Optional.ofNullable(DataAccessUtils.singleResult(template.query(sql, param, efficiencyMapper())));
}

public List<ModelDefaultDto> findModelDefaultDtoByCarId(int carId) {
public List<ModelDefaultDto> findDefaultModelListByCarId(int carId) {
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 " +
Expand All @@ -74,11 +74,12 @@ public List<ModelDefaultDto> findModelDefaultDtoByCarId(int carId) {

return template.query(sql, param, modelDefaultRowMapper());
}
public List<ModelDefaultDto> findModelListByModelId(int powerTrainId, int bodyTypeId, int operationId) {
String sql = "select model_id, model_name, model_price, model_image, model_type_name as modelTitle " +
"from Model " +
"inner join ModelType on Model.model_type_id = ModelType.model_type_id " +
"where model_id in (:powerTrainId, :bodyTypeId, :operationId)";

public List<ModelDefaultDto> findAllModelListByModel(int powerTrainId, int operationId, int bodyTypeId) {
String sql = "select model_id, model_name, model_price, model_image, model_type_name " +
"from Model " +
"inner join ModelType on Model.model_type_id = ModelType.model_type_id " +
"where model_id in (:powerTrainId, :bodyTypeId, :operationId)";

SqlParameterSource param = new MapSqlParameterSource()
.addValue("powerTrainId", powerTrainId)
Expand All @@ -89,7 +90,6 @@ public List<ModelDefaultDto> findModelListByModelId(int powerTrainId, int bodyTy
}



private RowMapper<ModelEfficiencyDataDto> efficiencyMapper() {
return BeanPropertyRowMapper.newInstance(ModelEfficiencyDataDto.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class ModelService {
private final CarRepository carRepository;

public List<ModelShortDataDto> getModelTypeData(int carId) {
List<ModelShortMappedDto> modelData = modelRepository.findAllModelTypeData(carId);
List<ModelShortMappedDto> modelData = modelRepository.findAllModelTypeDataByCarId(carId);
if (modelData.isEmpty()) {
throw new EmptyDataException(ErrorCode.DATA_NOT_EXISTS);
}
Expand Down Expand Up @@ -97,7 +97,7 @@ private Double calculateHmgString(String input) {
}

public ModelDetailMappedDto getModelDetail(int modelId) {
return modelRepository.findModelDetailData(modelId).orElseThrow(() -> new EmptyDataException(ErrorCode.DATA_NOT_EXISTS));
return modelRepository.findModelDetailDataMyModelId(modelId).orElseThrow(() -> new EmptyDataException(ErrorCode.DATA_NOT_EXISTS));
}

public ModelEfficiencyDataDto getEfficiencyData(int powerTrainId, int operationId) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package autoever2.cartag.models.dto;

import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.*;

@Getter
@Setter
Expand All @@ -13,13 +10,14 @@ public class ModelDefaultDto {
private String modelName;
private Long modelPrice;
private String modelImage;
private String modelTitle;
private String modelTypeName;

public ModelDefaultDto(int modelId, String modelName, Long modelPrice, String modelImage, String modelTitle) {
@Builder
public ModelDefaultDto(int modelId, String modelName, Long modelPrice, String modelImage, String modelTypeName) {
this.modelId = modelId;
this.modelName = modelName;
this.modelPrice = modelPrice;
this.modelImage = modelImage;
this.modelTitle = modelTitle;
this.modelTypeName = modelTypeName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,21 @@ public class ModelShortMappedDto {
private String modelTypeName;
private Long modelPrice;
private Long modelBoughtCount;
private boolean isDefaultModel;
private String modelImage;
private int modelTypeId;
private String maxPs;
private String maxKgfm;

@Builder
public ModelShortMappedDto(int modelId, String modelName, String modelTypeName, Long modelPrice, Long modelBoughtCount, boolean isDefaultModel, String modelImage, int modelTypeId, String maxPs, String maxKgfm) {
public ModelShortMappedDto(int modelId, String modelName, String modelTypeName, Long modelPrice, Long modelBoughtCount, String modelImage, int modelTypeId, String maxPs, String maxKgfm) {
this.modelId = modelId;
this.modelName = modelName;
this.modelTypeName = modelTypeName;
this.modelPrice = modelPrice;
this.modelBoughtCount = modelBoughtCount;
this.isDefaultModel = isDefaultModel;
this.modelImage = modelImage;
this.modelTypeId = modelTypeId;
this.maxPs = maxPs;
this.maxKgfm = maxKgfm;
}

public void setIsDefaultModel(int isDefaultModel) {
this.isDefaultModel = isDefaultModel > 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public QuoteInfoDto getAllCarInfoByQuoteDataDto(QuoteDataDto quoteDataDto) {
List<Integer> optionIdList = quoteDataDto.getOptionIdList();

Optional<TrimInfoDto> trimInfo = carRepository.findTrimInfoByCarId(carId);
List<ModelDefaultDto> modelInfos = modelRepository.findModelListByModelId(powerTrainId, bodyTypeId, operationId);
List<ModelDefaultDto> modelInfos = modelRepository.findAllModelListByModel(powerTrainId, operationId, bodyTypeId);
Optional<InnerColorDto> innerColorInfo = colorRepository.findInnerColorByColorId(innerColorId);
Optional<OuterColorDto> outerColorInfo = colorRepository.findOuterColorByColorId(outerColorId);
List<QuoteSubOptionDto> optionInfos = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ void getDefaultOptionData() {

softAssertions.assertThatThrownBy(() -> carService.getCarDefaultDtoByCarId(carId)).isInstanceOf(EmptyDataException.class);

when(modelRepository.findModelDefaultDtoByCarId(carId)).thenReturn(List.of(powerTrain, operation, bodyType));
when(modelRepository.findDefaultModelListByCarId(carId)).thenReturn(List.of(powerTrain, operation, bodyType));

softAssertions.assertThat(carService.getCarDefaultDtoByCarId(carId)).usingRecursiveComparison().isEqualTo(expected);
}
Expand Down
Loading

0 comments on commit 8180dd7

Please sign in to comment.