Skip to content

Commit

Permalink
Merge pull request #78 from Leets-Official/feat#77
Browse files Browse the repository at this point in the history
Feat #77 ์˜์ˆ˜์ฆ ์ˆ˜์ • ๊ธฐ๋Šฅ ์ถ”๊ฐ€
  • Loading branch information
jj0526 authored Nov 26, 2024
2 parents 9e56411 + e467330 commit dd1a7d9
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<@NotNull FileSaveRequest> files
) {}
}
Original file line number Diff line number Diff line change
@@ -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 receiptId, ReceiptDTO.Update dto);

void delete(Long id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand All @@ -49,6 +45,28 @@ public void save(ReceiptDTO.Save dto) {
fileSaveService.save(files);
}

@Override
@Transactional
public void update(Long receiptId, ReceiptDTO.Update dto){
Account account = accountGetService.find(dto.cardinal());
Receipt receipt = receiptGetService.find(receiptId);
account.cancel(receipt);

if(!dto.files().isEmpty()){ // ์—…๋ฐ์ดํŠธํ•˜๋ ค๋Š” ํŒŒ์ผ์ด ์žˆ๋‹ค๋ฉด ํŒŒ์ผ์„ ์ „์ฒด ์‚ญ์ œํ•œ ๋’ค ์ €์žฅ
List<File> fileList = getFiles(receiptId);
fileDeleteService.delete(fileList);

List<File> files = fileMapper.toFileList(dto.files(), receipt);
fileSaveService.save(files);
}
receiptUpdateService.update(receipt, dto);
account.spend(receipt);
}

private List<File> getFiles(Long receiptId) {
return fileGetService.findAllByReceipt(receiptId);
}

@Override
@Transactional
public void delete(Long id) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -30,10 +31,13 @@ public class Receipt extends BaseEntity {

private LocalDate date;

@Convert(converter = FileListConverter.class)
private List<String> images;

@ManyToOne
@JoinColumn(name = "account_id")
private Account account;

public void update(ReceiptDTO.Update dto){
this.description = dto.description();
this.amount = dto.amount();
this.date = dto.date();
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
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;
import leets.weeth.domain.account.application.dto.ReceiptDTO;
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
Expand All @@ -37,4 +31,11 @@ public CommonResponse<Void> delete(@PathVariable Long receiptId) {
receiptUseCase.delete(receiptId);
return CommonResponse.createSuccess(RECEIPT_DELETE_SUCCESS.getMessage());
}

@PatchMapping("/{receiptId}")
@Operation(summary="ํšŒ๋น„ ์‚ฌ์šฉ ๋‚ด์—ญ ์ˆ˜์ •")
public CommonResponse<Void> update(@PathVariable Long receiptId, @RequestBody @Valid ReceiptDTO.Update dto) {
receiptUseCase.update(receiptId, dto);
return CommonResponse.createSuccess(RECEIPT_UPDATE_SUCCESS.getMessage());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public enum ResponseMessage {

// ReceiptAdminController ๊ด€๋ จ
RECEIPT_SAVE_SUCCESS("์˜์ˆ˜์ฆ์ด ์„ฑ๊ณต์ ์œผ๋กœ ์ €์žฅ๋˜์—ˆ์Šต๋‹ˆ๋‹ค."),
RECEIPT_DELETE_SUCCESS("์˜์ˆ˜์ฆ์ด ์„ฑ๊ณต์ ์œผ๋กœ ์‚ญ์ œ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.");
RECEIPT_DELETE_SUCCESS("์˜์ˆ˜์ฆ์ด ์„ฑ๊ณต์ ์œผ๋กœ ์‚ญ์ œ๋˜์—ˆ์Šต๋‹ˆ๋‹ค."),
RECEIPT_UPDATE_SUCCESS("์˜์ˆ˜์ฆ์ด ์„ฑ๊ณต์ ์œผ๋กœ ์—…๋ฐ์ดํŠธ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.");

private final String message;
}

0 comments on commit dd1a7d9

Please sign in to comment.