Skip to content

Commit

Permalink
Merge pull request #105 from Hanaro-trip-together-bank/feature/dues-req
Browse files Browse the repository at this point in the history
refactor: 회비 규칙 생성/수정 api 구현
  • Loading branch information
ny2060 authored Jun 3, 2024
2 parents 608e457 + 6af1aec commit 567d33e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.hanaro.triptogether.dues.domain.entity;

import com.hanaro.triptogether.dues.dto.request.DuesRuleRequestDto;
import jakarta.persistence.*;
import lombok.*;

Expand All @@ -19,10 +20,14 @@ public class Dues extends BaseEntity {

private Long teamIdx;

private LocalDate duesDate;
private int duesDate;

private BigDecimal duesAmount;


public void modifyDuesRule(DuesRuleRequestDto dto){
this.duesDate=dto.getDuesDate();
this.duesAmount=dto.getDuesAmount();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
public class DuesRuleRequestDto {

private Long teamIdx;
private LocalDate duesDate;
private int duesDate;
private BigDecimal duesAmount;

public Dues toEntity() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import java.math.BigDecimal;
import java.time.YearMonth;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -34,15 +35,21 @@ public List<DuesDetailYearTotalAmountResponseDto> getDuesDetailByMonthAmount(Lon
}

public void setDuesRule(DuesRuleRequestDto duesRuleRequestDto){
duesRepository.save(duesRuleRequestDto.toEntity());
Dues curDues = duesRepository.findDuesByTeamIdx(duesRuleRequestDto.getTeamIdx());
if (curDues !=null) {
curDues.modifyDuesRule(duesRuleRequestDto);
duesRepository.save(curDues);
} else {
duesRepository.save(duesRuleRequestDto.toEntity());
}
}

public DuesRuleResponseDto getDuesRule(Long teamIdx){
Dues dues = duesRepository.findDuesByTeamIdx(teamIdx);
if (dues == null) {
return null;
}
return DuesRuleResponseDto.builder().duesDate(String.valueOf(dues.getDuesDate().getDayOfMonth())).duesAmount(dues.getDuesAmount()).build();
return DuesRuleResponseDto.builder().duesDate(String.valueOf(dues.getDuesDate())).duesAmount(dues.getDuesAmount()).build();
}


Expand Down

0 comments on commit 567d33e

Please sign in to comment.