Skip to content

Commit

Permalink
Merge pull request #350 from TrandPick/development
Browse files Browse the repository at this point in the history
트랜드픽 배포
  • Loading branch information
mmunkyeong authored Jul 10, 2023
2 parents f71e91e + 03ba36b commit 538eb7d
Show file tree
Hide file tree
Showing 29 changed files with 239 additions and 175 deletions.
15 changes: 15 additions & 0 deletions src/main/java/project/trendpick_pro/domain/common/base/rq/Rq.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ public Member getLogin() {
public Boolean checkMember() {
return getLogin().getRole().equals(RoleType.MEMBER);
}
public Boolean admin() {
return getLogin().getRole().equals(RoleType.ADMIN);
}
public Member getMember() {
Member member = getLogin();
if (member.getRole().equals(RoleType.MEMBER)) {
Expand All @@ -154,13 +157,25 @@ public Member getMember() {
throw new MemberNotMatchException("허용된 권한이 아닙니다.");
}

public Member getRollMember(){
Member member=getLogin();
if(member.getRole().equals(RoleType.MEMBER)){
return member;
}else if(member.getRole().equals(RoleType.BRAND_ADMIN)){
return member;
}else if(member.getRole().equals(RoleType.ADMIN)){
return member;
}
throw new MemberNotMatchException("허용된 권한이 아닙니다.");
}
public Member getBrandMember() {
Member member = getLogin();
if (member.getRole().equals(RoleType.BRAND_ADMIN)) {
return member;
}
throw new MemberNotMatchException("허용된 권한이 아닙니다.");
}

public Boolean checkAdmin() {
return !checkMember();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
@Getter
@Setter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Table(name = "index_member",
@Table(name = "member",
indexes = {@Index(name = "index_member_email", columnList="email", unique = true)})
public class Member extends BaseTimeEntity {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ public interface MemberRepository extends JpaRepository<Member, Long> {
Optional<Member> findByUsername(String username);
Optional<Member> findByEmail(String email);
Page<Member> findAllByRoleAndRecentlyAccessDateBetween(RoleType role, LocalDateTime fromDate, LocalDateTime toDate, Pageable pageable);

Member findByBrand(String brand);
}
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,9 @@ public RsData<Member> manageAccount(Member member, String bank_name, String acco
public Member findById(Long id) {
return memberRepository.findById(id).orElseThrow(() -> new MemberNotFoundException("존재하지 않는 회원입니다."));
}

public Member findByBrandMember(String name){
return memberRepository.findByBrand(name);
}
public Optional<Member> findByUsername(String username) {
return memberRepository.findByUsername(username);
}
Expand All @@ -184,7 +186,7 @@ public static class AddCashRsDataBody {

@Transactional
public RsData<AddCashRsDataBody> addCash(String brand, long price, Brand relEntity, CashLog.EvenType eventType) {
Member member=rq.getBrandMember();
Member member=findByBrandMember(brand);
if(!member.getBrand().equals(brand)){
return RsData.of("F-1","해당 브랜드와 관리자가 일치하지 않습니다.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import project.trendpick_pro.domain.common.base.rq.Rq;
import project.trendpick_pro.domain.member.entity.Member;
import project.trendpick_pro.domain.orders.entity.Order;
import project.trendpick_pro.domain.orders.entity.dto.request.ProductOrderRequest;
import project.trendpick_pro.domain.orders.entity.dto.request.CartToOrderRequest;
import project.trendpick_pro.domain.orders.entity.dto.request.ProductOrderRequest;
import project.trendpick_pro.domain.orders.entity.dto.response.OrderDetailResponse;
import project.trendpick_pro.domain.orders.entity.dto.response.OrderResponse;
import project.trendpick_pro.domain.orders.service.OrderService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,8 @@ public RsData<Order> productToOrder(Member member, Long id, int quantity, String
@Transactional
@KafkaListener(topicPattern = "orders", groupId = "group_id")
public void orderToOrder(@Payload String Id) throws JsonProcessingException {
// delay 2sec
try {
Thread.sleep(500);
Thread.sleep(750);
} catch (InterruptedException e) {
e.printStackTrace();
}
Expand All @@ -125,6 +124,9 @@ public void orderToOrder(@Payload String Id) throws JsonProcessingException {
try {
for (OrderItem orderItem : order.getOrderItems()) {
orderItem.getProduct().getProductOption().decreaseStock(orderItem.getQuantity());
if (orderItem.getProduct().getProductOption().getStock() == 0) {
productService.deleteCache(orderItem.getProduct().getProductOption());
}
}
order.modifyStatus(OrderStatus.ORDERED);
sendMessage("Success", order.getId(), member.getEmail());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ExecutionException;

@Slf4j
@Controller
Expand Down Expand Up @@ -85,7 +86,7 @@ public String registerProduct(@ModelAttribute("ProductRequest") ProductRequest p
@PostMapping("/register")
public String register(@ModelAttribute @Valid ProductRequest productRequest,
@RequestParam("mainFile") MultipartFile mainFile,
@RequestParam("subFiles") List<MultipartFile> subFiles) throws IOException {
@RequestParam("subFiles") List<MultipartFile> subFiles) throws IOException, ExecutionException, InterruptedException {
RsData<Long> id = productService.register(productRequest, mainFile, subFiles);
return rq.redirectWithMsg("/trendpick/products/" + id.getData(), id.getMsg());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package project.trendpick_pro.domain.product.entity.product;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public enum ProductStatus {

SALE("SALE"),
SOLD_OUT("SOLD_OUT"),
STOP("STOP");

private String text;

}
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
package project.trendpick_pro.domain.product.entity.product.dto.request;

import lombok.Getter;
import project.trendpick_pro.domain.product.entity.product.ProductStatus;

@Getter
public class ProductSearchCond {

private String mainCategory;
private String subCategory;
private String keyword;
private Integer sortCode;

public ProductSearchCond(String mainCategory, String subCategory, Integer sortCode) {
this.mainCategory = mainCategory;
this.subCategory = subCategory;
this.sortCode = sortCode;
}

public ProductSearchCond(String mainCategory, String subCategory) {
this.mainCategory = mainCategory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
import com.querydsl.core.annotations.QueryProjection;
import lombok.*;
import project.trendpick_pro.domain.product.entity.product.Product;

import java.io.Serializable;
//import project.trendpick_pro.global.search.entity.ProductSearch;

@Data
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class ProductListResponse {
public class ProductListResponse implements Serializable {

private Long id;
private String name;
private String brand;
private String mainFile;
private int price;

private int discountRate;

private int discountedPrice;

@Builder
Expand All @@ -32,15 +32,25 @@ public ProductListResponse(Long id, String name, String brand, String mainFile,
}

public static ProductListResponse of(Product product) {
return ProductListResponse.builder()
.id(product.getId())
.name(product.getName())
.brand(product.getBrand().getName())
.mainFile(product.getFile().getFileName())
.price(product.getProductOption().getPrice())
.discountedPrice(product.getDiscountedPrice())
.discountRate(product.getDiscountRate())
.build();
if (product.getDiscountedPrice() == 0 && product.getDiscountRate() == 0) {
return ProductListResponse.builder()
.id(product.getId())
.name(product.getName())
.brand(product.getBrand().getName())
.mainFile(product.getFile().getFileName())
.price(product.getProductOption().getPrice())
.build();
} else {
return ProductListResponse.builder()
.id(product.getId())
.name(product.getName())
.brand(product.getBrand().getName())
.mainFile(product.getFile().getFileName())
.price(product.getProductOption().getPrice())
.discountedPrice(product.getDiscountedPrice())
.discountRate(product.getDiscountRate())
.build();
}
}

// public static ProductListResponse of(ProductSearch product) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
import project.trendpick_pro.domain.product.entity.product.Product;
import project.trendpick_pro.domain.tags.tag.entity.Tag;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

@Data
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class ProductResponse {
public class ProductResponse implements Serializable {

private Long id;
private String name;
Expand All @@ -27,17 +28,14 @@ public class ProductResponse {
private List<String> sizes;
private List<String> colors;
private int price;
private int stock;
private List<Tag> tags = new ArrayList<>();

private List<String> tags = new ArrayList<>();
private int discountRate;

private int discountedPrice;

@Builder
@QueryProjection
public ProductResponse(Long id, String name, String mainCategory, String subCategory, String brand, String description,
String mainFile, List<String> subFiles, List<String> sizes, List<String> colors, int price, int stock, List<Tag> tags, double discountRate, int discountedPrice) {
String mainFile, List<String> subFiles, List<String> sizes, List<String> colors, int price, List<String> tags, double discountRate, int discountedPrice) {
this.id = id;
this.name = name;
this.mainCategory = mainCategory;
Expand All @@ -49,30 +47,45 @@ public ProductResponse(Long id, String name, String mainCategory, String subCate
this.sizes = sizes;
this.colors = colors;
this.price = price;
this.stock = stock;
this.tags = tags;
this.discountRate = (int) discountRate;
this.discountedPrice = discountedPrice;
}

public static ProductResponse of (Product product) {
return ProductResponse.builder()
.id(product.getId())
.name(product.getName())
.mainCategory(product.getMainCategory().getName())
.subCategory(product.getSubCategory().getName())
.brand(product.getBrand().getName())
.description(product.getDescription())
.mainFile(product.getFile().getFileName())
.subFiles(subFiles(product.getFile().getChild()))
.sizes(product.getProductOption().getSizes())
.colors(product.getProductOption().getColors())
.price(product.getProductOption().getPrice())
.stock(product.getProductOption().getStock())
.tags(new ArrayList<>(product.getTags()))
.discountedPrice(product.getDiscountedPrice())
.discountRate(product.getDiscountRate())
.build();
if (product.getDiscountedPrice() == 0 && product.getDiscountRate() == 0) {
return ProductResponse.builder()
.id(product.getId())
.name(product.getName())
.mainCategory(product.getMainCategory().getName())
.subCategory(product.getSubCategory().getName())
.brand(product.getBrand().getName())
.description(product.getDescription())
.mainFile(product.getFile().getFileName())
.subFiles(subFiles(product.getFile().getChild()))
.sizes(product.getProductOption().getSizes())
.colors(product.getProductOption().getColors())
.price(product.getProductOption().getPrice())
.tags(product.getTags().stream().map(Tag::getName).toList())
.build();
} else {
return ProductResponse.builder()
.id(product.getId())
.name(product.getName())
.mainCategory(product.getMainCategory().getName())
.subCategory(product.getSubCategory().getName())
.brand(product.getBrand().getName())
.description(product.getDescription())
.mainFile(product.getFile().getFileName())
.subFiles(subFiles(product.getFile().getChild()))
.sizes(product.getProductOption().getSizes())
.colors(product.getProductOption().getColors())
.price(product.getProductOption().getPrice())
.tags(product.getTags().stream().map(Tag::getName).toList())
.discountedPrice(product.getDiscountedPrice())
.discountRate(product.getDiscountRate())
.build();
}
}

private static List<String> subFiles(List<CommonFile> subFiles) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,27 @@
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import project.trendpick_pro.domain.product.entity.product.ProductStatus;
import project.trendpick_pro.domain.product.entity.productOption.dto.ProductOptionSaveRequest;
import project.trendpick_pro.domain.product.exception.ProductStockOutException;

import java.io.Serializable;
import java.util.List;

@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class ProductOption {
public class ProductOption implements Serializable {

@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@ElementCollection
@ElementCollection(fetch = FetchType.EAGER)
@CollectionTable(name = "product_option_sizes", joinColumns = @JoinColumn(name = "product_option_id"))
@Column(name = "size")
private List<String> sizes;

@ElementCollection
@ElementCollection(fetch = FetchType.EAGER)
@CollectionTable(name = "product_option_colors", joinColumns = @JoinColumn(name = "product_option_id"))
@Column(name = "color")
private List<String> colors;
Expand All @@ -34,8 +36,15 @@ public class ProductOption {
@Column(name = "price", nullable = false)
private int price;

@Enumerated(EnumType.STRING)
private ProductStatus status;

public void connectStatus(ProductStatus status){
this.status = status;
}

@Builder
public ProductOption(List<String> size, List<String> color, int stock, int price) {
private ProductOption(List<String> size, List<String> color, int stock, int price) {
this.sizes = size;
this.colors = color;
this.stock = stock;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,24 @@ public class ProductOptionSaveRequest {
@Min(value = 1, message = "가격을 입력해주세요.(1원 이상부터 입력할 수 있습니다.)")
private int price;

private String status;

@Builder
public ProductOptionSaveRequest(List<String> sizes, List<String> colors, int stock, int price) {
public ProductOptionSaveRequest(List<String> sizes, List<String> colors, int stock, int price, String status) {
this.sizes = sizes;
this.colors = colors;
this.stock = stock;
this.price = price;
this.status = status;
}

public static ProductOptionSaveRequest of (List<String> sizes, List<String> colors, int stock, int price) {
public static ProductOptionSaveRequest of (List<String> sizes, List<String> colors, int stock, int price, String status) {
return ProductOptionSaveRequest.builder()
.sizes(sizes)
.colors(colors)
.stock(stock)
.price(price)
.status(status)
.build();
}
}
Loading

0 comments on commit 538eb7d

Please sign in to comment.