Skip to content

Commit

Permalink
Merge pull request #85 from HAB-DAY/update/#62/updateApis
Browse files Browse the repository at this point in the history
Update/#62/update apis
  • Loading branch information
yeonank authored Sep 6, 2023
2 parents 2f48611 + efde94a commit 0eeac45
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/main/java/com/habday/server/classes/Calculation.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ public int calFundingPercentage(BigDecimal totalPrice, BigDecimal goalPrice){
return totalPrice.divide(goalPrice, 2, BigDecimal.ROUND_DOWN).multiply(BigDecimal.valueOf(100)).intValue();
}

public BigDecimal calCancelTotalPrice(BigDecimal amount, BigDecimal totalPrice){
if (totalPrice == null) {
log.info("fundingService: totalPrice null임" + totalPrice);
totalPrice = BigDecimal.ZERO;
}
return totalPrice.subtract(amount);
}

//예약결제 시간 계산
public Date calPayDate(LocalDate localDate){
Date toDate = Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,8 @@ public void updateFundDetail(String fundDetail) {
this.fundDetail = fundDetail;
}

public void updateCancel(BigDecimal totalPrice, int percentage){
this.totalPrice = totalPrice;
this.percentage = percentage;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public interface FundingMemberRepository extends JpaRepository<FundingMember, Lo
@Query("select fm.id as fundingMemberId, i.id as fundingItemId, i.fundingName as fundingName, m.name as creatorName, fm.amount as fundingAmount, i.fundingItemImg as fundingItemImg, i.status as fundingStatus, fm.fundingDate as fundingDate, fm.payment_status as payment_status, fm.merchantId as merchantId, i.fundDetail as fundDetail, i.startDate as startDate, i.finishDate as finishDate from FundingMember fm join fm.fundingItem i join fm.member m where fm.member = :member order by fm.id desc")
List<ParticipatedListInterface> getPagingListFirst(Member member, Pageable page);

@Query("select fm.id as fundingMemberId, i.id as fundingItemId, i.fundingName as fundingName, m.name as creatorName, fm.amount as fundingAmount, i.fundingItemImg as fundingItemImg, i.status as fundingStatus, fm.fundingDate as fundingDate, fm.payment_status as payment_status, fm.merchantId as merchantId from FundingMember fm join fm.fundingItem i join fm.member m where fm.id < :id and fm.member = :member order by fm.id desc")
@Query("select fm.id as fundingMemberId, i.id as fundingItemId, i.fundingName as fundingName, m.name as creatorName, fm.amount as fundingAmount, i.fundingItemImg as fundingItemImg, i.status as fundingStatus, fm.fundingDate as fundingDate, fm.payment_status as payment_status, fm.merchantId as merchantId from FundingMember fm join fm.fundingItem i join fm.member m where i.id < :id and fm.member = :member order by fm.id desc")
List<ParticipatedListInterface> getPagingListAfter(Long id, Member member, Pageable page);

/*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.habday.server.dto.req.iamport;

import lombok.Getter;
import lombok.NoArgsConstructor;

import javax.validation.constraints.NotNull;

@Getter
@NoArgsConstructor
public class NoneAuthPayUnscheduleRequestDto {
/*@NotNull(message = "취소를 위해서는 결제 수단 id가 필요합니다.")
private Long payment_id;*/
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/com/habday/server/service/FundingService.java
Original file line number Diff line number Diff line change
Expand Up @@ -291,11 +291,19 @@ public void deleteFundingItem(Long memberId, Long fundingItemId) {
confirmation.updateFundingItemNull();
}

@Transactional
public UnscheduleResponseDto cancel(Long memberId, NoneAuthPayUnscheduleRequestDto request){
FundingMember fundingMember = fundingMemberRepository.findById(request.getFundingMemberId()).orElseThrow(() -> new CustomException(NO_FUNDING_MEMBER_ID));
FundingItem fundingItem = fundingItemRepository.findById(fundingMember.getFundingItem().getId()).orElseThrow(() -> new CustomException(NO_FUNDING_ITEM_ID));

if(memberId != fundingMember.getMember().getId())
throw new CustomException(FUNDING_MEMBER_VALIDATION_FAIL);
return payService.noneAuthPayUnschedule(request);

UnscheduleResponseDto response = payService.noneAuthPayUnschedule(request);
BigDecimal totalBrice = calculation.calCancelTotalPrice(fundingMember.getAmount(), fundingItem.getTotalPrice());
int percentage = calculation.calFundingPercentage(totalBrice, fundingItem.getGoalPrice());
fundingItem.updateCancel(totalBrice, percentage);
return response;

}

Expand Down

0 comments on commit 0eeac45

Please sign in to comment.