Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Expand Up @@ -54,6 +54,7 @@ public enum ErrorStatus {
* 403 FORBIDDEN
*/
PERMISSION_DENIED_PUBLIC_COURSE_DELETE_EXCEPTION(HttpStatus.FORBIDDEN, "퍼블릭 코스를 삭제할 권한이 존재하지 않습니다."),
PERMISSION_DENIED_PUBLIC_COURSE_UPDATE_EXCEPTION(HttpStatus.FORBIDDEN, "퍼블릭 코스를 수정할 권한이 존재하지 않습니다."),
PERMISSION_DENIED_RECORD_DELETE_EXCEPTION(HttpStatus.FORBIDDEN, "기록을 삭제할 권한이 존재하지 않습니다."),
PERMISSION_DENIED_RECORD_UPDATE_EXCEPTION(HttpStatus.FORBIDDEN, "기록을 수정할 권한이 존재하지 않습니다."),
PERMISSION_DENIED_HEALTH_DATA_EXCEPTION(HttpStatus.FORBIDDEN, "건강 데이터에 대한 접근 권한이 없습니다"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,23 @@ public void updatePublicCourse(String title, String description) {
public void updateDeletedAt() {
throw new RuntimeException("Course를 제외한 테이블은 정상적으로 삭제됩니다.");
}

// RunnectUser와 동일한 이유(참조 동일성 의존 방지)로 id 기준 equals/hashCode를 둔다.
// scrap 목록과 publicCourse 목록을 서로 다른 쿼리로 가져와 비교하는 곳(isScrap 매칭)이 많아서 영향이 크다.
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof PublicCourse)) {
return false;
}
PublicCourse that = (PublicCourse) o;
return id != null && id.equals(that.id);
}

@Override
public int hashCode() {
return getClass().hashCode();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import lombok.RequiredArgsConstructor;
import org.runnect.server.common.constant.ErrorStatus;
import org.runnect.server.common.constant.SortStatus;
import org.runnect.server.common.exception.BadRequestException;
import org.runnect.server.common.exception.ConflictException;
import org.runnect.server.common.exception.NotFoundException;
import org.runnect.server.common.exception.PermissionDeniedException;
Expand Down Expand Up @@ -181,6 +182,9 @@ public RecommendPublicCourseResponseDto recommendPublicCourse(Long userId, Integ
publicCourses = publicCourseRepository.findAll(
PageRequest.of(pageNo - 1, PAGE_SIZE,
Sort.by(Sort.Direction.DESC, SortStatus.DATE_DESC.getProperty())));
} else {
throw new BadRequestException(ErrorStatus.INVALID_SORT_PARAMETER_EXCEPTION,
ErrorStatus.INVALID_SORT_PARAMETER_EXCEPTION.getMessage());
}

publicCourses.forEach(publicCourse -> {
Expand Down Expand Up @@ -263,8 +267,8 @@ public GetPublicCourseDetailResponseDto getPublicCourseDetail(final Long userId,
Course course = publicCourse.getCourse();

//2. 이미 삭제된 코스인지
if (course.getDeletedAt() == null) {
new NotFoundException(ErrorStatus.NOT_FOUND_PUBLIC_COURSE_EXCEPTION,
if (course.getDeletedAt() != null) {
throw new NotFoundException(ErrorStatus.NOT_FOUND_PUBLIC_COURSE_EXCEPTION,
ErrorStatus.NOT_FOUND_PUBLIC_COURSE_EXCEPTION.getMessage());
}

Expand Down Expand Up @@ -394,6 +398,12 @@ public UpdatePublicCourseResponseDto updatePublicCourse(Long userId, Long public
PublicCourse publicCourse = publicCourseRepository.findById(publicCourseId)
.orElseThrow(() -> new NotFoundException(ErrorStatus.NOT_FOUND_PUBLIC_COURSE_EXCEPTION, ErrorStatus.NOT_FOUND_PUBLIC_COURSE_EXCEPTION.getMessage()));

boolean isAdmin = userId.equals(ADMIN_USER_ID);
if (!isAdmin && !publicCourse.getCourse().getRunnectUser().getId().equals(userId)) {
throw new PermissionDeniedException(ErrorStatus.PERMISSION_DENIED_PUBLIC_COURSE_UPDATE_EXCEPTION,
ErrorStatus.PERMISSION_DENIED_PUBLIC_COURSE_UPDATE_EXCEPTION.getMessage());
}

publicCourse.updatePublicCourse(title, description);

return UpdatePublicCourseResponseDto.of(publicCourse);
Expand Down
Loading
Loading