Skip to content

Commit

Permalink
Merge pull request #445 from TrandPick/development
Browse files Browse the repository at this point in the history
메인 브랜치로 병합
  • Loading branch information
jooooonj authored Sep 19, 2023
2 parents 2d43ceb + 5130e78 commit 4520639
Show file tree
Hide file tree
Showing 93 changed files with 1,624 additions and 976 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/
docker-compose.yml

### STS ###
.apt_generated
Expand Down
13 changes: 0 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,8 @@
# Stage 1: Pinpoint setup
# FROM alpine:3.14 as pinpoint-setup
# WORKDIR /usr/local
# ADD https://github.com/pinpoint-apm/pinpoint/releases/download/v2.5.2/pinpoint-agent-2.5.2.tar.gz /usr/local
# RUN tar -zxvf pinpoint-agent-2.5.2.tar.gz && \
# sed -i 's/profiler.transport.grpc.collector.ip=127.0.0.1/profiler.transport.grpc.collector.ip=10.41.183.156/g' pinpoint-agent-2.5.2/pinpoint-root.config && \
# sed -i 's/profiler.collector.ip=127.0.0.1/profiler.collector.ip=10.41.183.156/g' pinpoint-agent-2.5.2/pinpoint-root.config

# Stage 2: Build final image
FROM openjdk:17-jdk-alpine
WORKDIR /app
# COPY --from=pinpoint-setup /usr/local/pinpoint-agent-2.5.2/ ./pinpoint-agent
ARG JAR_FILE=build/libs/*.jar
COPY ${JAR_FILE} app.jar
EXPOSE 8080
ENTRYPOINT ["java","-jar", \
# "-javaagent:/app/pinpoint-agent/pinpoint-bootstrap-2.5.2.jar", \
# "-Dpinpoint.applicationName=TrendPick", \
# "-Dpinpoint.config=/app/pinpoint-agent/pinpoint-root.config", \
"-Dspring.profiles.active=prod", \
"/app/app.jar"]
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ public interface BrandService {
Brand findByName(String name);
Brand findById(Long id);
Long count();
void saveAll(List<String> brands);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,48 +7,51 @@
import project.trendpick_pro.domain.brand.entity.dto.BrandResponse;
import project.trendpick_pro.domain.brand.repository.BrandRepository;
import project.trendpick_pro.domain.brand.service.BrandService;
import project.trendpick_pro.domain.store.entity.Store;
import project.trendpick_pro.domain.store.repository.StoreRepository;
import project.trendpick_pro.global.basedata.tagname.entity.TagName;

import java.util.ArrayList;
import java.util.List;

@Service
@RequiredArgsConstructor
public class BrandServiceImpl implements BrandService {

private final BrandRepository brandRepository;
private final StoreRepository storeRepository;

@Transactional(readOnly = true)
@Override
public boolean isPresent(String name){
public boolean isPresent(String name) {
return brandRepository.findByName(name).isPresent();
}

@Transactional
@Override
public void save(String name){
public void save(String name) {
brandRepository.save(new Brand(name));
}

@Transactional
@Override
public void delete(Long id){
public void delete(Long id) {
Brand brand = brandRepository.findById(id).orElseThrow();
brandRepository.delete(brand);
}

@Transactional(readOnly = true)
@Override
public List<BrandResponse> findAll(){
public List<BrandResponse> findAll() {
return brandRepository.findAllBy();
}

@Transactional(readOnly = true)
@Override
public Brand findByName(String name) {
try {
return brandRepository.findByName(name).get();
} catch (Exception e) {
return brandRepository.save(new Brand(name));
}
return brandRepository.findByName(name).orElseThrow(
() -> new IllegalArgumentException("해당 브랜드는 존재하지 않습니다.")
);
}

@Transactional(readOnly = true)
Expand All @@ -62,4 +65,15 @@ public Brand findById(Long id) {
public Long count() {
return brandRepository.count();
}

@Override
@Transactional
public void saveAll(List<String> brands) {
List<Brand> list = new ArrayList<>();
for (String brand : brands) {
list.add(new Brand(brand));
}

brandRepository.saveAll(list);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public String showCart(Model model) {

@PreAuthorize("hasAuthority({'MEMBER'})")
@PostMapping("/add")
public String addItem(@ModelAttribute @Valid CartItemRequest cartItemRequests, Model model) {
public String addItem(@ModelAttribute @Valid CartItemRequest cartItemRequests) {
RsData<CartItem> result = cartService.addCartItem(rq.getMember(), cartItemRequests);

if(result.isFail())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ public static CartItem of(Cart cart, Product product, CartItemRequest cartItemRe
return CartItem.builder()
.cart(cart)
.product(product)
.quantity(cartItemRequest.getQuantity())
.quantity(0)
.size(cartItemRequest.getSize())
.color(cartItemRequest.getColor())
.build();
}

public void updateCount(int quantity){
this.quantity += quantity;
this.cart.updateTotalCount(quantity);
this.quantity += quantity;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ public RsData<CartItem> addCartItem(Member member, CartItemRequest cartItemReque
}
CartItem cartItem = cartItemRepository.findByCartIdAndProductId(cart.getId(), product.getId());

if (cartItem == null)
if (cartItem == null) {
cartItem = CartItem.of(cart, product, cartItemRequest);
}

cartItem.updateCount(cartItemRequest.getQuantity());
cartItemRepository.save(cartItem);
Expand Down
43 changes: 28 additions & 15 deletions src/main/java/project/trendpick_pro/domain/cash/entity/CashLog.java
Original file line number Diff line number Diff line change
@@ -1,42 +1,55 @@
package project.trendpick_pro.domain.cash.entity;

import jakarta.persistence.*;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.SuperBuilder;
import lombok.*;
import project.trendpick_pro.domain.common.base.BaseTimeEntity;
import project.trendpick_pro.domain.member.entity.Member;
import project.trendpick_pro.domain.rebate.entity.RebateOrderItem;
import project.trendpick_pro.domain.withdraw.entity.WithdrawApply;

import static jakarta.persistence.FetchType.LAZY;

@Entity
@Getter
@NoArgsConstructor
@SuperBuilder
@AllArgsConstructor
@Builder
@ToString(callSuper = true)
public class CashLog {
public class CashLog extends BaseTimeEntity { //돈의 흐름을 기록하기 위한 엔티티
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "cash_log_id")
private Long id;

private String relTypeCode;

private Long relId;

@ManyToOne(fetch = LAZY)
private Member member;

private String store;
private long price; // 변동
private Long rebateOrderItemId;
private Long withDrawApplyId;

@Enumerated(EnumType.STRING)
private EvenType eventType;

public CashLog(Long id){
this.id=id;
}
public enum EvenType {
출금__통장입금,
브랜드정산__예치금;
}

static public CashLog of(WithdrawApply withdrawApply){
return CashLog.builder()
.withDrawApplyId(withdrawApply.getId())
.price(withdrawApply.getPrice() * -1)
.store(withdrawApply.getStore())
.eventType(EvenType.출금__통장입금)
.build();
}

static public CashLog of(RebateOrderItem rebateOrderItem){
return CashLog.builder()
.rebateOrderItemId(rebateOrderItem.getId())
.price(rebateOrderItem.calculateRebatePrice())
.store(rebateOrderItem.getSellerName())
.eventType(EvenType.브랜드정산__예치금)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,5 @@
@Getter
@AllArgsConstructor
public class CashResponse {

CashLog cashLog;
long newRestCash;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@

import project.trendpick_pro.domain.cash.entity.CashLog;
import project.trendpick_pro.domain.member.entity.Member;
import project.trendpick_pro.domain.rebate.entity.RebateOrderItem;
import project.trendpick_pro.domain.withdraw.entity.WithdrawApply;


public interface CashService {
CashLog addCash(Member member, long price, String relTypeCode,Long relId, CashLog.EvenType eventType);
CashLog addCashLog(WithdrawApply withdrawApply);

CashLog addCashLog(RebateOrderItem rebateOrderItem);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,35 @@

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import project.trendpick_pro.domain.brand.entity.Brand;
import project.trendpick_pro.domain.brand.service.BrandService;
import project.trendpick_pro.domain.cash.entity.CashLog;
import project.trendpick_pro.domain.cash.repository.CashLogRepository;
import project.trendpick_pro.domain.cash.service.CashService;
import project.trendpick_pro.domain.member.entity.Member;
import project.trendpick_pro.domain.member.service.MemberService;
import project.trendpick_pro.domain.rebate.entity.RebateOrderItem;
import project.trendpick_pro.domain.withdraw.entity.WithdrawApply;

@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class CashServiceImpl implements CashService {
private final CashLogRepository cashLogRepository;
@Transactional
@Override
public CashLog addCashLog(WithdrawApply withdrawApply) {
CashLog cashLog = cashLogRepository.save(CashLog.of(withdrawApply));
return cashLog;
}

public CashLog addCash(Member member, long price, String relTypeCode, Long relId, CashLog.EvenType eventType) {
CashLog cashLog = CashLog.builder()
.member(member)
.price(price)
.relTypeCode(relTypeCode)
.relId(relId)
.eventType(eventType)
.build();

cashLogRepository.save(cashLog);

@Transactional
@Override
public CashLog addCashLog(RebateOrderItem rebateOrderItem) {
CashLog cashLog = cashLogRepository.save(CashLog.of(rebateOrderItem));
return cashLog;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,14 @@
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.util.UriComponentsBuilder;
import project.trendpick_pro.global.kafka.view.service.ViewService;

@Slf4j
@Controller
@RequiredArgsConstructor
public class CommonController {

private final ViewService viewService;

@GetMapping("/")
public String homePage(HttpSession session) {
viewService.requestIncrementViewCount(session);
String mainCategory = "전체";
return "redirect:" + UriComponentsBuilder
.fromPath("/trendpick/products/list")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import project.trendpick_pro.domain.coupon.entity.dto.response.CouponCardByApplyResponse;
import project.trendpick_pro.domain.coupon.service.CouponCardService;
import project.trendpick_pro.global.util.rsData.RsData;

import java.time.LocalDateTime;
import java.util.List;

Expand All @@ -29,21 +28,21 @@ public String issueCoupon(@PathVariable("couponId") Long couponId, HttpServletRe
}

@PreAuthorize("hasRole('MEMBER')")
@GetMapping("apply")
@GetMapping("/apply")
@ResponseBody
public List<CouponCardByApplyResponse> showApplicableCoupons(@RequestParam("orderItem") Long orderItemId) {
return couponCardService.showCouponCardsByOrderItem(orderItemId);
}

@PreAuthorize("hasRole('MEMBER')")
@PostMapping("apply")
@PostMapping("/apply")
public String applyCoupon(@RequestParam("couponCard") Long couponCardId, @RequestParam("orderItem") Long orderItemId, HttpServletRequest req) {
RsData result = couponCardService.apply(couponCardId, orderItemId);
RsData result = couponCardService.apply(couponCardId, orderItemId, LocalDateTime.now());
return processRequest(result, "쿠폰이 적용되었습니다.", req);
}

@PreAuthorize("hasRole('MEMBER')")
@PostMapping("cancel")
@PostMapping("/cancel")
public String cancelCoupon(@RequestParam("orderItem") Long orderItemId, HttpServletRequest req) {
RsData result = couponCardService.cancel(orderItemId);
return processRequest(result, "쿠폰 적용이 취소되었습니다.", req);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class CouponCard extends BaseTimeEntity {
private Long id;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "coupon", nullable = false)
@JoinColumn(name = "coupon")
private Coupon coupon;

@Column(name = "coupon_code", nullable = false, unique = true)
Expand Down Expand Up @@ -63,24 +63,15 @@ && validateStatus()
&& validateMinimumPurchaseAmount(orderItem.getOrderPrice());
}

public void use(OrderItem orderItem, LocalDateTime dateTime) {
settingStatusAndDate(dateTime);
orderItem.applyCouponCard(this);
orderItem.discount(
orderItem.getOrderPrice() * (this.coupon.getDiscountPercent() / 100)
);
public void use(LocalDateTime dateTime) {
this.status = CouponStatus.USED;
this.usedDate = dateTime;
}

public void cancel(OrderItem orderItem){
this.status = CouponStatus.AVAILABLE;
this.usedDate = null;
orderItem.cancelCouponCard();
this.coupon.decreaseIssueCount();
}

private void settingStatusAndDate(LocalDateTime dateTime) {
this.status = CouponStatus.USED;
this.usedDate = dateTime;
}

private boolean validateMinimumPurchaseAmount(int price){
Expand All @@ -98,9 +89,10 @@ private boolean validateStatus(){

private void updateStatus(LocalDateTime dateTime) {
checkDateNotNull(dateTime);
if(dateTime.isBefore(this.coupon.getExpirationPeriod().getStartDate())) {
if(dateTime.isBefore(this.coupon.getExpirationPeriod().getStartDate()))
this.status = CouponStatus.NOT_YET_ACTIVE;
} this.status = CouponStatus.AVAILABLE;
else
this.status = CouponStatus.AVAILABLE;
}

private void checkDateNotNull(LocalDateTime dateTime) {
Expand Down
Loading

0 comments on commit 4520639

Please sign in to comment.