Skip to content

Commit

Permalink
Merge pull request #423 from softeerbootcamp-2nd/feat/be-refactor
Browse files Browse the repository at this point in the history
Model 관련 리팩토링 진행
  • Loading branch information
dydwo0740 authored Aug 24, 2023
2 parents cd45c9e + 32f7807 commit f39332e
Show file tree
Hide file tree
Showing 37 changed files with 829 additions and 973 deletions.
16 changes: 12 additions & 4 deletions backend-recommend/recommend.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@

load_dotenv(verbose=True)

conn = pymysql.connect(host=os.getenv('host'), user=os.getenv('user'), password=os.getenv('password'), db=os.getenv('db'))
cur = conn.cursor()
def mysql_create_session():
conn = pymysql.connect(host=os.getenv('host'), user=os.getenv('user'), password=os.getenv('password'), db=os.getenv('db'))
cur = conn.cursor()
return conn, cur

def recByApriori(body):
start = time.time()
Expand All @@ -29,8 +31,14 @@ def recByApriori(body):

input = set(input)
dataset = []
cur.execute('SELECT hm.history_id, sh.sold_count, sh.sold_options_id FROM SalesHistory sh INNER JOIN HistoryModelMapper hm ON sh.history_id = hm.history_id WHERE sh.car_id = %s AND hm.model_id IN (%s, %s, %s) GROUP BY hm.history_id HAVING COUNT(DISTINCT hm.model_id) = 3;', (carId, powerTrainId, bodyTypeId, operationId))
dbRow = cur.fetchall()

conn, cur = mysql_create_session()
try:
cur.execute('SELECT hm.history_id, sh.sold_count, sh.sold_options_id FROM SalesHistory sh INNER JOIN HistoryModelMapper hm ON sh.history_id = hm.history_id WHERE sh.car_id = %s AND hm.model_id IN (%s, %s, %s) GROUP BY hm.history_id HAVING COUNT(DISTINCT hm.model_id) = 3;', (carId, powerTrainId, bodyTypeId, operationId))
dbRow = cur.fetchall()
finally:
conn.close()

for j in range(len(dbRow)):
oneRow = dbRow[j][2]
if(oneRow == ''):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public List<CarTypeDto> findAllCarType() {
return template.query(sql, carTypeDtoRowMapper());
}

public Optional<TrimInfoDto> findTrimInfoByCarId(int carId){
public Optional<TrimInfoDto> findTrimInfoByCarId(int carId) {
String sql = "select car_id, trim, car_default_price " +
"from Car " +
"where car_id = :carId";
Expand Down
6 changes: 3 additions & 3 deletions backend/src/main/java/autoever2/cartag/cars/CarService.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import autoever2.cartag.cars.dto.*;
import autoever2.cartag.domain.color.InnerColorDto;
import autoever2.cartag.domain.color.OuterColorDto;
import autoever2.cartag.domain.model.ModelDefaultDto;
import autoever2.cartag.models.dto.ModelDefaultDto;
import autoever2.cartag.exception.EmptyDataException;
import autoever2.cartag.exception.ErrorCode;
import autoever2.cartag.repository.ColorRepository;
import autoever2.cartag.repository.ModelRepository;
import autoever2.cartag.models.ModelRepository;
import autoever2.cartag.repository.OptionRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand Down 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 @@ -2,7 +2,7 @@

import autoever2.cartag.domain.color.InnerColorDto;
import autoever2.cartag.domain.color.OuterColorDto;
import autoever2.cartag.domain.model.ModelDefaultDto;
import autoever2.cartag.models.dto.ModelDefaultDto;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package autoever2.cartag.cars.dto;

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

@Getter
@Setter
@NoArgsConstructor
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class CarInfoDto {

private int carId;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package autoever2.cartag.cars.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.*;

@Getter
@Setter
@NoArgsConstructor
@NoArgsConstructor(access = AccessLevel.PRIVATE)
@Schema(description = "차종 ID와, 차종의 대표이미지, 차종명을 반환")
public class CarTypeDto {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package autoever2.cartag.cars.dto;

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

@Getter
@Setter
@NoArgsConstructor
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class TrimInfoDto {
private int carId;
private String trim;
Expand Down

This file was deleted.

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

This file was deleted.

This file was deleted.

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 @@ -3,7 +3,7 @@
import autoever2.cartag.cars.dto.TrimInfoDto;
import autoever2.cartag.domain.color.InnerColorDto;
import autoever2.cartag.domain.color.OuterColorDto;
import autoever2.cartag.domain.model.ModelDefaultDto;
import autoever2.cartag.models.dto.ModelDefaultDto;
import autoever2.cartag.domain.option.QuoteSubOptionDto;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
Expand Down 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
50 changes: 50 additions & 0 deletions backend/src/main/java/autoever2/cartag/models/ModelController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package autoever2.cartag.models;

import autoever2.cartag.models.dto.ModelDetailMappedDto;
import autoever2.cartag.models.dto.ModelEfficiencyDataDto;
import autoever2.cartag.models.dto.ModelShortDataDto;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
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 java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/modeltypes")
@Tag(name = "모델타입 관련 API", description = "모델 타입 리스트 및 상세 정보, 모델과 관련한 HMG데이터를 제공합니다.")
public class ModelController {

private final ModelService modelTypeService;

@Operation(summary = "모델타입의 리스트를 조회하는 API", description = "트림이 가지는 모든 모델타입을 반환하는 API입니다.")
@ApiResponse(responseCode = "200", description = "성공", content = {
@Content(array = @ArraySchema(schema = @Schema(implementation = ModelShortDataDto.class)))})
@GetMapping("/list")
public List<ModelShortDataDto> getModelList(@Parameter(description = "트림 ID") @RequestParam("carid") int carId) {
return modelTypeService.getModelTypeData(carId);
}

@Operation(summary = "특정 모델 타입의 상세데이터를 조회하는 API", description = "특정 모델의 모델타입명과 모델명, 설명, 이미지를 반환하는 API입니다.")
@ApiResponse(responseCode = "200", description = "조회 성공", content = @Content(schema = @Schema(implementation = ModelDetailMappedDto.class)))
@GetMapping("/detail")
public ModelDetailMappedDto getModelDetail(@Parameter(description = "모델 타입 ID") @RequestParam("modelid") int modelId) {
return modelTypeService.getModelDetail(modelId);
}

@Operation(summary = "효율 HMG 데이터를 조회하는 API", description = "파워트레인과 구동방식이 선택되었을 때 효율(연비 등) HMG 데이터를 반환하는 API입니다.")
@ApiResponse(responseCode = "200", description = "조회 성공", content = @Content(schema = @Schema(implementation = ModelEfficiencyDataDto.class)))
@GetMapping("/hmg-efficiency")
public ModelEfficiencyDataDto getEfficiencyHmgData(@Parameter(description = "파워트레인 ID") @RequestParam("powertrain") int powerTrainId, @Parameter(description = "구동방식 ID") @RequestParam("operation") int operationId) {
return modelTypeService.getEfficiencyData(powerTrainId, operationId);
}
}
Loading

0 comments on commit f39332e

Please sign in to comment.