diff --git a/backend/src/main/java/autoever2/cartag/controller/TrimController.java b/backend/src/main/java/autoever2/cartag/controller/TrimController.java index 989785a..e114f4a 100644 --- a/backend/src/main/java/autoever2/cartag/controller/TrimController.java +++ b/backend/src/main/java/autoever2/cartag/controller/TrimController.java @@ -3,6 +3,8 @@ import autoever2.cartag.domain.car.BoughtCarDto; import autoever2.cartag.domain.car.CarDefaultDto; import autoever2.cartag.domain.car.CarDto; +import autoever2.cartag.domain.share.QuoteIdList; +import autoever2.cartag.domain.share.QuoteInfoDto; import autoever2.cartag.service.CarService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; @@ -12,11 +14,7 @@ import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import java.util.List; @@ -55,4 +53,14 @@ public List boughtCarDtos() { return service.findAllBoughInfos(); } + @Operation(summary = "차량 공유하기를 위한 api", description = "차량 공유를 위한 정보 반환") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "조회 성공", content = @Content(schema = @Schema(implementation = QuoteInfoDto.class))), + }) + @GetMapping("/infos/shares") + public QuoteInfoDto boughtCarDtos(@Parameter(description = "선택한 id 리스트") @RequestBody QuoteIdList idList) { + return service.findShareInfoDto(idList); + } + + } diff --git a/backend/src/main/java/autoever2/cartag/domain/car/TrimInfoDto.java b/backend/src/main/java/autoever2/cartag/domain/car/TrimInfoDto.java new file mode 100644 index 0000000..03d5620 --- /dev/null +++ b/backend/src/main/java/autoever2/cartag/domain/car/TrimInfoDto.java @@ -0,0 +1,20 @@ +package autoever2.cartag.domain.car; + +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Getter @Setter +@NoArgsConstructor +public class TrimInfoDto { + private int carId; + private String trim; + private int carDefaultPrice; + @Builder + public TrimInfoDto(int carId, String trim, int carDefaultPrice) { + this.carId = carId; + this.trim = trim; + this.carDefaultPrice = carDefaultPrice; + } +} 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 8f39f33..fbdf704 100644 --- a/backend/src/main/java/autoever2/cartag/domain/model/ModelDefaultDto.java +++ b/backend/src/main/java/autoever2/cartag/domain/model/ModelDefaultDto.java @@ -12,12 +12,14 @@ public class ModelDefaultDto { private String modelName; private Long modelPrice; private String modelImage; + private String modelTitle; @Builder - public ModelDefaultDto(int modelId, String modelName, Long modelPrice, String modelImage) { + public ModelDefaultDto(int modelId, String modelName, Long modelPrice, String modelImage, String modelTitle) { this.modelId = modelId; this.modelName = modelName; this.modelPrice = modelPrice; this.modelImage = modelImage; + this.modelTitle = modelTitle; } } diff --git a/backend/src/main/java/autoever2/cartag/domain/option/QuoteSubOptionDto.java b/backend/src/main/java/autoever2/cartag/domain/option/QuoteSubOptionDto.java new file mode 100644 index 0000000..d1a3c65 --- /dev/null +++ b/backend/src/main/java/autoever2/cartag/domain/option/QuoteSubOptionDto.java @@ -0,0 +1,13 @@ +package autoever2.cartag.domain.option; + +import lombok.Getter; +import lombok.Setter; + +@Getter @Setter +public class QuoteSubOptionDto { + private int optionId; + private String optionName; + private Long optionPrice; + private String optionTitle; + private String optionImage; +} diff --git a/backend/src/main/java/autoever2/cartag/domain/share/QuoteIdList.java b/backend/src/main/java/autoever2/cartag/domain/share/QuoteIdList.java new file mode 100644 index 0000000..d84336a --- /dev/null +++ b/backend/src/main/java/autoever2/cartag/domain/share/QuoteIdList.java @@ -0,0 +1,17 @@ +package autoever2.cartag.domain.share; + +import lombok.Getter; +import lombok.Setter; + +import java.util.ArrayList; +import java.util.List; +@Getter @Setter +public class QuoteIdList { + private int carId; + private int powerTrainId; + private int bodyTypeId; + private int operationId; + private int outerColorId; + private int innerColorId; + private List optionIdList = new ArrayList<>(); +} diff --git a/backend/src/main/java/autoever2/cartag/domain/share/QuoteInfoDto.java b/backend/src/main/java/autoever2/cartag/domain/share/QuoteInfoDto.java new file mode 100644 index 0000000..4f3770f --- /dev/null +++ b/backend/src/main/java/autoever2/cartag/domain/share/QuoteInfoDto.java @@ -0,0 +1,121 @@ +package autoever2.cartag.domain.share; + +import autoever2.cartag.domain.car.TrimInfoDto; +import autoever2.cartag.domain.color.InnerColorDto; +import autoever2.cartag.domain.color.OuterColorDto; +import autoever2.cartag.domain.model.ModelDefaultDto; +import autoever2.cartag.domain.option.QuoteSubOptionDto; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Builder; +import lombok.Getter; + +import java.util.List; + +@Getter +@Builder +public class QuoteInfoDto { + @Schema(description = "car의 id") + private int carId; + @Schema(description = "차량의 trim명") + private String trim; + @Schema(description = "차량 기본 가격") + private int carDefaultPrice; + @Schema(description = "powerTrain의 id") + private int powerTrainId; + private String powerTrainTitle; + @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 명") + private String bodyTypeTitle; + @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 명") + private String operationTitle; + @Schema(description = "기본 operation의 이름", example = "2WD") + private String operationName; + @Schema(description = "기본 operation의 이미지 url") + private String operationImage; + @Schema(description = "기본 operation의 가격") + private Long operationPrice; + + @Schema(description = "외장색상의 id") + private int colorOuterId; + @Schema(description = "기본 외장색상 이미지 url") + private String colorOuterImage; + @Schema(description = "기본 외장색상이 적용된 차량 url") + private String colorCarOuterImage; + @Schema(description = "기본 외장색상 가격") + private Long colorOuterPrice; + @Schema(description = "기본 외장색상 이름") + private String colorOuterImageName; + @Schema(description = "외장색상 명") + private String colorOuterTitle; + + + @Schema(description = "내장색상의 id") + private int colorInnerId; + @Schema(description = "기본 내장색상 이미지 url") + private String colorInnerImage; + @Schema(description = "기본 내장색상이 적용된 차량 url") + private String colorCarInnerImage; + @Schema(description = "기본 내장색상 가격") + private Long colorInnerPrice; + @Schema(description = "기본 내장색상 이름") + private String colorInnerImageName; + @Schema(description = "내장색상 명") + private String colorInnerTitle; + @Schema(description = "option들의 리스트") + List optionList; + + public static QuoteInfoDto toInfoDto(TrimInfoDto trimInfoDto, OuterColorDto outerColorDto, InnerColorDto innerColorDto, + List modelDefaultDto, List optionInfos, String colorCarOuterImage) { + return QuoteInfoDto.builder() + .carId(trimInfoDto.getCarId()) + .trim(trimInfoDto.getTrim()) + .carDefaultPrice(trimInfoDto.getCarDefaultPrice()) + .powerTrainId(modelDefaultDto.get(0).getModelId()) + .powerTrainName(modelDefaultDto.get(0).getModelName()) + .powerTrainImage(modelDefaultDto.get(0).getModelImage()) + .powerTrainPrice(modelDefaultDto.get(0).getModelPrice()) + .powerTrainTitle(modelDefaultDto.get(0).getModelTitle()) + .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()) + .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()) + .colorOuterId(outerColorDto.getColorId()) + .colorOuterImage(outerColorDto.getColorImage()) + .colorCarOuterImage(colorCarOuterImage) + .colorOuterPrice(outerColorDto.getColorPrice()) + .colorOuterImageName(outerColorDto.getColorName()) + .colorOuterTitle("외장 색상") + .colorInnerTitle("내장 색상") + .colorInnerId(innerColorDto.getColorId()) + .colorInnerImage(innerColorDto.getColorImage()) + .colorCarInnerImage(innerColorDto.getColorCarImage()) + .colorInnerPrice(innerColorDto.getColorPrice()) + .colorInnerImageName(innerColorDto.getColorName()) + .optionList(optionInfos) + .build(); + + } +} diff --git a/backend/src/main/java/autoever2/cartag/repository/CarRepository.java b/backend/src/main/java/autoever2/cartag/repository/CarRepository.java index f289bef..ea9ece4 100644 --- a/backend/src/main/java/autoever2/cartag/repository/CarRepository.java +++ b/backend/src/main/java/autoever2/cartag/repository/CarRepository.java @@ -2,6 +2,8 @@ import autoever2.cartag.domain.car.CarInfoDto; import autoever2.cartag.domain.car.CarPriceDto; +import autoever2.cartag.domain.car.TrimInfoDto; +import org.springframework.dao.DataAccessException; import org.springframework.dao.support.DataAccessUtils; import org.springframework.jdbc.core.BeanPropertyRowMapper; import org.springframework.jdbc.core.RowMapper; @@ -11,6 +13,7 @@ import org.springframework.stereotype.Repository; import javax.sql.DataSource; +import javax.swing.text.html.Option; import java.util.List; import java.util.Optional; @@ -45,6 +48,21 @@ public Optional findCarBoughtCountByCarId(int carId) { return Optional.ofNullable(DataAccessUtils.singleResult(template.query(sql, param, (rs, rowNum) -> rs.getLong("bought_count")))); } + public Optional findTrimInfoByCarId(int carId){ + String sql = "select car_id, trim, car_default_price from Car where car_id = :carId"; + try { + SqlParameterSource param = new MapSqlParameterSource() + .addValue("carId", carId); + return Optional.of(template.queryForObject(sql, param, trimInfoRowMapper())); + } catch (DataAccessException e) { + return Optional.empty(); + } + } + + private RowMapper trimInfoRowMapper() { + return BeanPropertyRowMapper.newInstance(TrimInfoDto.class); + } + public List findCarPriceAndCount() { String sql = "select SalesHistory.sold_options_id, (car_default_price + sum(model_price)) as sum from Model inner join HistoryModelMapper " + "on Model.model_id = HistoryModelMapper.model_id inner join SalesHistory " + @@ -55,6 +73,7 @@ public List findCarPriceAndCount() { return template.query(sql, CarPriceRowMapper()); } + private RowMapper CarPriceRowMapper() { return (rs, rowNum) -> CarPriceDto .builder() diff --git a/backend/src/main/java/autoever2/cartag/repository/ColorRepository.java b/backend/src/main/java/autoever2/cartag/repository/ColorRepository.java index 2dbbfa4..18646d5 100644 --- a/backend/src/main/java/autoever2/cartag/repository/ColorRepository.java +++ b/backend/src/main/java/autoever2/cartag/repository/ColorRepository.java @@ -2,6 +2,7 @@ import autoever2.cartag.domain.color.InnerColorDto; import autoever2.cartag.domain.color.OuterColorDto; +import org.springframework.dao.DataAccessException; import org.springframework.dao.EmptyResultDataAccessException; import org.springframework.jdbc.core.BeanPropertyRowMapper; import org.springframework.jdbc.core.RowMapper; @@ -29,7 +30,7 @@ public List findInnerColorCarByCarId(int carId) { SqlParameterSource param = new MapSqlParameterSource() .addValue("carId", carId); - return template.query(sql, param, InnerColorCarMapper()); + return template.query(sql, param, innerColorCarMapper()); } @@ -40,7 +41,7 @@ public List findOuterColorCarByCarId(int carId) { SqlParameterSource param = new MapSqlParameterSource() .addValue("carId", carId); - return template.query(sql, param, OuterColorCarMapper()); + return template.query(sql, param, outerColorCarMapper()); } public Optional findOuterColorImagesByColorId(int colorId) { @@ -55,11 +56,36 @@ public Optional findOuterColorImagesByColorId(int colorId) { } } - private RowMapper OuterColorCarMapper() { + public Optional findInnerColorByColorId(int colorId) { + String sql = "select c.color_id, color_name, color_image, color_car_image, color_price " + + "from ColorCarMapper as cm inner join Color as c " + + "on cm.color_id = c.color_id where c.color_id = :colorId and c.is_outer_color = 0"; + try { + SqlParameterSource param = new MapSqlParameterSource() + .addValue("colorId", colorId); + return Optional.of(template.queryForObject(sql, param, innerColorCarMapper())); + } catch (DataAccessException e) { + return Optional.empty(); + } + } + public Optional findOuterColorByColorId(int colorId) { + String sql = "select c.color_id, color_name, color_image, color_car_image, color_price " + + "from ColorCarMapper as cm inner join Color as c " + + "on cm.color_id = c.color_id where c.color_id = :colorId and c.is_outer_color = 1"; + try { + SqlParameterSource param = new MapSqlParameterSource() + .addValue("colorId", colorId); + return Optional.of(template.queryForObject(sql, param, outerColorCarMapper())); + } catch (DataAccessException e) { + return Optional.empty(); + } + } + + private RowMapper outerColorCarMapper() { return BeanPropertyRowMapper.newInstance(OuterColorDto.class); } - private RowMapper InnerColorCarMapper() { + private RowMapper innerColorCarMapper() { return BeanPropertyRowMapper.newInstance(InnerColorDto.class); } } diff --git a/backend/src/main/java/autoever2/cartag/repository/ModelRepository.java b/backend/src/main/java/autoever2/cartag/repository/ModelRepository.java index 5088d15..0a56556 100644 --- a/backend/src/main/java/autoever2/cartag/repository/ModelRepository.java +++ b/backend/src/main/java/autoever2/cartag/repository/ModelRepository.java @@ -45,7 +45,7 @@ public List findModelDefaultDtoByCarId(int carId) { SqlParameterSource param = new MapSqlParameterSource() .addValue("carId", carId); - return template.query(sql, param, ModelDefaultRowMapper()); + return template.query(sql, param, modelDefaultRowMapper()); } public Optional findModelDetailData(int modelId) { @@ -73,6 +73,17 @@ public Optional findEfficiencyData(int powerTrainId, int return Optional.ofNullable(DataAccessUtils.singleResult(template.query(sql, param, efficiencyMapper()))); } + public List 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 = :powerTrainId " + + "or model_id = :bodyTypeId or model_id = :operationId"; + SqlParameterSource param = new MapSqlParameterSource() + .addValue("powerTrainId", powerTrainId) + .addValue("bodyTypeId", bodyTypeId) + .addValue("operationId", operationId); + return template.query(sql, param, modelDefaultRowMapper()); + } + private RowMapper efficiencyMapper() { return BeanPropertyRowMapper.newInstance(ModelEfficiencyDataDto.class); @@ -86,7 +97,7 @@ private RowMapper modelShortRowMapper() { return BeanPropertyRowMapper.newInstance(ModelShortMappedDto.class); } - private RowMapper ModelDefaultRowMapper() { + private RowMapper modelDefaultRowMapper() { return BeanPropertyRowMapper.newInstance(ModelDefaultDto.class); } diff --git a/backend/src/main/java/autoever2/cartag/repository/OptionRepository.java b/backend/src/main/java/autoever2/cartag/repository/OptionRepository.java index fb62db5..079a4ab 100644 --- a/backend/src/main/java/autoever2/cartag/repository/OptionRepository.java +++ b/backend/src/main/java/autoever2/cartag/repository/OptionRepository.java @@ -3,6 +3,7 @@ import autoever2.cartag.domain.car.TrimDefaultOptionDto; import autoever2.cartag.domain.option.OptionDetailMappedDto; import autoever2.cartag.domain.option.OptionShortMappedDto; +import autoever2.cartag.domain.option.QuoteSubOptionDto; import org.springframework.dao.DataAccessException; import org.springframework.dao.support.DataAccessUtils; import org.springframework.jdbc.core.BeanPropertyRowMapper; @@ -131,4 +132,22 @@ public Optional findOptionPriceByOptionId(int optionId) { return Optional.empty(); } } + + public Optional findSubOptionByOptionId(int optionId){ + String sql = "select CarOption.option_id, option_name, option_image, option_price, option_category_name as optionTitle from CarOption inner join SubOptionData " + + "on CarOption.option_id = SubOptionData.option_id inner join OptionCategory on " + + "OptionCategory.option_category_id = CarOption.option_category_id where CarOption.option_id = :optionId"; + try { + SqlParameterSource param = new MapSqlParameterSource() + .addValue("optionId", optionId); + return Optional.of(template.queryForObject(sql, param, shareSubOptionRowMapper())); + } catch (DataAccessException e) { + return Optional.empty(); + } + } + + private RowMapper shareSubOptionRowMapper() { + return BeanPropertyRowMapper.newInstance(QuoteSubOptionDto.class); + } + } diff --git a/backend/src/main/java/autoever2/cartag/service/CarService.java b/backend/src/main/java/autoever2/cartag/service/CarService.java index 3adb36c..1d2315e 100644 --- a/backend/src/main/java/autoever2/cartag/service/CarService.java +++ b/backend/src/main/java/autoever2/cartag/service/CarService.java @@ -4,6 +4,9 @@ import autoever2.cartag.domain.color.InnerColorDto; import autoever2.cartag.domain.color.OuterColorDto; import autoever2.cartag.domain.model.ModelDefaultDto; +import autoever2.cartag.domain.option.QuoteSubOptionDto; +import autoever2.cartag.domain.share.QuoteIdList; +import autoever2.cartag.domain.share.QuoteInfoDto; import autoever2.cartag.exception.EmptyDataException; import autoever2.cartag.exception.ErrorCode; import autoever2.cartag.repository.CarRepository; @@ -87,5 +90,37 @@ public List findAllBoughInfos() { .collect(Collectors.toList()); } + public QuoteInfoDto findShareInfoDto(QuoteIdList idList) { + int carId = idList.getCarId(); + int powerTrainId = idList.getPowerTrainId(); + int bodyTypeId = idList.getBodyTypeId(); + int operationId = idList.getOperationId(); + int outerColorId = idList.getOuterColorId(); + int innerColorId = idList.getInnerColorId(); + List optionIdList = idList.getOptionIdList(); + + Optional trimInfo = carRepository.findTrimInfoByCarId(carId); + List modelInfos = modelRepository.findModelListByModelId(powerTrainId, bodyTypeId, operationId); + Optional innerColorInfo = colorRepository.findInnerColorByColorId(innerColorId); + Optional outerColorInfo = colorRepository.findOuterColorByColorId(outerColorId); + List optionInfos = new ArrayList<>(); + for (Integer id : optionIdList) { + Optional optionInfo = optionRepository.findSubOptionByOptionId(id); + if (optionInfo.isPresent()) { + optionInfos.add(optionInfo.get()); + continue; + } + throw new EmptyDataException(ErrorCode.RESOURCE_NOT_FOUND); + } + OuterColorDto outerColorDto = outerColorInfo.get(); + String imageUrl = changeUrl(outerColorDto.getColorCarImage(), 1); + return QuoteInfoDto.toInfoDto(trimInfo.get(), outerColorDto, innerColorInfo.get(), modelInfos, optionInfos, imageUrl); + + } + + public String changeUrl(String value, int index) { + return value.substring(0, value.indexOf("*")) + index + value.substring(value.indexOf("*") + 1, value.length()); + } + } diff --git a/backend/src/main/java/autoever2/cartag/service/RecommendService.java b/backend/src/main/java/autoever2/cartag/service/RecommendService.java index 3860e10..406f76e 100644 --- a/backend/src/main/java/autoever2/cartag/service/RecommendService.java +++ b/backend/src/main/java/autoever2/cartag/service/RecommendService.java @@ -14,7 +14,7 @@ @Service public class RecommendService { - @Value("${python.url}") + //@Value("${python.url}") private String requestURL; //TODO: 응답 존재 안할 시 예외처리 diff --git a/frontend/package-lock.json b/frontend/package-lock.json index dde58e9..bb5e84c 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -12,6 +12,7 @@ "react": "^18.2.0", "react-dom": "^18.2.0", "react-router-dom": "^6.14.2", + "react-to-print": "^2.14.13", "styled-components": "^6.0.5" }, "devDependencies": { @@ -4922,6 +4923,15 @@ "react-dom": ">=16.8" } }, + "node_modules/react-to-print": { + "version": "2.14.13", + "resolved": "https://registry.npmjs.org/react-to-print/-/react-to-print-2.14.13.tgz", + "integrity": "sha512-PqUGgTRZvkyBzWgaZHVBECWPX2nGEc3HOUy6WNXof6HT4yTFI92wtIkqQtr4jfvHbadqjwTgzgh6vgN8KXlWWw==", + "peerDependencies": { + "react": "^15.0.0 || ^16.0.0 || ^17.0.0 || ^18.0.0", + "react-dom": "^15.0.0 || ^16.0.0 || ^17.0.0 || ^18.0.0" + } + }, "node_modules/readdirp": { "version": "3.6.0", "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz", diff --git a/frontend/package.json b/frontend/package.json index 7db31a8..d06208b 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -16,15 +16,16 @@ "react": "^18.2.0", "react-dom": "^18.2.0", "react-router-dom": "^6.14.2", + "react-to-print": "^2.14.13", "styled-components": "^6.0.5" }, "devDependencies": { "@types/react": "^18.2.15", "@types/react-dom": "^18.2.7", + "@types/styled-components": "^5.1.26", "@typescript-eslint/eslint-plugin": "^6.0.0", "@typescript-eslint/parser": "^6.0.0", "@vitejs/plugin-react": "^4.0.3", - "@types/styled-components": "^5.1.26", "eslint": "^8.45.0", "eslint-config-prettier": "^8.9.0", "eslint-plugin-react-hooks": "^4.6.0", diff --git a/frontend/src/components/priceStaticBar/PriceStaticBar.tsx b/frontend/src/components/priceStaticBar/PriceStaticBar.tsx index 4a85819..846d46e 100644 --- a/frontend/src/components/priceStaticBar/PriceStaticBar.tsx +++ b/frontend/src/components/priceStaticBar/PriceStaticBar.tsx @@ -64,7 +64,6 @@ export default function PriceStaticBar({ ...props }: IPriceStaticBar) { dragRef.current = false; }; - /////// useEffect(() => { setBudget((selectedItem.trim.price + highestPrice) / 2); }, [selectedItem.trim.price]); diff --git a/frontend/src/containers/ResultPage/QuoteSummaryContainer.tsx b/frontend/src/containers/ResultPage/QuoteSummaryContainer.tsx index 84c8806..894f480 100644 --- a/frontend/src/containers/ResultPage/QuoteSummaryContainer.tsx +++ b/frontend/src/containers/ResultPage/QuoteSummaryContainer.tsx @@ -35,6 +35,7 @@ const Wrapper = styled.div` align-items: center; background: ${({ theme }) => theme.color.skyBlueCardBg}; height: 95px; + padding: 40px; `; const FlexCenterWrapper = styled(CenterWrapper)` diff --git a/frontend/src/containers/ResultPage/ResultFooterContainer.tsx b/frontend/src/containers/ResultPage/ResultFooterContainer.tsx index 99703b1..1e227fa 100644 --- a/frontend/src/containers/ResultPage/ResultFooterContainer.tsx +++ b/frontend/src/containers/ResultPage/ResultFooterContainer.tsx @@ -2,11 +2,14 @@ import { styled } from 'styled-components'; import CenterWrapper from '../../components/layout/CenterWrapper'; import { BodyKrRegular3, HeadingKrMedium2 } from '../../styles/typefaces'; import RectButton from '../../components/common/buttons/RectButton'; -import { useContext } from 'react'; +import { HTMLAttributes, useContext } from 'react'; import { ItemContext } from '../../context/ItemProvider'; import { flexCenterCss } from '../../utils/commonStyle'; -export default function ResultFooterContainer() { +interface IResultFooterContainer extends HTMLAttributes { + handlePrint: () => void; +} +export default function ResultFooterContainer({ handlePrint }: IResultFooterContainer) { const { totalPrice } = useContext(ItemContext); return ( @@ -18,7 +21,9 @@ export default function ResultFooterContainer() { 공유하기 - PDF 다운로드 + + PDF 다운로드 + diff --git a/frontend/src/pages/ResultPage.tsx b/frontend/src/pages/ResultPage.tsx index 6e364a8..a567fe9 100644 --- a/frontend/src/pages/ResultPage.tsx +++ b/frontend/src/pages/ResultPage.tsx @@ -5,21 +5,37 @@ import QuoteSummaryContainer from '../containers/ResultPage/QuoteSummaryContaine import ResultBannerContainer from '../containers/ResultPage/ResultBannerContainer'; import HistogramContainer from '../containers/ResultPage/HistogramContainer'; import ResultFooterContainer from '../containers/ResultPage/ResultFooterContainer'; +import { useRef } from 'react'; +import { useReactToPrint } from 'react-to-print'; export default function ResultPage() { + const resultRef = useRef(null); + + const getPageStyles = () => { + return `@page {margin:40px; !important }`; + }; + + const handlePrint = useReactToPrint({ + content: () => resultRef.current, + documentTitle: Math.random().toString(36).substring(2, 12), + }); return ( <> - - - - - - - + + + + + + + + + + ); } +const Wrapper = styled.div``; const Row = styled(CenterWrapper)` display: flex; flex-direction: row;