From 6af1aeccc3932aeac7e41d85aed8a1e255c40e11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=A1=E1=86=AB=E1=84=82=E1=85=A1=E1=84=8B?= =?UTF-8?q?=E1=85=A7=E1=86=BC?= Date: Mon, 3 Jun 2024 15:47:11 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20=ED=9A=8C=EB=B9=84=20=EA=B7=9C?= =?UTF-8?q?=EC=B9=99=20=EC=83=9D=EC=84=B1/=EC=88=98=EC=A0=95=20api=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hanaro/triptogether/dues/domain/entity/Dues.java | 7 ++++++- .../dues/dto/request/DuesRuleRequestDto.java | 2 +- .../hanaro/triptogether/dues/service/DuesService.java | 11 +++++++++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/hanaro/triptogether/dues/domain/entity/Dues.java b/src/main/java/com/hanaro/triptogether/dues/domain/entity/Dues.java index 28190f5..ef40871 100644 --- a/src/main/java/com/hanaro/triptogether/dues/domain/entity/Dues.java +++ b/src/main/java/com/hanaro/triptogether/dues/domain/entity/Dues.java @@ -1,5 +1,6 @@ package com.hanaro.triptogether.dues.domain.entity; +import com.hanaro.triptogether.dues.dto.request.DuesRuleRequestDto; import jakarta.persistence.*; import lombok.*; @@ -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(); + } } diff --git a/src/main/java/com/hanaro/triptogether/dues/dto/request/DuesRuleRequestDto.java b/src/main/java/com/hanaro/triptogether/dues/dto/request/DuesRuleRequestDto.java index 8909e58..448b9a1 100644 --- a/src/main/java/com/hanaro/triptogether/dues/dto/request/DuesRuleRequestDto.java +++ b/src/main/java/com/hanaro/triptogether/dues/dto/request/DuesRuleRequestDto.java @@ -14,7 +14,7 @@ public class DuesRuleRequestDto { private Long teamIdx; - private LocalDate duesDate; + private int duesDate; private BigDecimal duesAmount; public Dues toEntity() { diff --git a/src/main/java/com/hanaro/triptogether/dues/service/DuesService.java b/src/main/java/com/hanaro/triptogether/dues/service/DuesService.java index 06d18f7..ae27929 100644 --- a/src/main/java/com/hanaro/triptogether/dues/service/DuesService.java +++ b/src/main/java/com/hanaro/triptogether/dues/service/DuesService.java @@ -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; @@ -34,7 +35,13 @@ public List 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){ @@ -42,7 +49,7 @@ public DuesRuleResponseDto getDuesRule(Long 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(); }