Skip to content

Commit

Permalink
Merge pull request #444 from softeerbootcamp-2nd/dev
Browse files Browse the repository at this point in the history
MAIN MERGE
  • Loading branch information
tank3a authored Aug 24, 2023
2 parents c2a6c85 + 1422a3a commit 670cf4f
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ public QuoteInfoDto getAllCarInfoByQuoteDataDto(QuoteRequestDto quoteRequestDto)
ColorDto innerColor = colorRepository.findColorDataByColorId(innerColorId, false).orElseThrow(() -> new EmptyDataException(ErrorCode.DATA_NOT_EXISTS));
ColorDto outerColor = colorRepository.findColorDataByColorId(outerColorId, true).orElseThrow(() -> new EmptyDataException(ErrorCode.DATA_NOT_EXISTS));
List<QuoteSubOptionDto> optionList = new ArrayList<>();

innerColor.setColorType("내장 색상");
outerColor.setColorType("외장 색상");

if (modelInfos.size() != 3) {
throw new EmptyDataException(ErrorCode.DATA_NOT_EXISTS);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public class HistoryShortDto {
List<HistoryShortDto> histories;

@Builder
@ConstructorProperties({"historyId", "soldCount", "histories"})
public HistoryShortDto(Long historyId, int soldCount, List<HistoryShortDto> histories) {
this.historyId = historyId;
this.soldCount = soldCount;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import lombok.*;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@Getter
Expand All @@ -11,8 +12,8 @@
public class QuoteRequestDto {
private int carId;
private int powerTrainId;
private int bodyTypeId;
private int operationId;
private int bodyTypeId;
private int outerColorId;
private int innerColorId;
private List<Integer> optionIdList = new ArrayList<>();
Expand All @@ -28,4 +29,17 @@ public QuoteRequestDto(int carId, int powerTrainId, int bodyTypeId, int operatio
this.optionIdList = new ArrayList<>();
this.optionIdList.addAll(optionIdList);
}

@Override
public String toString() {
return "QuoteRequestDto{" +
"carId=" + carId +
", powerTrainId=" + powerTrainId +
", bodyTypeId=" + bodyTypeId +
", operationId=" + operationId +
", outerColorId=" + outerColorId +
", innerColorId=" + innerColorId +
", optionIdList=" + Arrays.toString(optionIdList.toArray()) +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import autoever2.cartag.domain.color.ColorDto;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.dao.support.DataAccessUtils;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
Expand Down Expand Up @@ -57,7 +58,7 @@ public Optional<String> findOuterColorImagesByColorId(int colorId) {

public Optional<ColorDto> findColorDataByColorId(int colorId, boolean isOuterColor) {
StringBuilder query = new StringBuilder();
query.append("select c.color_id, color_name, color_image, color_car_image, color_price " +
query.append("select c.color_id, color_name, color_image, color_car_image, color_price, cm.color_bought_count " +
"from ColorCarMapper as cm inner join Color as c " +
"on cm.color_id = c.color_id where c.color_id = :colorId ");

Expand All @@ -68,13 +69,10 @@ public Optional<ColorDto> findColorDataByColorId(int colorId, boolean isOuterCol
query.append("and c.is_outer_color = 0");
}

try {
SqlParameterSource param = new MapSqlParameterSource()
.addValue("colorId", colorId);
return Optional.of(template.queryForObject(query.toString(), param, outerColorCarMapper()));
} catch (DataAccessException e) {
return Optional.empty();
}
SqlParameterSource param = new MapSqlParameterSource()
.addValue("colorId", colorId);

return Optional.ofNullable(DataAccessUtils.singleResult(template.query(query.toString(), param, outerColorCarMapper())));
}

private RowMapper<ColorDto> outerColorCarMapper() {
Expand Down
62 changes: 31 additions & 31 deletions frontend/src/context/ItemProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ export default function ItemProvider({ children }: IItemProvider) {
body: params,
});
const jsonData = await res.json();

setData(jsonData);
} catch (e) {
setError(e as Error);
Expand Down Expand Up @@ -189,65 +188,66 @@ export default function ItemProvider({ children }: IItemProvider) {

useEffect(() => {
if (!data || loading || error) return;

setSelectedItem({
type: 'SET_TRIM',
value: {
id: data.carId,
name: data.trim,
price: data.carDefaultPrice,
id: data.trimData.carId,
name: data.trimData.trim,
price: data.trimData.carDefaultPrice,
},
});
setSelectedItem({
type: 'SET_POWER_TRAIN',
value: {
id: data.powerTrainId,
title: data.powerTrainTitle,
name: data.powerTrainName,
imgSrc: data.powerTrainImage,
price: data.powerTrainPrice,
id: data.powertrainData.modelId,
title: data.powertrainData.modelTypeName,
name: data.powertrainData.modelName,
imgSrc: data.powertrainData.modelImage,
price: data.powertrainData.modelPrice,
},
});
setSelectedItem({
type: 'SET_BODY_TYPE',
value: {
id: data.bodyTypeId,
title: data.bodyTypeTitle,
name: data.bodyTypeName,
imgSrc: data.bodyTypeImage,
price: data.bodyTypePrice,
id: data.bodyTypeData.modelId,
title: data.bodyTypeData.modelTypeName,
name: data.bodyTypeData.modelName,
imgSrc: data.bodyTypeData.modelImage,
price: data.bodyTypeData.modelPrice,
},
});
setSelectedItem({
type: 'SET_OPERATION',
value: {
id: data.operationId,
title: data.operationTitle,
name: data.operationName,
imgSrc: data.operationImage,
price: data.operationPrice,
id: data.operationData.modelId,
title: data.operationData.modelTypeName,
name: data.operationData.modelName,
imgSrc: data.operationData.modelImage,
price: data.operationData.modelPrice,
},
});

setSelectedItem({
type: 'SET_OUTER_COLOR',
value: {
id: data.colorOuterId,
name: data.colorOuterImageName,
title: data.colorOuterTitle,
price: data.colorOuterPrice,
carImgSrc: data.colorCarOuterImage,
imgSrc: data.colorOuterImage,
id: data.outerColor.colorId,
name: data.outerColor.colorName,
title: data.outerColor.colorType,
price: data.outerColor.colorPrice,
carImgSrc: data.outerColor.colorCarImage,
imgSrc: data.outerColor.colorImage,
},
});
setSelectedItem({
type: 'SET_INNER_COLOR',
value: {
id: data.colorInnerId,
name: data.colorInnerImageName,
title: data.colorInnerTitle,
price: data.colorInnerPrice,
carImgSrc: data.colorCarInnerImage,
imgSrc: data.colorInnerImage,
id: data.innerColor.colorId,
name: data.innerColor.colorName,
title: data.innerColor.colorType,
price: data.innerColor.colorPrice,
carImgSrc: data.innerColor.colorCarImage,
imgSrc: data.innerColor.colorImage,
},
});

Expand Down
57 changes: 27 additions & 30 deletions frontend/src/hooks/useSharedInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,34 @@ import { useSearchParams } from 'react-router-dom';
import { SHARE_INFO_API } from '../utils/apis';
import { useCallback, useEffect, useState } from 'react';

interface IModelTypeInfo {
modelId: number;
modelName: string;
modelPrice: number;
modelImage: string;
modelTypeName: string;
}

interface IColorInfo {
colorId: number;
colorName: string;
colorImage: string;
colorType: string;
colorPrice: number;
colorBoughtCount: number | null;
colorCarImage: string;
}
export interface ISharedInfo {
carId: number;
trim: string;
carDefaultPrice: number;
powerTrainId: number;
powerTrainTitle: string;
powerTrainName: string;
powerTrainImage: string;
powerTrainPrice: number;
bodyTypeId: number;
bodyTypeTitle: string;
bodyTypeName: string;
bodyTypeImage: string;
bodyTypePrice: number;
operationId: number;
operationTitle: string;
operationName: string;
operationImage: string;
operationPrice: number;
colorOuterId: number;
colorOuterImage: string;
colorCarOuterImage: string;
colorOuterPrice: number;
colorOuterImageName: string;
colorOuterTitle: string;
colorInnerId: number;
colorInnerImage: string;
colorCarInnerImage: string;
colorInnerPrice: number;
colorInnerImageName: string;
colorInnerTitle: string;
trimData: {
carId: number;
trim: string;
carDefaultPrice: number;
};
powertrainData: IModelTypeInfo;
operationData: IModelTypeInfo;
bodyTypeData: IModelTypeInfo;
outerColor: IColorInfo;
innerColor: IColorInfo;
optionList: [
{
optionId: number;
Expand Down
64 changes: 32 additions & 32 deletions frontend/src/pages/ResultPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ export default function ResultPage() {
const { setSelectedItem } = useContext(ItemContext);
const { data: sharedInfo } = useSharedInfo();
const { data: efficiencyData } = useEfficiencyData({
powerTrainId: sharedInfo?.powerTrainId,
operationId: sharedInfo?.operationId,
powerTrainId: sharedInfo?.powertrainData.modelId,
operationId: sharedInfo?.operationData.modelId,
});
const { setNextStepAvailable } = useContext(ProgressContext);

Expand All @@ -37,9 +37,9 @@ export default function ResultPage() {
if (!sharedInfo) return;

const sharedTrim = {
id: sharedInfo.carId,
name: sharedInfo.trim,
price: sharedInfo.carDefaultPrice,
id: sharedInfo.trimData.carId,
name: sharedInfo.trimData.trim,
price: sharedInfo.trimData.carDefaultPrice,
};
const sharedOptions = sharedInfo.optionList.map((option) => {
return {
Expand All @@ -51,42 +51,42 @@ export default function ResultPage() {
};
});
const sharedPowerTrain = {
id: sharedInfo.powerTrainId,
name: sharedInfo.powerTrainName,
title: sharedInfo.powerTrainTitle,
imgSrc: sharedInfo.powerTrainImage,
price: sharedInfo.powerTrainPrice,
id: sharedInfo.powertrainData.modelId,
name: sharedInfo.powertrainData.modelName,
title: sharedInfo.powertrainData.modelTypeName,
imgSrc: sharedInfo.powertrainData.modelImage,
price: sharedInfo.powertrainData.modelPrice,
};
const shraedBodyType = {
id: sharedInfo.bodyTypeId,
name: sharedInfo.bodyTypeName,
title: sharedInfo.bodyTypeTitle,
imgSrc: sharedInfo.bodyTypeImage,
price: sharedInfo.bodyTypePrice,
id: sharedInfo.bodyTypeData.modelId,
name: sharedInfo.bodyTypeData.modelName,
title: sharedInfo.bodyTypeData.modelTypeName,
imgSrc: sharedInfo.bodyTypeData.modelImage,
price: sharedInfo.bodyTypeData.modelPrice,
};
const sharedOperation = {
id: sharedInfo.operationId,
name: sharedInfo.operationName,
title: sharedInfo.operationTitle,
imgSrc: sharedInfo.operationImage,
price: sharedInfo.operationPrice,
id: sharedInfo.operationData.modelId,
name: sharedInfo.operationData.modelName,
title: sharedInfo.operationData.modelTypeName,
imgSrc: sharedInfo.operationData.modelImage,
price: sharedInfo.operationData.modelPrice,
};
const sharedOuterColor = {
id: sharedInfo.colorOuterId,
name: sharedInfo.colorOuterImageName,
title: sharedInfo.colorOuterTitle,
imgSrc: sharedInfo.colorOuterImage,
price: sharedInfo.colorOuterPrice,
carImgSrc: sharedInfo.colorCarOuterImage,
id: sharedInfo.outerColor.colorId,
name: sharedInfo.outerColor.colorName,
title: sharedInfo.outerColor.colorType,
imgSrc: sharedInfo.outerColor.colorImage,
price: sharedInfo.outerColor.colorPrice,
carImgSrc: sharedInfo.outerColor.colorCarImage,
};

const sharedInnerColor = {
id: sharedInfo.colorInnerId,
name: sharedInfo.colorInnerImageName,
title: sharedInfo.colorInnerTitle,
imgSrc: sharedInfo.colorInnerImage,
price: sharedInfo.colorInnerPrice,
carImgSrc: sharedInfo.colorCarInnerImage,
id: sharedInfo.innerColor.colorId,
name: sharedInfo.innerColor.colorName,
title: sharedInfo.innerColor.colorType,
imgSrc: sharedInfo.innerColor.colorImage,
price: sharedInfo.innerColor.colorPrice,
carImgSrc: sharedInfo.innerColor.colorCarImage,
};
setSelectedItem({
type: 'SET_TRIM',
Expand Down

0 comments on commit 670cf4f

Please sign in to comment.