Skip to content

Commit

Permalink
Refactor: 운동일지 완료, 공유 시 운동기록과 운동일지가 완료된 상태인지 확인하는 기능 추가
Browse files Browse the repository at this point in the history
- [ ] 운동일지 완료시 모든 운동기록들이 완료된 상태인지 체크
- [ ] 운동일지 공유시 운동일지가 완료된 상태인지 체크
  • Loading branch information
Dongjin113 committed Nov 21, 2023
1 parent 6673004 commit b4bd710
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public enum ErrorCode implements ErrorType {
NOT_FOUND_USER(HttpStatus.NOT_FOUND, "404", "유저를 찾을 수 없습니다"),

//BAD_REQUEST
NOT_COMPLETED_EXERCISE_JOURNAL(HttpStatus.BAD_REQUEST,"400","운동일지가 완료되지 않았습니다"),
NOT_COMPLETED_EXERCISE_HISTORY(HttpStatus.BAD_REQUEST,"400","완료되지 않은 운동기록이 존재합니다"),
ALREADY_FOLLOW_USER(HttpStatus.BAD_REQUEST, "400", "이미 팔로우한 유저입니다"),
ALREADY_EXIST_FEED_COLLECTION(HttpStatus.BAD_REQUEST, "400", "이미 스크랩한 피드 운동일지 게시물입니다"),
ALREADY_SHARED_JOURNAL(HttpStatus.BAD_REQUEST, "400", "이미 공유된 운동일지입니다"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.ogjg.daitgym.common.exception.journal;

import com.ogjg.daitgym.common.exception.CustomException;
import com.ogjg.daitgym.common.exception.ErrorCode;
import com.ogjg.daitgym.common.exception.ErrorData;

public class NotCompletedExerciseHistory extends CustomException {

public NotCompletedExerciseHistory() {
super(ErrorCode.NOT_COMPLETED_EXERCISE_HISTORY);
}

public NotCompletedExerciseHistory(String message) {
super(ErrorCode.NOT_COMPLETED_EXERCISE_HISTORY, message);
}

public NotCompletedExerciseHistory(ErrorData errorData) {
super(ErrorCode.NOT_COMPLETED_EXERCISE_HISTORY, errorData);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.ogjg.daitgym.common.exception.journal;

import com.ogjg.daitgym.common.exception.CustomException;
import com.ogjg.daitgym.common.exception.ErrorCode;
import com.ogjg.daitgym.common.exception.ErrorData;

public class NotCompletedExerciseJournal extends CustomException {

public NotCompletedExerciseJournal() {
super(ErrorCode.NOT_COMPLETED_EXERCISE_JOURNAL);
}

public NotCompletedExerciseJournal(String message) {
super(ErrorCode.NOT_COMPLETED_EXERCISE_JOURNAL, message);
}

public NotCompletedExerciseJournal(ErrorData errorData) {
super(ErrorCode.NOT_COMPLETED_EXERCISE_JOURNAL, errorData);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

import com.ogjg.daitgym.comment.feedExerciseJournal.exception.NotFoundExerciseJournal;
import com.ogjg.daitgym.comment.feedExerciseJournal.exception.NotFoundUser;
import com.ogjg.daitgym.common.exception.journal.NotFoundExerciseHistory;
import com.ogjg.daitgym.common.exception.journal.NotFoundExerciseList;
import com.ogjg.daitgym.common.exception.journal.NotFoundJournal;
import com.ogjg.daitgym.common.exception.journal.UserNotAuthorizedForJournal;
import com.ogjg.daitgym.common.exception.journal.*;
import com.ogjg.daitgym.domain.User;
import com.ogjg.daitgym.domain.exercise.Exercise;
import com.ogjg.daitgym.domain.journal.ExerciseHistory;
Expand Down Expand Up @@ -120,6 +117,26 @@ public boolean checkForExistJournalSameDate(
.isPresent();
}

/**
* 운동일지의 운동기록들이 모두 완료된 상태인지 확인
*
* @param exerciseJournal 확인할 운동일지
*/
public void checkAllExerciseHistoriesCompleted(
ExerciseJournal exerciseJournal
) {
List<ExerciseList> exerciseLists = findExerciseListsByJournal(exerciseJournal);
exerciseLists.forEach(
exerciseList -> {
findExerciseHistoriesByExerciseList(exerciseList).forEach(
exerciseHistory -> {
if (!exerciseHistory.isCompleted()) throw new NotCompletedExerciseHistory();
}
);
}
);
}

/**
* todo
* 이메일로 유저 검색
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.ogjg.daitgym.common.exception.feed.AlreadyExistFeedJournal;
import com.ogjg.daitgym.common.exception.journal.AlreadyExistExerciseJournal;
import com.ogjg.daitgym.common.exception.journal.NotCompletedExerciseJournal;
import com.ogjg.daitgym.domain.User;
import com.ogjg.daitgym.domain.feed.FeedExerciseJournal;
import com.ogjg.daitgym.domain.journal.ExerciseHistory;
Expand All @@ -18,7 +19,6 @@
import com.ogjg.daitgym.journal.repository.exercisehistory.ExerciseHistoryRepository;
import com.ogjg.daitgym.journal.repository.exerciselist.ExerciseListRepository;
import com.ogjg.daitgym.journal.repository.journal.ExerciseJournalRepository;
import com.ogjg.daitgym.routine.repository.RoutineRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -83,6 +83,7 @@ public void exerciseJournalComplete(
) {
exerciseJournalHelper.isAuthorizedForJournal(email, journalId);
ExerciseJournal exerciseJournal = exerciseJournalHelper.findExerciseJournalById(journalId);
exerciseJournalHelper.checkAllExerciseHistoriesCompleted(exerciseJournal);
exerciseJournal.journalComplete(exerciseJournalCompleteRequest);
}

Expand All @@ -99,9 +100,11 @@ public void exerciseJournalShare(
) {
ExerciseJournal exerciseJournal = exerciseJournalHelper.isAuthorizedForJournal(email, journalId);

if (feedJournalHelper.checkExistFeedExerciseJournalByExerciseJournal(exerciseJournal)) {
if (!exerciseJournal.isCompleted())
throw new NotCompletedExerciseJournal();

if (feedJournalHelper.checkExistFeedExerciseJournalByExerciseJournal(exerciseJournal))
throw new AlreadyExistFeedJournal();
}

exerciseJournal.journalShareToFeed(exerciseJournalShareRequest);

Expand Down Expand Up @@ -211,10 +214,10 @@ public void replicateExerciseJournalFromRoutine(
) {
replicationRoutineRequest.getRoutines()
.forEach(replicationRoutineRequestDto -> {
ExerciseJournal replicatedUserJournal = createJournal(email, replicationRoutineRequestDto.getJournalDate());
exerciseJournalHelper.replicateExerciseListAndHistoryByRoutine(replicatedUserJournal, replicationRoutineRequestDto);
}
);
ExerciseJournal replicatedUserJournal = createJournal(email, replicationRoutineRequestDto.getJournalDate());
exerciseJournalHelper.replicateExerciseListAndHistoryByRoutine(replicatedUserJournal, replicationRoutineRequestDto);
}
);
}

/**
Expand Down

0 comments on commit b4bd710

Please sign in to comment.