Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat #73 post,notice, receipt 파일 업로드 수정 #73

Merged
merged 42 commits into from
Nov 24, 2024
Merged
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
ce21481
refactor: requestPart로 multipart file을 받던 것을 제거
hyxklee Nov 16, 2024
387d567
refactor: currentUser 커스텀 어노테이션에서 인증 정보가 없는 경우 예외 던지기
hyxklee Nov 16, 2024
f4602da
refactor: notice, post 업데이트 시 fileUrl을 받지 않도록 수정
hyxklee Nov 16, 2024
b25b454
refactor: notice, post 객체 생성시 fileUrls를 받지 않도록 수정
hyxklee Nov 16, 2024
17064ce
refactor: notice, post 객체 생성, 수정 요청에 file 관련 dto 추가
hyxklee Nov 16, 2024
abb03ce
refactor: 트랜잭션을 상위에서 걸도록 수정
hyxklee Nov 16, 2024
0565845
refactor: 트랜잭션 제거 및 fileUrls를 받지 않도록 수정
hyxklee Nov 16, 2024
627faf4
refactor: 트랜잭션 제거
hyxklee Nov 16, 2024
3d93b2f
refactor: 게시글 생성, 수정 로직 구현
hyxklee Nov 16, 2024
1007d71
refactor: file 수정 책임을 이전
hyxklee Nov 16, 2024
cd7aac1
refactor: 예외 던지기 수정
hyxklee Nov 16, 2024
a97b8ce
refactor: file을 postId로 가져오던 것 수정
hyxklee Nov 16, 2024
b6f1ce3
refactor: 트랜잭션 상위로 이전
hyxklee Nov 16, 2024
afe72ca
refactor: 공지 생성, 수정 로직 구현
hyxklee Nov 16, 2024
e10c6b7
refactor: 오류 수정
hyxklee Nov 16, 2024
5166121
refactor: 사용하지 않는 컬럼 제거
hyxklee Nov 16, 2024
67112e0
feat: 공지사항 상세 조회 시 file 관련 정보도 함께 반환
hyxklee Nov 16, 2024
d0e61eb
refactor: fileId 수동 매핑 추가
hyxklee Nov 16, 2024
725de71
feat: post 상세조회시 file 조회 로직 추가
hyxklee Nov 16, 2024
315c0ca
feat: 스웨거 API 응답 속도 반환 설정
hyxklee Nov 16, 2024
9ed431b
feat: file delete service 구현
hyxklee Nov 16, 2024
fc7dfbf
feat: 공지사항, 게시글 삭제 시 file도 삭제
hyxklee Nov 16, 2024
98a1d66
refactor: 예외 던지기 수정
hyxklee Nov 16, 2024
6c14dad
feat: File 관련 요청 시 유효성 검증 옵션 추가
hyxklee Nov 17, 2024
050c756
feat: File에 영수증 추가
hyxklee Nov 17, 2024
da1e53f
feat: 영수증 id로 file을 가져오는 명령어 추가
hyxklee Nov 17, 2024
27aaa88
feat: 파일 관련 옵션에 유효성 검증 옵션 추가
hyxklee Nov 17, 2024
7b256c8
refactor: dto명 오류 수정
hyxklee Nov 17, 2024
eab4ef5
feat: 파일 저장시 File 객체 관련 책임을 mapper로 이전
hyxklee Nov 17, 2024
ab1e918
refactor: 파일 저장시 File 객체 관련 책임을 mapper로 이전
hyxklee Nov 17, 2024
27559ea
refactor: 영수증 생성, 삭제시 파일 관련 로직 추가
hyxklee Nov 17, 2024
6b71a7b
refactor: 영수증 생성시 멀티파트 파일 제거
hyxklee Nov 17, 2024
abe9ebd
refactor: 회비 조회시 영수증에 파일 함께 반환
hyxklee Nov 17, 2024
c5540f3
Merge branch 'refs/heads/develop' into feat/#70/post,notice-파일-업로드-수정
hyxklee Nov 19, 2024
572fb2d
refactor: 기존 dto 변수명과 통일
hyxklee Nov 19, 2024
77f2850
refactor: 기존 dto 변수명과 통일
hyxklee Nov 19, 2024
b19abcf
refactor: dto 변수명 통일
hyxklee Nov 19, 2024
7c4b654
refactor: dto 유효성 검사 추가
hyxklee Nov 19, 2024
4f46cf3
refactor: dto 유효성 검사 수정
hyxklee Nov 20, 2024
d4a5f61
refactor: 게시글(file) 업데이트 로직 수정
hyxklee Nov 21, 2024
1feab24
refactor: 공지사항 수정 로직 변경
hyxklee Nov 22, 2024
e600e46
refactor: 메서드 명 수정
hyxklee Nov 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package leets.weeth.domain.account.application.dto;

import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import leets.weeth.domain.file.application.dto.request.FileSaveRequest;
import leets.weeth.domain.file.application.dto.response.FileResponse;

import java.time.LocalDate;
import java.util.List;
Expand All @@ -12,13 +15,14 @@ public record Response(
String description,
Integer amount,
LocalDate date,
List<String> images
List<FileResponse> fileUrls
) {}

public record Save(
String description,
@NotNull Integer amount,
@NotNull LocalDate date,
@NotNull Integer cardinal
@NotNull Integer cardinal,
@Valid List<@NotNull FileSaveRequest> files
) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import leets.weeth.domain.account.application.dto.ReceiptDTO;
import leets.weeth.domain.account.domain.entity.Account;
import leets.weeth.domain.account.domain.entity.Receipt;
import leets.weeth.domain.file.application.dto.response.FileResponse;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingConstants;
Expand All @@ -15,8 +16,10 @@ public interface ReceiptMapper {

List<ReceiptDTO.Response> to(List<Receipt> account);

ReceiptDTO.Response to(Receipt receipt, List<FileResponse> fileUrls);

@Mapping(target = "id", ignore = true)
@Mapping(target = "description", source = "dto.description")
@Mapping(target = "account", source = "account")
Receipt from(ReceiptDTO.Save dto, List<String> images, Account account);
Receipt from(ReceiptDTO.Save dto, Account account);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@

import leets.weeth.domain.account.application.dto.AccountDTO;
import leets.weeth.domain.account.application.dto.ReceiptDTO;
import leets.weeth.domain.account.application.exception.AccountExistsException;
import leets.weeth.domain.account.application.mapper.AccountMapper;
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.AccountSaveService;
import leets.weeth.domain.account.application.exception.AccountExistsException;
import leets.weeth.domain.file.application.dto.response.FileResponse;
import leets.weeth.domain.file.application.mapper.FileMapper;
import leets.weeth.domain.file.domain.service.FileGetService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

Expand All @@ -19,14 +23,20 @@ public class AccountUseCaseImpl implements AccountUseCase {

private final AccountGetService accountGetService;
private final AccountSaveService accountSaveService;
private final FileGetService fileGetService;
private final AccountMapper accountMapper;
private final ReceiptMapper receiptMapper;
private final FileMapper fileMapper;

@Override
public AccountDTO.Response find(Integer cardinal) {
Account account = accountGetService.find(cardinal);
List<ReceiptDTO.Response> receipts = receiptMapper.to(account.getReceipts());
return accountMapper.to(account, receipts);
List<Receipt> receipts = account.getReceipts();
List<ReceiptDTO.Response> response = receipts.stream()
.map(receipt -> receiptMapper.to(receipt, getFiles(receipt.getId())))
.toList();

return accountMapper.to(account, response);
}

@Override
Expand All @@ -36,7 +46,13 @@ public void save(AccountDTO.Save dto) {
}

private void validate(AccountDTO.Save dto) {
if(accountGetService.validate(dto.cardinal()))
if (accountGetService.validate(dto.cardinal()))
throw new AccountExistsException();
}

private List<FileResponse> getFiles(Long receiptId) {
return fileGetService.findAllByReceipt(receiptId).stream()
.map(fileMapper::toFileResponse)
.toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import java.util.List;

public interface ReceiptUseCase {
void save(ReceiptDTO.Save dto, List<MultipartFile> images);
void save(ReceiptDTO.Save dto);

void delete(Long id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
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.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;
Expand All @@ -20,25 +25,39 @@
@RequiredArgsConstructor
public class ReceiptUseCaseImpl implements ReceiptUseCase {

private final ReceiptGetService receiptGetService;
private final ReceiptDeleteService receiptDeleteService;
private final ReceiptSaveService receiptSaveService;
private final S3Service s3Service;
private final ReceiptMapper mapper;
private final AccountGetService accountGetService;
private final ReceiptGetService receiptGetService;

@Override @Transactional
public void save(ReceiptDTO.Save dto, List<MultipartFile> files) {
List<String> images = s3Service.uploadFiles(files);
private final FileGetService fileGetService;
private final FileSaveService fileSaveService;
private final FileDeleteService fileDeleteService;

private final ReceiptMapper mapper;
private final FileMapper fileMapper;


@Override
@Transactional
public void save(ReceiptDTO.Save dto) {
Account account = accountGetService.find(dto.cardinal());
Receipt receipt = receiptSaveService.save(mapper.from(dto, images, account));
Receipt receipt = receiptSaveService.save(mapper.from(dto, account));
account.spend(receipt);

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

@Override @Transactional
@Override
@Transactional
public void delete(Long id) {
Receipt receipt = receiptGetService.find(id);
List<File> fileList = fileGetService.findAllByReceipt(id);

receipt.getAccount().cancel(receipt);

fileDeleteService.delete(fileList);
receiptDeleteService.delete(receipt);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ public class ReceiptAdminController {

private final ReceiptUseCase receiptUseCase;

@PostMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
@PostMapping
@Operation(summary="회비 사용 내역 기입")
public CommonResponse<Void> save(@RequestPart @Valid ReceiptDTO.Save dto, @RequestPart(required = false) List<MultipartFile> images) {
receiptUseCase.save(dto, images);
public CommonResponse<Void> save(@RequestBody @Valid ReceiptDTO.Save dto) {
receiptUseCase.save(dto);
return CommonResponse.createSuccess(RECEIPT_SAVE_SUCCESS.getMessage());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package leets.weeth.domain.board.application.dto;

import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import leets.weeth.domain.comment.application.dto.CommentDTO;
import leets.weeth.domain.file.application.dto.request.FileSaveRequest;
import leets.weeth.domain.file.application.dto.request.FileUpdateRequest;
import leets.weeth.domain.file.application.dto.response.FileResponse;
import lombok.Builder;

import java.time.LocalDateTime;
Expand All @@ -12,14 +16,18 @@ public class NoticeDTO {
@Builder
public record Save(
@NotNull String title,
@NotNull String content
){}
@NotNull String content,
@Valid List<@NotNull FileSaveRequest> files
) {
}

@Builder
public record Update(
@NotNull String title,
@NotNull String content
){}
@NotNull String content,
@Valid List<@NotNull FileUpdateRequest> files
) {
}

@Builder
public record Response(
Expand All @@ -29,9 +37,10 @@ public record Response(
String content,
LocalDateTime time,//modifiedAt
Integer commentCount,
List<String> fileUrls,
List<CommentDTO.Response> comments
){}
List<CommentDTO.Response> comments,
List<FileResponse> fileUrls
) {
}

@Builder
public record ResponseAll(
Expand All @@ -41,6 +50,7 @@ public record ResponseAll(
String content,
LocalDateTime time,//modifiedAt
Integer commentCount
){}
) {
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package leets.weeth.domain.board.application.dto;

import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import leets.weeth.domain.comment.application.dto.CommentDTO;
import leets.weeth.domain.file.application.dto.request.FileSaveRequest;
import leets.weeth.domain.file.application.dto.request.FileUpdateRequest;
import leets.weeth.domain.file.application.dto.response.FileResponse;
import lombok.Builder;

import java.time.LocalDateTime;
Expand All @@ -12,13 +16,15 @@ public class PostDTO {
@Builder
public record Save(
@NotNull String title,
@NotNull String content
@NotNull String content,
@Valid List<@NotNull FileSaveRequest> files
){}

@Builder
public record Update(
@NotNull String title,
@NotNull String content
@NotNull String content,
@Valid List<@NotNull FileUpdateRequest> files
){}

@Builder
Expand All @@ -29,8 +35,8 @@ public record Response(
String content,
LocalDateTime time,//modifiedAt
Integer commentCount,
List<String> fileUrls,
List<CommentDTO.Response> comments
List<CommentDTO.Response> comments,
List<FileResponse> fileUrls
){}

@Builder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import leets.weeth.domain.comment.application.dto.CommentDTO;
import leets.weeth.domain.comment.application.mapper.CommentMapper;
import leets.weeth.domain.comment.domain.entity.Comment;
import leets.weeth.domain.file.application.dto.response.FileResponse;
import leets.weeth.domain.file.domain.entity.File;
import leets.weeth.domain.user.domain.entity.User;
import org.mapstruct.*;

Expand All @@ -19,7 +21,7 @@ public interface NoticeMapper {
@Mapping(target = "id", ignore = true),
@Mapping(target = "user", source = "user")
})
Notice fromNoticeDto(NoticeDTO.Save dto, List<String> fileUrls, User user);
Notice fromNoticeDto(NoticeDTO.Save dto, User user);

@Mappings({
@Mapping(target = "name", source = "user.name"),
Expand All @@ -28,11 +30,11 @@ public interface NoticeMapper {
NoticeDTO.ResponseAll toAll(Notice notice);

@Mappings({
@Mapping(target = "name", source = "user.name"),
@Mapping(target = "name", source = "notice.user.name"),
@Mapping(target = "comments", expression = "java(filterParentComments(notice.getComments()))"),
@Mapping(target = "time", source = "modifiedAt")
@Mapping(target = "time", source = "notice.modifiedAt")
})
NoticeDTO.Response toNoticeDto(Notice notice);
NoticeDTO.Response toNoticeDto(Notice notice, List<FileResponse> fileUrls);

default List<CommentDTO.Response> filterParentComments(List<Comment> comments) {
if (comments == null || comments.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import leets.weeth.domain.comment.application.dto.CommentDTO;
import leets.weeth.domain.comment.application.mapper.CommentMapper;
import leets.weeth.domain.comment.domain.entity.Comment;
import leets.weeth.domain.file.application.dto.response.FileResponse;
import leets.weeth.domain.user.domain.entity.User;
import org.mapstruct.*;

Expand All @@ -19,7 +20,7 @@ public interface PostMapper {
@Mapping(target = "id", ignore = true),
@Mapping(target = "user", source = "user")
})
Post fromPostDto(PostDTO.Save dto, List<String> fileUrls, User user);
Post fromPostDto(PostDTO.Save dto, User user);

@Mappings({
@Mapping(target = "name", source = "user.name"),
Expand All @@ -28,11 +29,11 @@ public interface PostMapper {
PostDTO.ResponseAll toAll(Post post);

@Mappings({
@Mapping(target = "name", source = "user.name"),
@Mapping(target = "name", source = "post.user.name"),
@Mapping(target = "comments", expression = "java(filterParentComments(post.getComments()))"),
@Mapping(target = "time", source = "modifiedAt")
@Mapping(target = "time", source = "post.modifiedAt")
})
PostDTO.Response toPostDto(Post post);
PostDTO.Response toPostDto(Post post, List<FileResponse> fileUrls);

default List<CommentDTO.Response> filterParentComments(List<Comment> comments) {
if (comments == null || comments.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@

public interface NoticeUsecase {

void save(NoticeDTO.Save dto, List<MultipartFile> files, Long userId);
void save(NoticeDTO.Save dto, Long userId);

NoticeDTO.Response findNotice(Long noticeId);

List<NoticeDTO.ResponseAll> findNotices(Long noticeId, Integer count);

void update(Long noticeId, NoticeDTO.Update dto, List<MultipartFile> files, Long userId) throws UserNotMatchException;
void update(Long noticeId, NoticeDTO.Update dto, Long userId) throws UserNotMatchException;

void delete(Long noticeId, Long userId) throws UserNotMatchException;

Expand Down
Loading
Loading