Skip to content

Commit

Permalink
Merge branch 'develop' into feature/#16/orderhistory
Browse files Browse the repository at this point in the history
  • Loading branch information
bbbang105 authored Mar 8, 2024
2 parents d96b912 + ba9692a commit 4a26128
Show file tree
Hide file tree
Showing 20 changed files with 528 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,39 @@
package Weflo.backend.controller.orderpart;

import Weflo.backend.dto.common.OrderPartsDto;
import Weflo.backend.dto.part.response.AllOrderPartsResponse;
import Weflo.backend.dto.part.response.OrderPartsDetailResponse;
import Weflo.backend.global.ApiResponse;
//import Weflo.backend.service.orderpart.OrderPartDetailService;
//import Weflo.backend.service.orderpart.OrderPartDetailService;
import Weflo.backend.service.orderpart.OrderPartService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping(value = "/api")
public class OrderPartController {
private final OrderPartService orderPartService;
// private final OrderPartDetailService orderPartDetailService;

@GetMapping("/orders/{userId}")
public ApiResponse<AllOrderPartsResponse> getAllOrderParts(@PathVariable Long userId) {
AllOrderPartsResponse allOrderParts = orderPartService.getAllOrderParts(userId);
return ApiResponse.onSuccess(allOrderParts);
}

@GetMapping("/orders/{userId}/{droneId}")
public ApiResponse<OrderPartsDetailResponse> getOrderParts(@PathVariable Long userId,
@PathVariable Long droneId) {
OrderPartsDetailResponse orderPartDetailOfDrone = orderPartService.getOrderPart(userId, droneId);
return ApiResponse.onSuccess(orderPartDetailOfDrone);
}
}


16 changes: 15 additions & 1 deletion src/main/java/Weflo/backend/domain/Drone.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import lombok.*;

import java.time.LocalDate;
import java.util.List;

@Entity
@NoArgsConstructor(access = AccessLevel.PROTECTED)
Expand Down Expand Up @@ -33,7 +34,7 @@ public class Drone {
private LocalDate lastCheckDate;

@Column(name = "is_dispose")
private boolean isDispose;
private Boolean isDispose;

@Column(name = "need_parts_count")
private Integer count;
Expand All @@ -44,4 +45,17 @@ public class Drone {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
private User user;

@OneToMany(mappedBy = "drone", fetch = FetchType.LAZY)
private List<Part> parts;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "check_history_id")
private CheckHistory checkHistory;

public Integer setCount(Integer lowBladeCount, Integer lowMotorCount, Integer lowEscCount) {
this.count = lowBladeCount + lowMotorCount + lowEscCount;
return this.count;
}

}
8 changes: 8 additions & 0 deletions src/main/java/Weflo/backend/dto/common/AbnormalPartsDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,12 @@
public class AbnormalPartsDto {
private String category;
private List<PartScoreDto> partsScore;

public static AbnormalPartsDto of(String category, List<PartScoreDto> partsScoreList) {
return AbnormalPartsDto.builder()
.category(category)
.partsScore(partsScoreList)
.build();

}
}
44 changes: 44 additions & 0 deletions src/main/java/Weflo/backend/dto/common/OrderPartsDto.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,66 @@
package Weflo.backend.dto.common;

import Weflo.backend.domain.Drone;
import Weflo.backend.domain.OrderHistory;
import Weflo.backend.domain.Product;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Builder;
import lombok.Data;

import java.time.LocalDate;
import java.util.List;
import java.util.stream.Collectors;

@Data
@Builder
@JsonInclude(JsonInclude.Include.NON_NULL)
public class OrderPartsDto {
private Long id;
private String droneImg;
private String nickname;
private Integer balanceScore;
private Integer totalScore;
private LocalDate orderDate;
private LocalDate estimateDate;
private List<ProductInfoDto> productsInfo;
private List<AbnormalPartsDto> abnormalities;

public static OrderPartsDto of(OrderHistory orderHistory, List<ProductInfoDto> productInfoDtoList) {
return builder()
.id(orderHistory.getDrone().getId())
.droneImg("https://weflo.s3.ap-northeast-2.amazonaws.com/%E1%84%89%E1%85%B3%E1%84%8F%E1%85%B3%E1%84%85%E1%85%B5%E1%86%AB%E1%84%89%E1%85%A3%E1%86%BA+2024-03-07+%E1%84%8B%E1%85%A9%E1%84%92%E1%85%AE+3.48.15.png")
.nickname(orderHistory.getDrone().getNickname())
.balanceScore(orderHistory.getDrone().getCheckHistory().getBalanceScore())
.totalScore(orderHistory.getDrone().getCheckHistory().getTotalScore())
.orderDate(orderHistory.getOrderDate())
.estimateDate(orderHistory.getOrderDate().plusDays(3))
.productsInfo(productInfoDtoList)
.build();
}

public static OrderPartsDto of(OrderHistory orderHistory, List<ProductInfoDto> productInfoDtoList,List<AbnormalPartsDto> abnormalPartsDtos) {
return builder()
.id(orderHistory.getDrone().getId())
.droneImg("https://weflo.s3.ap-northeast-2.amazonaws.com/%E1%84%89%E1%85%B3%E1%84%8F%E1%85%B3%E1%84%85%E1%85%B5%E1%86%AB%E1%84%89%E1%85%A3%E1%86%BA+2024-03-07+%E1%84%8B%E1%85%A9%E1%84%92%E1%85%AE+3.48.15.png")
.nickname(orderHistory.getDrone().getNickname())
.balanceScore(orderHistory.getDrone().getCheckHistory().getBalanceScore())
.totalScore(orderHistory.getDrone().getCheckHistory().getTotalScore())
.orderDate(orderHistory.getOrderDate())
.estimateDate(orderHistory.getOrderDate().plusDays(3))
.productsInfo(productInfoDtoList)
.abnormalities(abnormalPartsDtos)
.build();
}

public OrderPartsDto(Long id, String droneImg, String nickname, Integer balanceScore, Integer totalScore, LocalDate orderDate, LocalDate estimateDate, List<ProductInfoDto> productsInfo, List<AbnormalPartsDto> abnormalities) {
this.id = id;
this.droneImg = droneImg;
this.nickname = nickname;
this.balanceScore = balanceScore;
this.totalScore = totalScore;
this.orderDate = orderDate;
this.estimateDate = estimateDate;
this.productsInfo = productsInfo;
this.abnormalities = abnormalities;
}
}
13 changes: 11 additions & 2 deletions src/main/java/Weflo/backend/dto/common/PartScoreDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ public class PartScoreDto {
private Integer motorScore;
private Integer bladeScore;
private Integer escScore;
private Integer totalAvg;
private AbnormalCountDto abnormalCount;
// private Integer totalAvg;
// private AbnormalCountDto abnormalCount;

public static PartScoreDto of(String name, Integer motorScore, Integer bladeScore, Integer escScore) {
return PartScoreDto.builder()
.name(name)
.motorScore(motorScore)
.bladeScore(bladeScore)
.escScore(escScore)
.build();
}
}
14 changes: 14 additions & 0 deletions src/main/java/Weflo/backend/dto/common/ProductInfoDto.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package Weflo.backend.dto.common;

import Weflo.backend.domain.OrderHistory;
import Weflo.backend.domain.Product;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Builder;
import lombok.Data;
Expand All @@ -15,4 +17,16 @@ public class ProductInfoDto {
private Integer salePrice;
private Integer totalPrice;
private Integer amount;

public static ProductInfoDto of(Product product, OrderHistory orderHistory) {
return ProductInfoDto.builder()
.productImage(product.getProductImage())
.category(product.getCategory())
.name(product.getName())
.price(product.getPrice())
.salePrice(product.getSalePrice())
.totalPrice(orderHistory.getTotalPrice())
.amount(orderHistory.getAmount())
.build();
}
}
26 changes: 26 additions & 0 deletions src/main/java/Weflo/backend/dto/common/ProductInfoListDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package Weflo.backend.dto.common;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Builder;
import lombok.Data;

@Data
@Builder
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ProductInfoListDto {
private ProductInfoDto bladeInfoDto;
private ProductInfoDto motorInfoDto;
private ProductInfoDto escInfoDto;

public static ProductInfoListDto of(ProductInfoDto bladeInfoDto, ProductInfoDto motorInfoDto, ProductInfoDto escInfoDto) {
// this.bladeInfoDto = bladeInfoDto;
// this.motorInfoDto = motorInfoDto;
// this.escInfoDto = escInfoDto;
return ProductInfoListDto.builder()
.bladeInfoDto(bladeInfoDto)
.motorInfoDto(motorInfoDto)
.escInfoDto(escInfoDto)
.build();

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,10 @@
@Builder
public class AllOrderPartsResponse {
private List<OrderPartsDto> orderParts;

public static AllOrderPartsResponse of(List<OrderPartsDto> orderPartsDtoList) {
return builder()
.orderParts(orderPartsDtoList)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,16 @@
import lombok.Builder;
import lombok.Data;

import java.util.List;

@Data
@Builder
public class OrderPartsDetailResponse {
private OrderPartsDto orderParts;

public static OrderPartsDetailResponse of(OrderPartsDto orderPartsDto) {
return builder()
.orderParts(orderPartsDto)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public String uploadFile(String keyName, MultipartFile file) {
return amazonS3.getUrl(amazonConfig.getBucket(), keyName).toString();
}

public String generatePartsKeyName(Uuid uuid) {
return amazonConfig.getPartsPath() + '/' + uuid.getUuid();
}
// public String generatePartsKeyName(Uuid uuid) {
// return amazonConfig.getPartsPath() + '/' + uuid.getUuid();
// }

}
4 changes: 2 additions & 2 deletions src/main/java/Weflo/backend/global/config/AmazonConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public class AmazonConfig {
@Value("${cloud.aws.region.static}")
private String region;

@Value("${cloud.aws.s3.path.parts}")
private String partsPath;
// @Value("${cloud.aws.s3.path.parts}")
// private String partsPath;


private AWSCredentials awsCredentials;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package Weflo.backend.repository.orderhistory;


import Weflo.backend.domain.Drone;
import Weflo.backend.domain.OrderHistory;
import org.hibernate.query.Order;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface OrderHistoryRepository extends JpaRepository<OrderHistory, Long> {
List<OrderHistory> findByDrone(Drone droneId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package Weflo.backend.repository.orderpart;

import Weflo.backend.domain.OrderHistory;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.Optional;

@Repository
public interface OrderPartRepository extends JpaRepository<OrderHistory, Long> {
Optional<OrderHistory> findById(Long droneId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.Optional;

@Repository
public interface ProductRepository extends JpaRepository<Product, Long> {

Optional<Product> findByCategory(String category);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
import org.springframework.data.jpa.repository.JpaRepository;

public interface UserRepository extends JpaRepository<User, Long> {
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//package Weflo.backend.service.orderpart;
//
//import Weflo.backend.dto.part.response.OrderPartsDetailResponse;
//
//public interface OrderPartDetailService {
// OrderPartsDetailResponse getOrderPartDetailOfDrone(Long userId, Long droneId);
//}
Loading

0 comments on commit 4a26128

Please sign in to comment.