Skip to content

Commit

Permalink
refactor(ActivityGroupBoardService): 활동 게시판 카테고리별 유효성 검사 함수화 #447
Browse files Browse the repository at this point in the history
  • Loading branch information
mingmingmon committed Aug 6, 2024
1 parent 457e004 commit 4f5d6ba
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.time.LocalDateTime;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
Expand All @@ -21,6 +22,7 @@
import page.clab.api.domain.activity.activitygroup.dto.response.AssignmentSubmissionWithFeedbackResponseDto;
import page.clab.api.domain.activity.activitygroup.dto.response.FeedbackResponseDto;
import page.clab.api.domain.activity.activitygroup.exception.AssignmentBoardHasNoDueDateTimeException;
import page.clab.api.domain.activity.activitygroup.exception.FeedbackBoardHasNoContentException;
import page.clab.api.domain.activity.activitygroup.exception.InvalidParentBoardException;
import page.clab.api.domain.memberManagement.member.application.dto.shared.MemberDetailedInfoDto;
import page.clab.api.domain.memberManagement.member.domain.Member;
Expand All @@ -37,6 +39,7 @@

@Service
@RequiredArgsConstructor
@Slf4j
public class ActivityGroupBoardService {

private final ActivityGroupBoardRepository activityGroupBoardRepository;
Expand All @@ -54,14 +57,9 @@ public Long createActivityGroupBoard(Long parentId, Long activityGroupId, Activi
throw new PermissionDeniedException("활동 그룹 멤버만 게시글을 등록할 수 있습니다.");
}

ActivityGroupBoardCategory activityGroupBoardCategory = requestDto.getCategory();
LocalDateTime dueDateTime = requestDto.getDueDateTime();

if (activityGroupBoardCategory == ActivityGroupBoardCategory.ASSIGNMENT && dueDateTime == null) {
throw new AssignmentBoardHasNoDueDateTimeException();
}

validateRequestBody(requestDto);
validateParentBoard(requestDto.getCategory(), parentId);

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

ActivityGroupBoard parentBoard = parentId != null ? getActivityGroupBoardByIdOrThrow(parentId) : null;
Expand Down Expand Up @@ -202,6 +200,20 @@ private void validateParentBoard(ActivityGroupBoardCategory category, Long paren
}
}

private void validateRequestBody(ActivityGroupBoardRequestDto activityGroupBoardRequestDto) {
ActivityGroupBoardCategory activityGroupBoardCategory = activityGroupBoardRequestDto.getCategory();
LocalDateTime dueDateTime = activityGroupBoardRequestDto.getDueDateTime();
String content = activityGroupBoardRequestDto.getContent();

if (activityGroupBoardCategory == ActivityGroupBoardCategory.ASSIGNMENT && dueDateTime == null) {
throw new AssignmentBoardHasNoDueDateTimeException();
}

if (activityGroupBoardCategory == ActivityGroupBoardCategory.FEEDBACK && 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
@@ -0,0 +1,14 @@
package page.clab.api.domain.activity.activitygroup.exception;

public class FeedbackBoardHasNoContentException extends RuntimeException {

private static final String DEFAULT_MESSAGE = "피드백 게시판에 내용이 없습니다.";

public FeedbackBoardHasNoContentException() {
super(DEFAULT_MESSAGE);
}

public FeedbackBoardHasNoContentException(String s) {
super(s);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import page.clab.api.domain.activity.activitygroup.exception.DuplicateAbsentExcuseException;
import page.clab.api.domain.activity.activitygroup.exception.DuplicateAttendanceException;
import page.clab.api.domain.activity.activitygroup.exception.DuplicateReportException;
import page.clab.api.domain.activity.activitygroup.exception.FeedbackBoardHasNoContentException;
import page.clab.api.domain.activity.activitygroup.exception.InvalidCategoryException;
import page.clab.api.domain.activity.activitygroup.exception.InvalidParentBoardException;
import page.clab.api.domain.activity.activitygroup.exception.LeaderStatusChangeNotAllowedException;
Expand Down Expand Up @@ -100,7 +101,8 @@ public class GlobalExceptionHandler {
NumberFormatException.class,
SortingArgumentException.class,
UnknownPathException.class,
AssignmentBoardHasNoDueDateTimeException.class
AssignmentBoardHasNoDueDateTimeException.class,
FeedbackBoardHasNoContentException.class
})
public ErrorResponse<Exception> badRequestException(HttpServletResponse response, Exception e) {
response.setStatus(HttpServletResponse.SC_OK);
Expand Down

0 comments on commit 4f5d6ba

Please sign in to comment.