-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
940 additions
and
153 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
src/main/java/com/ajou/hertz/common/dto/CoordinateDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.ajou.hertz.common.dto; | ||
|
||
import com.ajou.hertz.common.entity.Coordinate; | ||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
@Getter | ||
public class CoordinateDto { | ||
|
||
private String lat; | ||
private String lng; | ||
|
||
public static CoordinateDto from(Coordinate coordinate) { | ||
return new CoordinateDto(coordinate.getLat(), coordinate.getLng()); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/com/ajou/hertz/common/dto/FullAddressDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.ajou.hertz.common.dto; | ||
|
||
import com.ajou.hertz.common.entity.FullAddress; | ||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
@Getter | ||
public class FullAddressDto { | ||
|
||
private String sido; | ||
private String sgg; | ||
private String lotNumberAddress; | ||
private String roadAddress; | ||
private String detailAddress; | ||
|
||
public static FullAddressDto from(FullAddress fullAddress) { | ||
return new FullAddressDto( | ||
fullAddress.getSido(), | ||
fullAddress.getSgg(), | ||
fullAddress.getLotNumberAddress(), | ||
fullAddress.getRoadAddress(), | ||
fullAddress.getDetailAddress() | ||
); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/com/ajou/hertz/common/dto/request/CoordinateRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.ajou.hertz.common.dto.request; | ||
|
||
import com.ajou.hertz.common.entity.Coordinate; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import jakarta.validation.constraints.NotBlank; | ||
import lombok.*; | ||
|
||
@AllArgsConstructor(access = AccessLevel.PROTECTED) | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Setter | ||
@Getter | ||
public class CoordinateRequest { | ||
|
||
@Schema(description = "위도", example = "37.123456") | ||
@NotBlank | ||
private String lat; | ||
|
||
@Schema(description = "경도", example = "127.123456") | ||
@NotBlank | ||
private String lng; | ||
|
||
|
||
public Coordinate toEntity() { | ||
return new Coordinate(lat, lng); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/com/ajou/hertz/common/dto/request/FullAddressRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.ajou.hertz.common.dto.request; | ||
|
||
import com.ajou.hertz.common.entity.FullAddress; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import jakarta.validation.constraints.NotBlank; | ||
import lombok.*; | ||
|
||
@AllArgsConstructor(access = AccessLevel.PROTECTED) | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Setter | ||
@Getter | ||
public class FullAddressRequest { | ||
|
||
@Schema(description = "전체 주소", example = "서울특별시 강남구 역삼동 123-45") | ||
@NotBlank | ||
private String fullAddress; | ||
|
||
@Schema(description = "상세주소", example = "아주 빌딩 2층") | ||
@NotBlank | ||
private String detailAddress; | ||
|
||
public FullAddress toEntity() { | ||
return FullAddress.of(fullAddress, detailAddress); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/com/ajou/hertz/common/dto/response/CoordinateResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.ajou.hertz.common.dto.response; | ||
|
||
import com.ajou.hertz.common.dto.CoordinateDto; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
@Getter | ||
public class CoordinateResponse { | ||
|
||
@Schema(description = "위도", example = "37.123456") | ||
private String lat; | ||
|
||
@Schema(description = "경도", example = "127.123456") | ||
private String lng; | ||
|
||
public static CoordinateResponse from(CoordinateDto coordinateDto) { | ||
return new CoordinateResponse(coordinateDto.getLat(), coordinateDto.getLng()); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/main/java/com/ajou/hertz/common/dto/response/FullAddressResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.ajou.hertz.common.dto.response; | ||
|
||
import com.ajou.hertz.common.dto.FullAddressDto; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
@Getter | ||
public class FullAddressResponse { | ||
|
||
|
||
@Schema(description = "시/도", example = "서울특별시") | ||
private String sido; | ||
|
||
@Schema(description = "시/군/구", example = "강남구") | ||
private String sgg; | ||
|
||
@Schema(description = "지번주소", example = "수원시 팔달구 권선로11") | ||
private String lotNumberAddress; | ||
|
||
@Schema(description = "도로명 주소", example = "서울특별시 강남구 역삼동 123-45번지") | ||
private String roadAddress; | ||
|
||
@Schema(description = "상세주소", example = "아주 빌딩 2층") | ||
private String detailAddress; | ||
|
||
public static FullAddressResponse from(FullAddressDto fullAddressDto) { | ||
return new FullAddressResponse( | ||
fullAddressDto.getSido(), | ||
fullAddressDto.getSgg(), | ||
fullAddressDto.getLotNumberAddress(), | ||
fullAddressDto.getRoadAddress(), | ||
fullAddressDto.getDetailAddress() | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 36 additions & 38 deletions
74
src/main/java/com/ajou/hertz/common/entity/FullAddress.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,66 @@ | ||
package com.ajou.hertz.common.entity; | ||
|
||
import java.util.Arrays; | ||
|
||
import com.ajou.hertz.common.exception.InvalidAddressFormatException; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Embeddable; | ||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.Arrays; | ||
|
||
@AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Getter | ||
@Embeddable | ||
public class FullAddress { | ||
|
||
@Column(nullable = false) | ||
private String sido; | ||
|
||
@Column(nullable = false) | ||
private String sgg; | ||
@Column(nullable = false) | ||
private String sido; | ||
|
||
private String lotNumberAddress; | ||
@Column(nullable = false) | ||
private String sgg; | ||
|
||
private String roadAddress; | ||
private String lotNumberAddress; | ||
|
||
@Column(nullable = false) | ||
private String detailAddress; | ||
private String roadAddress; | ||
|
||
public static FullAddress of(String fullAddress, String detailAddress) { | ||
@Column(nullable = false) | ||
private String detailAddress; | ||
|
||
String[] parsedAddress = fullAddress.split(" "); | ||
public static FullAddress of(String fullAddress, String detailAddress) { | ||
|
||
if (parsedAddress.length < 2) { | ||
throw new InvalidAddressFormatException(fullAddress); | ||
String[] parsedAddress = fullAddress.split(" "); | ||
|
||
} | ||
if (parsedAddress.length < 2) { | ||
throw new InvalidAddressFormatException(fullAddress); | ||
|
||
String sido = parsedAddress[0]; | ||
StringBuilder sggBuilder = new StringBuilder(); | ||
String lotNumberAddress = null; | ||
String roadAddress = null; | ||
} | ||
|
||
int num; | ||
for (num = 1; num < parsedAddress.length; num++) { | ||
if (parsedAddress[num].matches(".*[동면읍소로길]$")) { | ||
break; | ||
} | ||
sggBuilder.append(parsedAddress[num]).append(" "); | ||
} | ||
String sido = parsedAddress[0]; | ||
StringBuilder sggBuilder = new StringBuilder(); | ||
String lotNumberAddress = null; | ||
String roadAddress = null; | ||
|
||
String sgg = sggBuilder.toString().trim(); | ||
int num; | ||
for (num = 1; num < parsedAddress.length; num++) { | ||
if (parsedAddress[num].matches(".*[동면읍소로길]$")) { | ||
break; | ||
} | ||
sggBuilder.append(parsedAddress[num]).append(" "); | ||
} | ||
|
||
if (parsedAddress.length > num) { | ||
if (fullAddress.matches(".+[로길].+")) { | ||
roadAddress = String.join(" ", Arrays.copyOfRange(parsedAddress, num, parsedAddress.length)); | ||
} else { | ||
lotNumberAddress = String.join(" ", Arrays.copyOfRange(parsedAddress, num, parsedAddress.length)); | ||
} | ||
} | ||
String sgg = sggBuilder.toString().trim(); | ||
|
||
return new FullAddress(sido, sgg, lotNumberAddress, roadAddress, detailAddress); | ||
} | ||
if (parsedAddress.length > num) { | ||
if (fullAddress.matches(".+[로길].+")) { | ||
roadAddress = String.join(" ", Arrays.copyOfRange(parsedAddress, num, parsedAddress.length)); | ||
} else { | ||
lotNumberAddress = String.join(" ", Arrays.copyOfRange(parsedAddress, num, parsedAddress.length)); | ||
} | ||
} | ||
|
||
return new FullAddress(sido, sgg, lotNumberAddress, roadAddress, detailAddress); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.