Skip to content

Commit

Permalink
Merge branch 'InhaBas:master' into myinfo
Browse files Browse the repository at this point in the history
  • Loading branch information
skytin1004 authored Mar 22, 2024
2 parents 9f77efe + 91d6cb0 commit 6d94949
Show file tree
Hide file tree
Showing 62 changed files with 2,200 additions and 484 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public GroupedOpenApi getIBASApi() {

return GroupedOpenApi.builder()
.group("IBAS 관련")
.pathsToMatch("/club/**", "/**/**/**/comment/**", "/**/**/**/comments")
.pathsToMatch("/club/**", "/**/**/**/comment/**", "/**/**/**/comments", "/file/upload/**")
.build();
}

Expand All @@ -103,22 +103,26 @@ public GroupedOpenApi getBoardApi() {

return GroupedOpenApi.builder()
.group("게시판 관련")
.pathsToMatch("/board/**", "/**/**/**/comment/**", "/**/**/**/comments")
.pathsToMatch("/board/**", "/**/**/**/comment/**", "/**/**/**/comments", "/file/upload/**")
.build();
}

@Bean
public GroupedOpenApi getBudgetApi() {

return GroupedOpenApi.builder().group("회계 관련").pathsToMatch("/budget/**").build();
return GroupedOpenApi.builder()
.group("회계 관련")
.pathsToMatch("/budget/**", "/file/upload/**")
.build();
}

@Bean
public GroupedOpenApi getProjectBoardApi() {

return GroupedOpenApi.builder()
.group("프로젝트 게시판 관련")
.pathsToMatch("/project/**", "/**/**/**/comment/**", "/**/**/**/comments")
.pathsToMatch(
"/project/**", "/**/**/**/comment/**", "/**/**/**/comments", "/file/upload/**")
.build();
}

Expand All @@ -127,7 +131,18 @@ public GroupedOpenApi getContestApi() {

return GroupedOpenApi.builder()
.group("공모전 게시판 관련")
.pathsToMatch("/contest/**", "/**/**/**/comment/**", "/**/**/**/comments")
.pathsToMatch(
"/contest/**", "/**/**/**/comment/**", "/**/**/**/comments", "/file/upload/**")
.build();
}

@Bean
public GroupedOpenApi getScholarshipApi() {

return GroupedOpenApi.builder()
.group("장학회 관련")
.pathsToMatch(
"/scholarship/**", "/**/**/**/comment/**", "/**/**/**/comments", "/file/upload/**")
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.inhabas.api.web.converter.MenuIdConverter;
import com.inhabas.api.web.converter.NormalBoardTypeConverter;
import com.inhabas.api.web.converter.ProjectBoardTypeConverter;
import com.inhabas.api.web.converter.ScholarshipBoardConverter;
import io.swagger.v3.core.jackson.ModelResolver;

@Configuration
Expand All @@ -26,6 +27,8 @@ public void addFormatters(FormatterRegistry registry) {
registry.addConverter(new ContestTypeConverter.ContestTypeToStringConverter());
registry.addConverter(new NormalBoardTypeConverter.NormalTypeToStringConverter());
registry.addConverter(new NormalBoardTypeConverter.StringToNormalTypeConverter());
registry.addConverter(new ScholarshipBoardConverter.ScholarshipBoardTypeToStringConverter());
registry.addConverter(new ScholarshipBoardConverter.StringToScholarshipTypeConverter());
registry.addConverter(new ProjectBoardTypeConverter.ProjectBoardTypeToStringConverter());
registry.addConverter(new ProjectBoardTypeConverter.StringToProjectBoardTypeConverter());
registry.addConverter(new MenuIdConverter.StringToMenuIdConverter());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.inhabas.api.domain.budget.dto;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
Expand Down Expand Up @@ -37,14 +39,22 @@ public class BudgetApplicationRegisterForm {

@NotBlank private String account;

private List<String> files = new ArrayList<>();

@Builder
public BudgetApplicationRegisterForm(
String title, LocalDateTime dateUsed, String details, Integer outcome, String account) {
String title,
LocalDateTime dateUsed,
String details,
Integer outcome,
String account,
List<String> files) {
this.title = title;
this.dateUsed = dateUsed;
this.details = details;
this.outcome = outcome;
this.account = account;
this.files = files == null ? new ArrayList<>() : files;
}

public BudgetSupportApplication toEntity(Menu menu, Member applicant) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.inhabas.api.domain.budget.dto;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
Expand Down Expand Up @@ -33,13 +35,15 @@ public class BudgetHistoryCreateForm {

@NotBlank private String details;

@NotNull private String memberStudentIdReceived;
private String memberStudentIdReceived;

@NotBlank private String memberNameReceived;
private String memberNameReceived;

@PositiveOrZero @NotNull private Integer income;
@PositiveOrZero private Integer income;

@PositiveOrZero @NotNull private Integer outcome;
@PositiveOrZero private Integer outcome;

@NotNull private List<String> files = new ArrayList<>();

private static final Integer ZERO = 0;

Expand All @@ -51,15 +55,16 @@ public BudgetHistoryCreateForm(
String memberStudentIdReceived,
String memberNameReceived,
Integer income,
Integer outcome) {
Integer outcome,
List<String> files) {
this.dateUsed = dateUsed;
this.title = title;
this.details = details;
this.memberStudentIdReceived = memberStudentIdReceived;
this.memberNameReceived = memberNameReceived;
this.income = income;
this.outcome = outcome;

this.files = files == null ? new ArrayList<>() : files;
if (this.details.isBlank()) {
this.details = this.title;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,16 @@

import java.util.List;

import org.springframework.web.multipart.MultipartFile;

import com.inhabas.api.auth.domain.oauth2.member.domain.valueObject.RequestStatus;
import com.inhabas.api.domain.budget.dto.BudgetApplicationDetailDto;
import com.inhabas.api.domain.budget.dto.BudgetApplicationDto;
import com.inhabas.api.domain.budget.dto.BudgetApplicationRegisterForm;

public interface BudgetApplicationService {

Long registerApplication(
BudgetApplicationRegisterForm form, List<MultipartFile> files, Long memberId);
Long registerApplication(BudgetApplicationRegisterForm form, Long memberId);

void updateApplication(
Long applicationId,
BudgetApplicationRegisterForm form,
List<MultipartFile> files,
Long memberId);
void updateApplication(Long applicationId, BudgetApplicationRegisterForm form, Long memberId);

void deleteApplication(Long applicationId, Long memberId);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,30 @@
package com.inhabas.api.domain.budget.usecase;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import lombok.RequiredArgsConstructor;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import com.inhabas.api.auth.domain.error.businessException.NotFoundException;
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.domain.valueObject.RequestStatus;
import com.inhabas.api.auth.domain.oauth2.member.repository.MemberRepository;
import com.inhabas.api.domain.board.exception.OnlyWriterModifiableException;
import com.inhabas.api.domain.board.exception.S3UploadFailedException;
import com.inhabas.api.domain.budget.domain.BudgetSupportApplication;
import com.inhabas.api.domain.budget.dto.BudgetApplicationDetailDto;
import com.inhabas.api.domain.budget.dto.BudgetApplicationDto;
import com.inhabas.api.domain.budget.dto.BudgetApplicationRegisterForm;
import com.inhabas.api.domain.budget.exception.InProcessModifiableException;
import com.inhabas.api.domain.budget.repository.BudgetApplicationRepository;
import com.inhabas.api.domain.file.domain.BoardFile;
import com.inhabas.api.domain.file.usecase.S3Service;
import com.inhabas.api.domain.file.repository.BoardFileRepository;
import com.inhabas.api.domain.menu.domain.Menu;
import com.inhabas.api.domain.menu.repository.MenuRepository;
import com.inhabas.api.global.util.ClassifiedFiles;
import com.inhabas.api.global.util.ClassifyFiles;
import com.inhabas.api.global.util.FileUtil;

@Service
@RequiredArgsConstructor
Expand All @@ -38,7 +33,7 @@ public class BudgetApplicationServiceImpl implements BudgetApplicationService {
private final BudgetApplicationRepository budgetApplicationRepository;
private final MemberRepository memberRepository;
private final MenuRepository menuRepository;
private final S3Service s3Service;
private final BoardFileRepository boardFileRepository;
private static final Integer BUDGET_APPLICATION_MENU_ID = 14;
private static final String DIR_NAME = "budget/";

Expand Down Expand Up @@ -76,25 +71,30 @@ public BudgetApplicationDetailDto getApplicationDetails(Long applicationId) {

@Transactional
@Override
public Long registerApplication(
BudgetApplicationRegisterForm form, List<MultipartFile> files, Long memberId) {
public Long registerApplication(BudgetApplicationRegisterForm form, Long memberId) {
Member applicant =
memberRepository.findById(memberId).orElseThrow(MemberNotFoundException::new);
Menu menu =
menuRepository.findById(BUDGET_APPLICATION_MENU_ID).orElseThrow(NotFoundException::new);
BudgetSupportApplication application =
form.toEntity(menu, applicant).writtenBy(applicant, BudgetSupportApplication.class);

return updateBudgetFiles(files, application);
List<String> fileIdList = form.getFiles();
List<BoardFile> boardFileList =
boardFileRepository.getAllByIdInAndUploader(fileIdList, applicant);
application.updateFiles(boardFileList);

for (BoardFile file : boardFileList) {
file.toBoard(application);
}
application.updateFiles(boardFileList);
return budgetApplicationRepository.save(application).getId();
}

@Transactional
@Override
public void updateApplication(
Long applicationId,
BudgetApplicationRegisterForm form,
List<MultipartFile> files,
Long memberId) {
Long applicationId, BudgetApplicationRegisterForm form, Long memberId) {
Member applicant =
memberRepository.findById(memberId).orElseThrow(MemberNotFoundException::new);
BudgetSupportApplication application =
Expand All @@ -111,7 +111,14 @@ public void updateApplication(
form.getOutcome(),
form.getAccount());

updateBudgetFiles(files, application);
List<String> fileIdList = form.getFiles();
List<BoardFile> boardFileList =
boardFileRepository.getAllByIdInAndUploader(fileIdList, applicant);
application.updateFiles(boardFileList);

for (BoardFile file : boardFileList) {
file.toBoard(application);
}
}

@Transactional
Expand All @@ -126,37 +133,4 @@ public void deleteApplication(Long applicationId, Long memberId) {

budgetApplicationRepository.deleteById(applicationId);
}

private Long updateBudgetFiles(List<MultipartFile> files, BudgetSupportApplication application) {
List<BoardFile> updateReceipts = new ArrayList<>();
List<String> urlListForDelete = new ArrayList<>();

if (files != null) {
try {
updateReceipts =
files.stream()
.map(
file -> {
String path = FileUtil.generateFileName(file, DIR_NAME);
String url = s3Service.uploadS3Image(file, path);
urlListForDelete.add(url);
return BoardFile.builder()
.name(file.getOriginalFilename())
.url(url)
.board(application)
.build();
})
.collect(Collectors.toList());

} catch (RuntimeException e) {
for (String url : urlListForDelete) {
s3Service.deleteS3File(url);
}
throw new S3UploadFailedException();
}
}

application.updateFiles(updateReceipts);
return budgetApplicationRepository.save(application).getId();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,15 @@

import java.util.List;

import org.springframework.web.multipart.MultipartFile;

import com.inhabas.api.domain.budget.dto.BudgetHistoryCreateForm;
import com.inhabas.api.domain.budget.dto.BudgetHistoryDetailDto;
import com.inhabas.api.domain.budget.dto.BudgetHistoryDto;

public interface BudgetHistoryService {

Long createHistory(BudgetHistoryCreateForm form, List<MultipartFile> files, Long secretaryId);
Long createHistory(BudgetHistoryCreateForm form, Long secretaryId);

void modifyHistory(
Long historyId, BudgetHistoryCreateForm form, List<MultipartFile> files, Long secretaryId);
void modifyHistory(Long historyId, BudgetHistoryCreateForm form, Long secretaryId);

void deleteHistory(Long historyId, Long secretaryId);

Expand Down
Loading

0 comments on commit 6d94949

Please sign in to comment.