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 @@ -34,6 +34,7 @@ public enum ErrorStatus {
INVALID_HEALTH_DATA_EXCEPTION(HttpStatus.BAD_REQUEST, "유효하지 않은 건강 데이터입니다"),
INVALID_DATE_RANGE_EXCEPTION(HttpStatus.BAD_REQUEST, "유효하지 않은 날짜 범위입니다"),
EXCEED_HEART_RATE_SAMPLES_EXCEPTION(HttpStatus.BAD_REQUEST, "심박수 샘플은 최대 5000건까지 허용됩니다"),
VALIDATION_DEPARTURE_ADDRESS_EXCEPTION(HttpStatus.BAD_REQUEST, "출발지 주소 형식이 올바르지 않습니다."),

/**
* 401 UNAUTHORIZED
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package org.runnect.server.common.module.convert;

import org.runnect.server.common.constant.ErrorStatus;
import org.runnect.server.common.dto.DepartureResponse;
import org.runnect.server.common.exception.BadRequestException;

import java.util.Arrays;

public class DepartureConverter {
public static DepartureResponse requestConvertDeparture(String departureAddress, String departureName) {
String[] departures = departureAddress.split(" ");
if (departures.length < 3) {
return null;
throw new BadRequestException(ErrorStatus.VALIDATION_DEPARTURE_ADDRESS_EXCEPTION,
ErrorStatus.VALIDATION_DEPARTURE_ADDRESS_EXCEPTION.getMessage());
} else if (departures.length == 3) {
return new DepartureResponse(
departures[0],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public GetCourseDetailResponseDto getCourseDetail(Long courseId, Long userId) {

@Transactional
public UpdateCourseResponseDto updateCourse(Long userId, Long courseId, String title) {
Course course = courseRepository.findById(courseId)
Course course = courseRepository.findByCourseIdAndUserId(courseId, userId)
.orElseThrow(()->new NotFoundException(NOT_FOUND_COURSE_EXCEPTION, NOT_FOUND_COURSE_EXCEPTION.getMessage()));

course.updateCourse(title);
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/org/runnect/server/user/entity/RunnectUser.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,24 @@ public void updateCreatedPublicCourse() {
public void updateDeletedAt() {
throw new RuntimeException("Course를 제외한 테이블은 정상적으로 삭제됩니다.");
}

// 기본 equals(참조 비교)에 의존하면, 같은 유저를 서로 다른 조회 경로로 가져왔을 때
// (예: 로그인 유저 vs 코스에 매핑된 유저) 같은 사람인데도 다르다고 판정될 수 있다.
// id 기준으로 비교하고, hashCode는 영속화 전후로 값이 바뀌지 않도록 상수로 고정한다.
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof RunnectUser)) {
return false;
}
RunnectUser that = (RunnectUser) o;
return id != null && id.equals(that.id);
}

@Override
public int hashCode() {
return getClass().hashCode();
}
}
Loading
Loading