Skip to content

Commit

Permalink
refactor(ActivityGroupBoard): 카테고리에 따른 필수 요소 검증 로직 도메인 객체로 이동 #447
Browse files Browse the repository at this point in the history
  • Loading branch information
mingmingmon committed Aug 11, 2024
1 parent f1e8a0a commit deee4e3
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,15 @@ public Long createActivityGroupBoard(Long parentId, Long activityGroupId, Activi
if (!activityGroupMemberService.isGroupMember(activityGroup, currentMember.getId())) {
throw new PermissionDeniedException("활동 그룹 멤버만 게시글을 등록할 수 있습니다.");
}
if (requestDto.getCategory() == ActivityGroupBoardCategory.ASSIGNMENT) {
validateDueDateForAssignment(requestDto);
}
if (requestDto.getCategory() == ActivityGroupBoardCategory.FEEDBACK) {
validateContentForFeedback(requestDto);
}

validateParentBoard(requestDto.getCategory(), parentId);

List<UploadedFile> uploadedFiles = uploadedFileService.getUploadedFilesByUrls(requestDto.getFileUrls());

ActivityGroupBoard parentBoard = parentId != null ? getActivityGroupBoardByIdOrThrow(parentId) : null;
ActivityGroupBoard board = ActivityGroupBoardRequestDto.toEntity(requestDto, currentMember, activityGroup, parentBoard, uploadedFiles);
board.validateEssentialElementByCategory();

if (parentId != null) {
parentBoard.addChild(board);
activityGroupBoardRepository.save(parentBoard);
Expand Down Expand Up @@ -220,20 +216,6 @@ private void validateParentBoard(ActivityGroupBoardCategory category, Long paren
}
}

private void validateDueDateForAssignment(ActivityGroupBoardRequestDto activityGroupBoardRequestDto) {
LocalDateTime dueDateTime = activityGroupBoardRequestDto.getDueDateTime();
if (dueDateTime == null) {
throw new AssignmentBoardHasNoDueDateTimeException();
}
}

private void validateContentForFeedback(ActivityGroupBoardRequestDto activityGroupBoardRequestDto) {
String content = activityGroupBoardRequestDto.getContent();
if (content.isEmpty()) {
throw new FeedbackBoardHasNoContentException();
}
}

private void notifyMembersAboutNewBoard(Long activityGroupId, ActivityGroup activityGroup, Member member) {
GroupMember groupMember = activityGroupMemberService.getGroupMemberByActivityGroupAndMemberOrThrow(activityGroup, member.getId());
if (groupMember.isLeader()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
import lombok.Setter;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.SQLRestriction;
import page.clab.api.domain.activity.activitygroup.dto.request.ActivityGroupBoardRequestDto;
import page.clab.api.domain.activity.activitygroup.dto.request.ActivityGroupBoardUpdateRequestDto;
import page.clab.api.domain.activity.activitygroup.exception.AssignmentBoardHasNoDueDateTimeException;
import page.clab.api.domain.activity.activitygroup.exception.FeedbackBoardHasNoContentException;
import page.clab.api.domain.memberManagement.member.domain.Member;
import page.clab.api.global.common.domain.BaseEntity;
import page.clab.api.global.common.file.application.UploadedFileService;
Expand Down Expand Up @@ -115,4 +118,19 @@ public void validateAccessPermission(Member member, GroupMember leader) throws P
}
}
}

public void validateEssentialElementByCategory() {
if (this.isAssignment()) {
LocalDateTime dueDateTime = this.getDueDateTime();
if (dueDateTime == null) {
throw new AssignmentBoardHasNoDueDateTimeException();
}
}
if (this.isFeedback()) {
String content = this.getContent();
if (content.isEmpty()) {
throw new FeedbackBoardHasNoContentException();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import page.clab.api.global.common.dto.ApiResponse;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ public String saveQRCodeImage(byte[] QRCodeImage, String path, long storagePerio
return url;
}

public List<UploadedFileResponseDto> saveFilesTest(MultipartFile[] multipartFiles, String path, long storagePeriod) throws IOException, PermissionDeniedException {
List<UploadedFileResponseDto> uploadedFileResponseDtos = new ArrayList<>();
for (MultipartFile multipartFile : multipartFiles) {
UploadedFileResponseDto responseDto = saveFile(multipartFile, path, storagePeriod);
uploadedFileResponseDtos.add(responseDto);
}
return uploadedFileResponseDtos;
}


public List<UploadedFileResponseDto> saveFiles(List<MultipartFile> multipartFiles, String path, long storagePeriod) throws IOException, PermissionDeniedException {
List<UploadedFileResponseDto> uploadedFileResponseDtos = new ArrayList<>();
for (MultipartFile multipartFile : multipartFiles) {
Expand Down

0 comments on commit deee4e3

Please sign in to comment.