Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…into feat/footer
  • Loading branch information
kimdaye77 committed Aug 21, 2023
2 parents 592740f + 4e26914 commit 420b604
Show file tree
Hide file tree
Showing 18 changed files with 348 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -55,4 +53,14 @@ public List<BoughtCarDto> 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);
}


}
20 changes: 20 additions & 0 deletions backend/src/main/java/autoever2/cartag/domain/car/TrimInfoDto.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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<Integer> optionIdList = new ArrayList<>();
}
121 changes: 121 additions & 0 deletions backend/src/main/java/autoever2/cartag/domain/share/QuoteInfoDto.java
Original file line number Diff line number Diff line change
@@ -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<QuoteSubOptionDto> optionList;

public static QuoteInfoDto toInfoDto(TrimInfoDto trimInfoDto, OuterColorDto outerColorDto, InnerColorDto innerColorDto,
List<ModelDefaultDto> modelDefaultDto, List<QuoteSubOptionDto> 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();

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -45,6 +48,21 @@ public Optional<Long> findCarBoughtCountByCarId(int carId) {
return Optional.ofNullable(DataAccessUtils.singleResult(template.query(sql, param, (rs, rowNum) -> rs.getLong("bought_count"))));
}

public Optional<TrimInfoDto> 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<TrimInfoDto> trimInfoRowMapper() {
return BeanPropertyRowMapper.newInstance(TrimInfoDto.class);
}

public List<CarPriceDto> 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 " +
Expand All @@ -55,6 +73,7 @@ public List<CarPriceDto> findCarPriceAndCount() {
return template.query(sql, CarPriceRowMapper());
}


private RowMapper<CarPriceDto> CarPriceRowMapper() {
return (rs, rowNum) -> CarPriceDto
.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -29,7 +30,7 @@ public List<InnerColorDto> findInnerColorCarByCarId(int carId) {

SqlParameterSource param = new MapSqlParameterSource()
.addValue("carId", carId);
return template.query(sql, param, InnerColorCarMapper());
return template.query(sql, param, innerColorCarMapper());

}

Expand All @@ -40,7 +41,7 @@ public List<OuterColorDto> findOuterColorCarByCarId(int carId) {

SqlParameterSource param = new MapSqlParameterSource()
.addValue("carId", carId);
return template.query(sql, param, OuterColorCarMapper());
return template.query(sql, param, outerColorCarMapper());
}

public Optional<String> findOuterColorImagesByColorId(int colorId) {
Expand All @@ -55,11 +56,36 @@ public Optional<String> findOuterColorImagesByColorId(int colorId) {
}
}

private RowMapper<OuterColorDto> OuterColorCarMapper() {
public Optional<InnerColorDto> 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<OuterColorDto> 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<OuterColorDto> outerColorCarMapper() {
return BeanPropertyRowMapper.newInstance(OuterColorDto.class);
}

private RowMapper<InnerColorDto> InnerColorCarMapper() {
private RowMapper<InnerColorDto> innerColorCarMapper() {
return BeanPropertyRowMapper.newInstance(InnerColorDto.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public List<ModelDefaultDto> findModelDefaultDtoByCarId(int carId) {
SqlParameterSource param = new MapSqlParameterSource()
.addValue("carId", carId);

return template.query(sql, param, ModelDefaultRowMapper());
return template.query(sql, param, modelDefaultRowMapper());
}

public Optional<ModelDetailMappedDto> findModelDetailData(int modelId) {
Expand Down Expand Up @@ -73,6 +73,17 @@ public Optional<ModelEfficiencyDataDto> findEfficiencyData(int powerTrainId, int
return Optional.ofNullable(DataAccessUtils.singleResult(template.query(sql, param, efficiencyMapper())));
}

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 = :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<ModelEfficiencyDataDto> efficiencyMapper() {
return BeanPropertyRowMapper.newInstance(ModelEfficiencyDataDto.class);
Expand All @@ -86,7 +97,7 @@ private RowMapper<ModelShortMappedDto> modelShortRowMapper() {
return BeanPropertyRowMapper.newInstance(ModelShortMappedDto.class);
}

private RowMapper<ModelDefaultDto> ModelDefaultRowMapper() {
private RowMapper<ModelDefaultDto> modelDefaultRowMapper() {
return BeanPropertyRowMapper.newInstance(ModelDefaultDto.class);
}

Expand Down
Loading

0 comments on commit 420b604

Please sign in to comment.