Skip to content

Commit

Permalink
refactor: position Coord 용어 position으로 통일 개
Browse files Browse the repository at this point in the history
  • Loading branch information
Libienz committed Sep 25, 2024
1 parent 6988a59 commit 701da83
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Embeddable
public class GeographicalCoordinate {
public class Position {

private static final String LATITUDE_REGEX = "^([-+]?([1-8]?\\d(\\.\\d+)?|90(\\.0+)?))$";
private static final String LONGITUDE_REGEX = "^([-+]?((1[0-7]\\d(\\.\\d+)?|180(\\.0+)?)|([1-9]?\\d(\\.\\d+)?)))$";
Expand All @@ -25,7 +25,7 @@ public class GeographicalCoordinate {
@Column(nullable = false)
private String longitude;

public GeographicalCoordinate(String latitude, String longitude) {
public Position(String latitude, String longitude) {
validate(latitude, longitude);
this.latitude = latitude;
this.longitude = longitude;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import jakarta.persistence.OneToMany;
import java.util.ArrayList;
import java.util.List;
import kr.touroot.coordinate.domain.GeographicalCoordinate;
import kr.touroot.coordinate.domain.Position;
import kr.touroot.global.entity.BaseEntity;
import kr.touroot.global.exception.BadRequestException;
import lombok.AccessLevel;
Expand Down Expand Up @@ -48,7 +48,7 @@ public class TraveloguePlace extends BaseEntity {
private String name;

@Embedded
private GeographicalCoordinate coordinate;
private Position position;

@JoinColumn(nullable = false)
@ManyToOne(fetch = FetchType.LAZY)
Expand All @@ -62,15 +62,15 @@ public TraveloguePlace(
Integer order,
String description,
String name,
GeographicalCoordinate coordinate,
Position position,
TravelogueDay travelogueDay
) {
validate(order, description, name, coordinate, travelogueDay);
validate(order, description, name, position, travelogueDay);
this.id = id;
this.order = order;
this.description = description;
this.name = name;
this.coordinate = coordinate;
this.position = position;
this.travelogueDay = travelogueDay;
}

Expand All @@ -82,14 +82,14 @@ public TraveloguePlace(
String longitude,
TravelogueDay travelogueDay
) {
this(null, order, description, name, new GeographicalCoordinate(latitude, longitude), travelogueDay);
this(null, order, description, name, new Position(latitude, longitude), travelogueDay);
}

private void validate(
Integer order,
String description,
String name,
GeographicalCoordinate coordinate,
Position coordinate,
TravelogueDay travelogueDay
) {
validateNotNull(order, name, coordinate, travelogueDay);
Expand All @@ -99,7 +99,7 @@ private void validate(
validatePlaceNameLength(name);
}

private void validateNotNull(Integer order, String name, GeographicalCoordinate coordinate, TravelogueDay day) {
private void validateNotNull(Integer order, String name, Position coordinate, TravelogueDay day) {
if (order == null || name == null || coordinate == null || day == null) {
throw new BadRequestException("여행기 장소에서 순서와 장소 위치, 그리고 방문 날짜는 비어 있을 수 없습니다");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static TraveloguePlaceResponse of(TraveloguePlace place, List<String> pho
.id(place.getId())
.placeName(place.getName())
.description(place.getDescription())
.position(TraveloguePositionResponse.from(place.getCoordinate()))
.position(TraveloguePositionResponse.from(place.getPosition()))
.photoUrls(photoUrls)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package kr.touroot.travelogue.dto.response;

import io.swagger.v3.oas.annotations.media.Schema;
import kr.touroot.coordinate.domain.GeographicalCoordinate;
import kr.touroot.coordinate.domain.Position;
import lombok.Builder;

@Builder
Expand All @@ -12,10 +12,10 @@ public record TraveloguePositionResponse(
String lng
) {

public static TraveloguePositionResponse from(GeographicalCoordinate coordinate) {
public static TraveloguePositionResponse from(Position position) {
return TraveloguePositionResponse.builder()
.lat(coordinate.getLatitude())
.lng(coordinate.getLongitude())
.lat(position.getLatitude())
.lng(position.getLongitude())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import jakarta.persistence.OneToMany;
import java.util.ArrayList;
import java.util.List;
import kr.touroot.coordinate.domain.GeographicalCoordinate;
import kr.touroot.coordinate.domain.Position;
import kr.touroot.global.entity.BaseEntity;
import kr.touroot.global.exception.BadRequestException;
import lombok.AccessLevel;
Expand Down Expand Up @@ -47,33 +47,33 @@ public class TravelPlanPlace extends BaseEntity {
private String name;

@Embedded
private GeographicalCoordinate coordinate;
private Position position;

@OneToMany(mappedBy = "travelPlanPlace", cascade = CascadeType.ALL, orphanRemoval = true)
private List<TravelPlaceTodo> travelPlaceTodos = new ArrayList<>();

public TravelPlanPlace(Long id, Integer order, TravelPlanDay day, String name, GeographicalCoordinate coordinate) {
validate(order, day, name, coordinate);
public TravelPlanPlace(Long id, Integer order, TravelPlanDay day, String name, Position position) {
validate(order, day, name, position);
this.id = id;
this.order = order;
this.day = day;
this.name = name;
this.coordinate = coordinate;
this.position = position;
}

public TravelPlanPlace(Integer order, TravelPlanDay day, String name, String latitude, String longitude) {
this(null, order, day, name, new GeographicalCoordinate(latitude, longitude));
this(null, order, day, name, new Position(latitude, longitude));
}


private void validate(Integer order, TravelPlanDay day, String name, GeographicalCoordinate coordinate) {
private void validate(Integer order, TravelPlanDay day, String name, Position coordinate) {
validateNotNull(order, day, name, coordinate);
validateNotBlank(name);
validateOrderRange(order);
validatePlaceNameLength(name);
}

private void validateNotNull(Integer order, TravelPlanDay day, String name, GeographicalCoordinate coordinate) {
private void validateNotNull(Integer order, TravelPlanDay day, String name, Position coordinate) {
if (order == null || day == null || name == null || coordinate == null) {
throw new BadRequestException("여행 계획 장소에서 순서와 날짜, 그리고 장소 위치는 비어 있을 수 없습니다");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static PlanPlaceResponse of(TravelPlanPlace planPlace, List<PlanPlaceTodo
return PlanPlaceResponse.builder()
.id(planPlace.getId())
.placeName(planPlace.getName())
.position(PlanPositionResponse.from(planPlace.getCoordinate()))
.position(PlanPositionResponse.from(planPlace.getPosition()))
.todos(todos)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package kr.touroot.travelplan.dto.response;

import io.swagger.v3.oas.annotations.media.Schema;
import kr.touroot.coordinate.domain.GeographicalCoordinate;
import kr.touroot.coordinate.domain.Position;
import lombok.Builder;

@Builder
Expand All @@ -11,10 +11,10 @@ public record PlanPositionResponse(
@Schema(description = "여행 계획 경도", example = "127.0867236") String lng
) {

public static PlanPositionResponse from(GeographicalCoordinate coordinate) {
public static PlanPositionResponse from(Position position) {
return PlanPositionResponse.builder()
.lat(coordinate.getLatitude())
.lng(coordinate.getLongitude())
.lat(position.getLatitude())
.lng(position.getLongitude())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,30 @@
import org.junit.jupiter.params.provider.ValueSource;

@DisplayName("위도 경도 값타입 테스트")
class GeographicalCoordinateTest {
class PositionTest {

private static final String VALID_LAT = "33.5431";
private static final String VALID_LNG = "126.6728";

@DisplayName("올바른 위경도 값타입 생성 시 예외가 발생하지 않는다")
@Test
void createCoordinateWithValidData() {
assertThatCode(() -> new GeographicalCoordinate(VALID_LAT, VALID_LNG))
assertThatCode(() -> new Position(VALID_LAT, VALID_LNG))
.doesNotThrowAnyException();
}

@DisplayName("위도가 비어 있을 경우 여행 계획 장소 생성 시 예외가 발생한다")
@Test
void createCoordinateWithNullLatitude() {
assertThatThrownBy(() -> new GeographicalCoordinate(null, VALID_LNG))
assertThatThrownBy(() -> new Position(null, VALID_LNG))
.isInstanceOf(BadRequestException.class)
.hasMessage("위도와 경도는 비어있을 수 없습니다");
}

@DisplayName("경도가 비어 있을 경우 여행 계획 장소 생성 시 예외가 발생한다")
@Test
void createCoordinateWithNullLongitude() {
assertThatThrownBy(() -> new GeographicalCoordinate(VALID_LAT, null))
assertThatThrownBy(() -> new Position(VALID_LAT, null))
.isInstanceOf(BadRequestException.class)
.hasMessage("위도와 경도는 비어있을 수 없습니다");
}
Expand All @@ -42,7 +42,7 @@ void createCoordinateWithNullLongitude() {
@ParameterizedTest
@ValueSource(strings = {"", " ", " "})
void createCoordinateWithBlankLatitude(String blank) {
assertThatThrownBy(() -> new GeographicalCoordinate(blank, VALID_LNG))
assertThatThrownBy(() -> new Position(blank, VALID_LNG))
.isInstanceOf(BadRequestException.class)
.hasMessage("위도와 경도는 공백 문자로만 이루어질 수 없습니다");
}
Expand All @@ -51,7 +51,7 @@ void createCoordinateWithBlankLatitude(String blank) {
@ParameterizedTest
@ValueSource(strings = {"", " ", " "})
void createCoordinateWithBlankLongitude(String blank) {
assertThatThrownBy(() -> new GeographicalCoordinate(VALID_LAT, blank))
assertThatThrownBy(() -> new Position(VALID_LAT, blank))
.isInstanceOf(BadRequestException.class)
.hasMessage("위도와 경도는 공백 문자로만 이루어질 수 없습니다");
}
Expand All @@ -60,7 +60,7 @@ void createCoordinateWithBlankLongitude(String blank) {
@ParameterizedTest
@ValueSource(strings = {"91.0000", "-91.0000", "100.0000", "-100.0000", "abc", "45.0000.0", "45,0000"})
void createCoordinateWithMalformedLatitude(String malformed) {
assertThatThrownBy(() -> new GeographicalCoordinate(malformed, VALID_LNG))
assertThatThrownBy(() -> new Position(malformed, VALID_LNG))
.isInstanceOf(BadRequestException.class)
.hasMessage("위,경도의 형식이 올바르지 않습니다");
}
Expand All @@ -69,7 +69,7 @@ void createCoordinateWithMalformedLatitude(String malformed) {
@ParameterizedTest
@ValueSource(strings = {"181.0000", "-181.0000", "200.0000", "-200.0000", "abc", "100.0000.0", "100,0000"})
void createCoordinateWithMalformedLongitude(String malformed) {
assertThatThrownBy(() -> new GeographicalCoordinate(VALID_LAT, malformed))
assertThatThrownBy(() -> new Position(VALID_LAT, malformed))
.isInstanceOf(BadRequestException.class)
.hasMessage("위,경도의 형식이 올바르지 않습니다");
}
Expand Down

0 comments on commit 701da83

Please sign in to comment.