From ed8f73a61652e7570d57ea6abf5d96267dda4b25 Mon Sep 17 00:00:00 2001 From: jj Date: Mon, 25 Nov 2024 23:16:13 +0900 Subject: [PATCH 1/8] =?UTF-8?q?refactor:=20=EC=98=81=EC=88=98=EC=A6=9D=20?= =?UTF-8?q?=EC=97=85=EB=8D=B0=EC=9D=B4=ED=8A=B8=20=EC=84=B1=EA=B3=B5=20?= =?UTF-8?q?=EB=A9=94=EC=8B=9C=EC=A7=80=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weeth/domain/account/presentation/ResponseMessage.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/leets/weeth/domain/account/presentation/ResponseMessage.java b/src/main/java/leets/weeth/domain/account/presentation/ResponseMessage.java index 7e918168..ab0a78b3 100644 --- a/src/main/java/leets/weeth/domain/account/presentation/ResponseMessage.java +++ b/src/main/java/leets/weeth/domain/account/presentation/ResponseMessage.java @@ -14,7 +14,8 @@ public enum ResponseMessage { // ReceiptAdminController 관련 RECEIPT_SAVE_SUCCESS("영수증이 성공적으로 저장되었습니다."), - RECEIPT_DELETE_SUCCESS("영수증이 성공적으로 삭제되었습니다."); + RECEIPT_DELETE_SUCCESS("영수증이 성공적으로 삭제되었습니다."), + RECEIPT_UPDATE_SUCCESS("영수증이 성공적으로 업데이트 되었습니다."); private final String message; } From c681af020045bd0879975bc4147d991089034682 Mon Sep 17 00:00:00 2001 From: jj Date: Mon, 25 Nov 2024 23:16:52 +0900 Subject: [PATCH 2/8] =?UTF-8?q?refactor:=20=EC=98=81=EC=88=98=EC=A6=9D=20D?= =?UTF-8?q?TO=EC=97=90=20update=20record=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weeth/domain/account/application/dto/ReceiptDTO.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/leets/weeth/domain/account/application/dto/ReceiptDTO.java b/src/main/java/leets/weeth/domain/account/application/dto/ReceiptDTO.java index 3a9af7ad..ce4536c7 100644 --- a/src/main/java/leets/weeth/domain/account/application/dto/ReceiptDTO.java +++ b/src/main/java/leets/weeth/domain/account/application/dto/ReceiptDTO.java @@ -25,4 +25,12 @@ public record Save( @NotNull Integer cardinal, @Valid List<@NotNull FileSaveRequest> files ) {} + + public record Update( + String description, + @NotNull Integer amount, + @NotNull LocalDate date, + @NotNull Integer cardinal, + @Valid List files + ) {} } From 473022e7720ad3c595d609b9f23aced616e8b09c Mon Sep 17 00:00:00 2001 From: jj Date: Mon, 25 Nov 2024 23:18:47 +0900 Subject: [PATCH 3/8] =?UTF-8?q?feat:=20=ED=9A=8C=EB=B9=84=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=20=EB=82=B4=EC=97=AD=20=EC=88=98=EC=A0=95=20API=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/ReceiptAdminController.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/main/java/leets/weeth/domain/account/presentation/ReceiptAdminController.java b/src/main/java/leets/weeth/domain/account/presentation/ReceiptAdminController.java index df226e7a..274b2d57 100644 --- a/src/main/java/leets/weeth/domain/account/presentation/ReceiptAdminController.java +++ b/src/main/java/leets/weeth/domain/account/presentation/ReceiptAdminController.java @@ -1,8 +1,5 @@ package leets.weeth.domain.account.presentation; -import static leets.weeth.domain.account.presentation.ResponseMessage.RECEIPT_DELETE_SUCCESS; -import static leets.weeth.domain.account.presentation.ResponseMessage.RECEIPT_SAVE_SUCCESS; - import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; @@ -10,11 +7,8 @@ import leets.weeth.domain.account.application.usecase.ReceiptUseCase; import leets.weeth.global.common.response.CommonResponse; import lombok.RequiredArgsConstructor; -import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.*; -import org.springframework.web.multipart.MultipartFile; - -import java.util.List; +import static leets.weeth.domain.account.presentation.ResponseMessage.*; @Tag(name = "ReceiptAdminController", description = "회비 내역 관련 어드민 컨트롤러") @RestController @@ -37,4 +31,11 @@ public CommonResponse delete(@PathVariable Long receiptId) { receiptUseCase.delete(receiptId); return CommonResponse.createSuccess(RECEIPT_DELETE_SUCCESS.getMessage()); } + + @PatchMapping("/{receiptId}") + @Operation(summary="회비 사용 내역 수정") + public CommonResponse update(@PathVariable Long receiptId, @RequestBody @Valid ReceiptDTO.Update dto) { + receiptUseCase.update(receiptId, dto); + return CommonResponse.createSuccess(RECEIPT_UPDATE_SUCCESS.getMessage()); + } } From d599bd91e1aa436ec527003f4492b326175d39d1 Mon Sep 17 00:00:00 2001 From: jj Date: Mon, 25 Nov 2024 23:20:08 +0900 Subject: [PATCH 4/8] =?UTF-8?q?refactor:=20=EC=98=81=EC=88=98=EC=A6=9D=20?= =?UTF-8?q?=EC=97=94=ED=8B=B0=ED=8B=B0=EC=97=90=20update=20=EB=A9=94?= =?UTF-8?q?=EC=86=8C=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weeth/domain/account/domain/entity/Receipt.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main/java/leets/weeth/domain/account/domain/entity/Receipt.java b/src/main/java/leets/weeth/domain/account/domain/entity/Receipt.java index ab55d1c3..6f8fc7e6 100644 --- a/src/main/java/leets/weeth/domain/account/domain/entity/Receipt.java +++ b/src/main/java/leets/weeth/domain/account/domain/entity/Receipt.java @@ -1,6 +1,7 @@ package leets.weeth.domain.account.domain.entity; import jakarta.persistence.*; +import leets.weeth.domain.account.application.dto.ReceiptDTO; import leets.weeth.domain.file.converter.FileListConverter; import leets.weeth.global.common.entity.BaseEntity; import lombok.AccessLevel; @@ -36,4 +37,14 @@ public class Receipt extends BaseEntity { @ManyToOne @JoinColumn(name = "account_id") private Account account; + + public void update(ReceiptDTO.Update dto){ + this.updateUpperClass(dto); + } + + public void updateUpperClass(ReceiptDTO.Update dto) { + this.description = dto.description(); + this.amount = dto.amount(); + this.date = dto.date(); + } } From 70d4cc6c74258735f5e28d386a114eef6371a745 Mon Sep 17 00:00:00 2001 From: jj Date: Mon, 25 Nov 2024 23:20:42 +0900 Subject: [PATCH 5/8] =?UTF-8?q?feat:=20=EC=98=81=EC=88=98=EC=A6=9D=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/usecase/ReceiptUseCase.java | 5 ++-- .../usecase/ReceiptUseCaseImpl.java | 30 +++++++++++++++---- .../domain/service/ReceiptUpdateService.java | 14 +++++++++ 3 files changed, 40 insertions(+), 9 deletions(-) create mode 100644 src/main/java/leets/weeth/domain/account/domain/service/ReceiptUpdateService.java diff --git a/src/main/java/leets/weeth/domain/account/application/usecase/ReceiptUseCase.java b/src/main/java/leets/weeth/domain/account/application/usecase/ReceiptUseCase.java index 6207b941..c0d27f15 100644 --- a/src/main/java/leets/weeth/domain/account/application/usecase/ReceiptUseCase.java +++ b/src/main/java/leets/weeth/domain/account/application/usecase/ReceiptUseCase.java @@ -1,12 +1,11 @@ package leets.weeth.domain.account.application.usecase; import leets.weeth.domain.account.application.dto.ReceiptDTO; -import org.springframework.web.multipart.MultipartFile; - -import java.util.List; public interface ReceiptUseCase { void save(ReceiptDTO.Save dto); + void update(Long reciptId, ReceiptDTO.Update dto); + void delete(Long id); } diff --git a/src/main/java/leets/weeth/domain/account/application/usecase/ReceiptUseCaseImpl.java b/src/main/java/leets/weeth/domain/account/application/usecase/ReceiptUseCaseImpl.java index 76e0dec9..6b371af5 100644 --- a/src/main/java/leets/weeth/domain/account/application/usecase/ReceiptUseCaseImpl.java +++ b/src/main/java/leets/weeth/domain/account/application/usecase/ReceiptUseCaseImpl.java @@ -5,19 +5,14 @@ import leets.weeth.domain.account.application.mapper.ReceiptMapper; import leets.weeth.domain.account.domain.entity.Account; import leets.weeth.domain.account.domain.entity.Receipt; -import leets.weeth.domain.account.domain.service.AccountGetService; -import leets.weeth.domain.account.domain.service.ReceiptDeleteService; -import leets.weeth.domain.account.domain.service.ReceiptGetService; -import leets.weeth.domain.account.domain.service.ReceiptSaveService; +import leets.weeth.domain.account.domain.service.*; import leets.weeth.domain.file.application.mapper.FileMapper; import leets.weeth.domain.file.domain.entity.File; import leets.weeth.domain.file.domain.service.FileDeleteService; import leets.weeth.domain.file.domain.service.FileGetService; import leets.weeth.domain.file.domain.service.FileSaveService; -import leets.weeth.domain.file.service.S3Service; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; -import org.springframework.web.multipart.MultipartFile; import java.util.List; @@ -28,6 +23,7 @@ public class ReceiptUseCaseImpl implements ReceiptUseCase { private final ReceiptGetService receiptGetService; private final ReceiptDeleteService receiptDeleteService; private final ReceiptSaveService receiptSaveService; + private final ReceiptUpdateService receiptUpdateService; private final AccountGetService accountGetService; private final FileGetService fileGetService; @@ -49,6 +45,28 @@ public void save(ReceiptDTO.Save dto) { fileSaveService.save(files); } + @Override + @Transactional + public void update(Long reciptId, ReceiptDTO.Update dto){ + Account account = accountGetService.find(dto.cardinal()); + Receipt receipt = receiptGetService.find(reciptId); + account.cancel(receipt); + + if(!dto.files().isEmpty()){ // 업데이트하려는 파일이 있다면 파일을 전체 삭제한 뒤 저장 + List fileList = getFiles(reciptId); + fileDeleteService.delete(fileList); + + List files = fileMapper.toFileList(dto.files(), receipt); + fileSaveService.save(files); + } + receiptUpdateService.update(receipt, dto); + account.spend(receipt); + } + + private List getFiles(Long reciptId) { + return fileGetService.findAllByReceipt(reciptId); + } + @Override @Transactional public void delete(Long id) { diff --git a/src/main/java/leets/weeth/domain/account/domain/service/ReceiptUpdateService.java b/src/main/java/leets/weeth/domain/account/domain/service/ReceiptUpdateService.java new file mode 100644 index 00000000..96f4c29c --- /dev/null +++ b/src/main/java/leets/weeth/domain/account/domain/service/ReceiptUpdateService.java @@ -0,0 +1,14 @@ +package leets.weeth.domain.account.domain.service; + +import leets.weeth.domain.account.application.dto.ReceiptDTO; +import leets.weeth.domain.account.domain.entity.Receipt; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class ReceiptUpdateService { + public void update(Receipt receipt, ReceiptDTO.Update dto) { + receipt.update(dto); + } +} \ No newline at end of file From 506ca5b9b7a5db9ff184b55943704220c2c1975d Mon Sep 17 00:00:00 2001 From: jj Date: Tue, 26 Nov 2024 00:46:12 +0900 Subject: [PATCH 6/8] =?UTF-8?q?refactor:=20=EB=B3=80=EC=88=98=EB=AA=85=20?= =?UTF-8?q?=EC=98=A4=ED=83=80=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../account/application/usecase/ReceiptUseCase.java | 2 +- .../application/usecase/ReceiptUseCaseImpl.java | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/leets/weeth/domain/account/application/usecase/ReceiptUseCase.java b/src/main/java/leets/weeth/domain/account/application/usecase/ReceiptUseCase.java index c0d27f15..cf1486f3 100644 --- a/src/main/java/leets/weeth/domain/account/application/usecase/ReceiptUseCase.java +++ b/src/main/java/leets/weeth/domain/account/application/usecase/ReceiptUseCase.java @@ -5,7 +5,7 @@ public interface ReceiptUseCase { void save(ReceiptDTO.Save dto); - void update(Long reciptId, ReceiptDTO.Update dto); + void update(Long receiptId, ReceiptDTO.Update dto); void delete(Long id); } diff --git a/src/main/java/leets/weeth/domain/account/application/usecase/ReceiptUseCaseImpl.java b/src/main/java/leets/weeth/domain/account/application/usecase/ReceiptUseCaseImpl.java index 6b371af5..cf763837 100644 --- a/src/main/java/leets/weeth/domain/account/application/usecase/ReceiptUseCaseImpl.java +++ b/src/main/java/leets/weeth/domain/account/application/usecase/ReceiptUseCaseImpl.java @@ -47,13 +47,13 @@ public void save(ReceiptDTO.Save dto) { @Override @Transactional - public void update(Long reciptId, ReceiptDTO.Update dto){ + public void update(Long receiptId, ReceiptDTO.Update dto){ Account account = accountGetService.find(dto.cardinal()); - Receipt receipt = receiptGetService.find(reciptId); + Receipt receipt = receiptGetService.find(receiptId); account.cancel(receipt); if(!dto.files().isEmpty()){ // 업데이트하려는 파일이 있다면 파일을 전체 삭제한 뒤 저장 - List fileList = getFiles(reciptId); + List fileList = getFiles(receiptId); fileDeleteService.delete(fileList); List files = fileMapper.toFileList(dto.files(), receipt); @@ -63,8 +63,8 @@ public void update(Long reciptId, ReceiptDTO.Update dto){ account.spend(receipt); } - private List getFiles(Long reciptId) { - return fileGetService.findAllByReceipt(reciptId); + private List getFiles(Long receiptId) { + return fileGetService.findAllByReceipt(receiptId); } @Override From 495cfae33bff6b35a89e7d2f76e4191fd6d6abba Mon Sep 17 00:00:00 2001 From: jj Date: Tue, 26 Nov 2024 13:23:43 +0900 Subject: [PATCH 7/8] =?UTF-8?q?refactor:=20=EC=98=81=EC=88=98=EC=A6=9D=20u?= =?UTF-8?q?pdate=20record=EC=9D=98=20files=EC=97=90=20@NotNull=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../leets/weeth/domain/account/application/dto/ReceiptDTO.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/leets/weeth/domain/account/application/dto/ReceiptDTO.java b/src/main/java/leets/weeth/domain/account/application/dto/ReceiptDTO.java index ce4536c7..bf1b33c1 100644 --- a/src/main/java/leets/weeth/domain/account/application/dto/ReceiptDTO.java +++ b/src/main/java/leets/weeth/domain/account/application/dto/ReceiptDTO.java @@ -31,6 +31,6 @@ public record Update( @NotNull Integer amount, @NotNull LocalDate date, @NotNull Integer cardinal, - @Valid List files + @Valid List<@NotNull FileSaveRequest> files ) {} } From e4673301a7c59a336e0de94b099c66da282a29e1 Mon Sep 17 00:00:00 2001 From: jj Date: Tue, 26 Nov 2024 13:25:53 +0900 Subject: [PATCH 8/8] =?UTF-8?q?refactor:=20=EC=98=81=EC=88=98=EC=A6=9D=20e?= =?UTF-8?q?ntity=EC=97=90=EC=84=9C=20updateUpperClass=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=EB=A5=BC=20update=20=EB=A9=94=EC=84=9C=EB=93=9C?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=91=ED=95=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../leets/weeth/domain/account/domain/entity/Receipt.java | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/main/java/leets/weeth/domain/account/domain/entity/Receipt.java b/src/main/java/leets/weeth/domain/account/domain/entity/Receipt.java index 6f8fc7e6..1569b638 100644 --- a/src/main/java/leets/weeth/domain/account/domain/entity/Receipt.java +++ b/src/main/java/leets/weeth/domain/account/domain/entity/Receipt.java @@ -31,18 +31,11 @@ public class Receipt extends BaseEntity { private LocalDate date; - @Convert(converter = FileListConverter.class) - private List images; - @ManyToOne @JoinColumn(name = "account_id") private Account account; public void update(ReceiptDTO.Update dto){ - this.updateUpperClass(dto); - } - - public void updateUpperClass(ReceiptDTO.Update dto) { this.description = dto.description(); this.amount = dto.amount(); this.date = dto.date();