Skip to content

Commit

Permalink
[bugfix/InhaBas#341] 예산 신청 COMPLETED시 회계내역에 파일 복사
Browse files Browse the repository at this point in the history
  • Loading branch information
whitem4rk committed Jul 4, 2024
1 parent acf52b4 commit 9445c9d
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

public interface S3Service {

String uploadS3File(MultipartFile multipartFile, String dirName)
String uploadS3File(MultipartFile multipartFile, String fileName)
throws SdkClientException, IOException;

String uploadS3Image(MultipartFile multipartFile, String fileName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
@Embeddable
public class Price {

@Column(nullable = false)
@Column(nullable = false, name = "OUTCOME")
private Integer value;

public Price() {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.inhabas.api.domain.budget.usecase;

import java.util.ArrayList;
import java.util.List;

import lombok.RequiredArgsConstructor;

import org.springframework.stereotype.Service;
Expand All @@ -9,10 +12,12 @@
import com.inhabas.api.auth.domain.oauth2.member.domain.entity.Member;
import com.inhabas.api.auth.domain.oauth2.member.domain.exception.MemberNotFoundException;
import com.inhabas.api.auth.domain.oauth2.member.repository.MemberRepository;
import com.inhabas.api.domain.budget.domain.BudgetHistory;
import com.inhabas.api.domain.budget.domain.BudgetSupportApplication;
import com.inhabas.api.domain.budget.dto.BudgetApplicationStatusChangeRequest;
import com.inhabas.api.domain.budget.repository.BudgetApplicationRepository;
import com.inhabas.api.domain.budget.repository.BudgetHistoryRepository;
import com.inhabas.api.domain.file.domain.BoardFile;
import com.inhabas.api.domain.menu.domain.Menu;
import com.inhabas.api.domain.menu.repository.MenuRepository;

Expand Down Expand Up @@ -53,9 +58,27 @@ public void process(

case COMPLETED:
application.complete(secretary);
historyRepository.save(application.makeHistory(secretary, menu)); // application to history
applicationRepository.save(application);

// application to history
transformToHistory(application, secretary, menu);
break;
}
}

private void transformToHistory(
BudgetSupportApplication application, Member secretary, Menu menu) {
BudgetHistory transformedHistory =
historyRepository.save(application.makeHistory(secretary, menu));

// application 에 있던 file 들을 history 에 복사
List<BoardFile> files = application.getFiles();
List<BoardFile> copiedFiles = new ArrayList<>();
for (BoardFile file : files) {
BoardFile copiedFile = file.copyFileWithNewId();
copiedFiles.add(copiedFile);
copiedFile.toBoard(transformedHistory);
}

transformedHistory.updateFiles(copiedFiles);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.inhabas.api.auth.domain.error.businessException.InvalidInputException;
import com.inhabas.api.auth.domain.oauth2.member.domain.entity.Member;
import com.inhabas.api.domain.board.domain.BaseBoard;
import com.inhabas.api.global.util.FileUtil;

@Entity
@Getter
Expand All @@ -34,8 +35,6 @@ public class BoardFile extends BaseFile {
public BoardFile(String id, String name, String url, Member uploader, Long size, String type) {
super(id, name, url, size, type);
this.uploader = uploader;
this.size = size;
this.type = type;
}

// boardFile 과 baseBoard 의 연관관계 편의 메소드
Expand All @@ -47,6 +46,17 @@ public <T extends BaseBoard> void toBoard(T newParentBoard) {
}
}

public BoardFile copyFileWithNewId() {
return BoardFile.builder()
.id(FileUtil.generateUUID())
.name(this.name.getValue())
.url(this.url.getValue())
.size(this.size)
.type(this.type)
.uploader(this.uploader)
.build();
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.Optional;

import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.transaction.annotation.Transactional;

import com.inhabas.api.auth.domain.error.ErrorCode;
import com.inhabas.api.auth.domain.error.businessException.InvalidInputException;
Expand Down Expand Up @@ -84,6 +85,7 @@ public void setUp() {
}

@DisplayName("대기중인 요청을 승인한다.")
@Transactional
@Test
public void waitingToApproveTest() {
// given
Expand All @@ -100,6 +102,7 @@ public void waitingToApproveTest() {
}

@DisplayName("대기중인 요청을 거절한다.")
@Transactional
@Test
public void waitingToDenyTest() {
// given
Expand All @@ -116,6 +119,7 @@ public void waitingToDenyTest() {
}

@DisplayName("대기중인 요청을 거절할 때, 거절 사유는 필수이다.")
@Transactional
@Test
public void rejectReasonIsNecessaryToDenyTest() {
// given
Expand All @@ -129,6 +133,7 @@ public void rejectReasonIsNecessaryToDenyTest() {
}

@DisplayName("대기중인 요청을 완료처리한다.")
@Transactional
@Test
public void waitingToProcessTest() {
// given
Expand All @@ -142,7 +147,19 @@ public void waitingToProcessTest() {
APPLICATION_OUTCOME,
applicant,
RequestStatus.APPROVED);
BudgetHistory history =
new BudgetHistory(
"title",
menu,
"datails",
LocalDateTime.now().minusDays(1),
secretary,
ACCOUNT_NUMBER,
0,
APPLICATION_OUTCOME,
applicant);
given(applicationRepository.findById(any())).willReturn(Optional.of(application));
given(historyRepository.save(any())).willReturn(history);
BudgetApplicationStatusChangeRequest request =
new BudgetApplicationStatusChangeRequest(RequestStatus.COMPLETED, null);

Expand All @@ -157,6 +174,7 @@ public void waitingToProcessTest() {
}

@DisplayName("거절했던 신청은 되돌리지 못한다.")
@Transactional
@Test
public void deniedToProcessTest() {
// given
Expand Down

0 comments on commit 9445c9d

Please sign in to comment.