-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: w3w open api component - coordinates, locale -> w3wWords - w3wWords -> coordinates * fix: test 코드 일시적으로 비활성화 - 환경변수 설정이 필요함 - 추후 github action workflow 수정 예정 * code-review: w3w 컴포넌트 인터페이스 리턴 타입 변경 - W3wWordsResponse - W3wCoordinatesResponse
- Loading branch information
1 parent
3837936
commit 19ac696
Showing
15 changed files
with
269 additions
and
4 deletions.
There are no files selected for viewing
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
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
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
2 changes: 0 additions & 2 deletions
2
subprojects/api/src/test/java/com/poemfoot/api/ApiApplicationTests.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
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,17 @@ | ||
ext { | ||
w3wJavaWrapperVersion = '3.1.19' | ||
} | ||
|
||
dependencies { | ||
implementation 'org.springframework.boot:spring-boot-starter-web' | ||
|
||
implementation "com.what3words:w3w-java-wrapper:${w3wJavaWrapperVersion}" | ||
|
||
compileOnly 'org.projectlombok:lombok' | ||
annotationProcessor 'org.projectlombok:lombok' | ||
testImplementation 'org.springframework.boot:spring-boot-starter-test' | ||
} | ||
|
||
tasks.named('test') { | ||
useJUnitPlatform() | ||
} |
11 changes: 11 additions & 0 deletions
11
subprojects/w3w/src/main/java/com/poemfoot/w3w/W3wApplication.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,11 @@ | ||
package com.poemfoot.w3w; | ||
|
||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
public class W3wApplication { | ||
|
||
public static void main(String[] args) { | ||
// Do Nothing | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
subprojects/w3w/src/main/java/com/poemfoot/w3w/W3wProvider.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,11 @@ | ||
package com.poemfoot.w3w; | ||
|
||
import com.poemfoot.w3w.dto.W3wCoordinatesResponse; | ||
import com.poemfoot.w3w.dto.W3wWordsResponse; | ||
import java.util.Locale; | ||
|
||
public interface W3wProvider { | ||
W3wWordsResponse getWords(double latitude, double longitude, Locale locale); | ||
|
||
W3wCoordinatesResponse getCoordinates(String word1, String word2, String word3); | ||
} |
17 changes: 17 additions & 0 deletions
17
subprojects/w3w/src/main/java/com/poemfoot/w3w/config/W3wConfig.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,17 @@ | ||
package com.poemfoot.w3w.config; | ||
|
||
import com.what3words.javawrapper.What3WordsV3; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
public class W3wConfig { | ||
@Value("${w3w.api.key}") | ||
private String apiKey; | ||
|
||
@Bean | ||
public What3WordsV3 what3WordsV3() { | ||
return new What3WordsV3(apiKey); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
subprojects/w3w/src/main/java/com/poemfoot/w3w/dto/W3wCoordinatesResponse.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.poemfoot.w3w.dto; | ||
|
||
import com.what3words.javawrapper.response.ConvertToCoordinates; | ||
import com.what3words.javawrapper.response.Coordinates; | ||
import com.what3words.javawrapper.response.Square; | ||
|
||
public record W3wCoordinatesResponse( | ||
String country, | ||
Square square, | ||
String nearestPlace, | ||
Coordinates coordinates, | ||
W3wWords words, | ||
String language, | ||
String locale, | ||
String map | ||
){ | ||
public static W3wCoordinatesResponse of(ConvertToCoordinates convertToCoordinates) { | ||
return new W3wCoordinatesResponse( | ||
convertToCoordinates.getCountry(), | ||
convertToCoordinates.getSquare(), | ||
convertToCoordinates.getNearestPlace(), | ||
convertToCoordinates.getCoordinates(), | ||
W3wWords.of(convertToCoordinates.getWords()), | ||
convertToCoordinates.getLanguage(), | ||
convertToCoordinates.getLocale(), | ||
convertToCoordinates.getMap() | ||
); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
subprojects/w3w/src/main/java/com/poemfoot/w3w/dto/W3wWords.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,22 @@ | ||
package com.poemfoot.w3w.dto; | ||
|
||
public record W3wWords ( | ||
String word1, | ||
String word2, | ||
String word3 | ||
){ | ||
public static W3wWords of(String compositeWords) { | ||
String[] words = compositeWords.split("\\."); | ||
|
||
if (words.length != 3) { | ||
throw new IllegalArgumentException("Invalid composite words: " + compositeWords); | ||
} | ||
|
||
return new W3wWords(words[0], words[1], words[2]); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return String.join(".", word1, word2, word3); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
subprojects/w3w/src/main/java/com/poemfoot/w3w/dto/W3wWordsResponse.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.poemfoot.w3w.dto; | ||
|
||
import com.what3words.javawrapper.response.ConvertTo3WA; | ||
import com.what3words.javawrapper.response.Coordinates; | ||
import com.what3words.javawrapper.response.Square; | ||
|
||
public record W3wWordsResponse( | ||
String country, | ||
Square square, | ||
String nearestPlace, | ||
Coordinates coordinates, | ||
W3wWords words, | ||
String language, | ||
String locale, | ||
String map | ||
){ | ||
public static W3wWordsResponse of(ConvertTo3WA convertTo3WA) { | ||
return new W3wWordsResponse( | ||
convertTo3WA.getCountry(), | ||
convertTo3WA.getSquare(), | ||
convertTo3WA.getNearestPlace(), | ||
convertTo3WA.getCoordinates(), | ||
W3wWords.of(convertTo3WA.getWords()), | ||
convertTo3WA.getLanguage(), | ||
convertTo3WA.getLocale(), | ||
convertTo3WA.getMap() | ||
); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
subprojects/w3w/src/main/java/com/poemfoot/w3w/impl/W3wProviderImpl.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,38 @@ | ||
package com.poemfoot.w3w.impl; | ||
|
||
import com.poemfoot.w3w.W3wProvider; | ||
import com.poemfoot.w3w.dto.W3wCoordinatesResponse; | ||
import com.poemfoot.w3w.dto.W3wWordsResponse; | ||
import com.what3words.javawrapper.What3WordsV3; | ||
import com.what3words.javawrapper.request.Coordinates; | ||
import com.what3words.javawrapper.response.ConvertTo3WA; | ||
import com.what3words.javawrapper.response.ConvertToCoordinates; | ||
import java.util.Locale; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class W3wProviderImpl implements W3wProvider { | ||
|
||
private final What3WordsV3 w3wApi; | ||
|
||
@Override | ||
public W3wWordsResponse getWords(double latitude, double longitude, Locale locale) { | ||
ConvertTo3WA convertTo3WA = w3wApi.convertTo3wa(new Coordinates(latitude, longitude)) | ||
.language(locale.getLanguage()) | ||
.execute(); | ||
|
||
return W3wWordsResponse.of(convertTo3WA); | ||
} | ||
|
||
@Override | ||
public W3wCoordinatesResponse getCoordinates(String word1, String word2, String word3) { | ||
String w3wWords = String.join(".", word1, word2, word3); | ||
|
||
ConvertToCoordinates convertToCoordinates = w3wApi.convertToCoordinates(w3wWords) | ||
.execute(); | ||
|
||
return W3wCoordinatesResponse.of(convertToCoordinates); | ||
} | ||
} |
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,3 @@ | ||
w3w: | ||
api: | ||
key: ${W3W_API_KEY} |
64 changes: 64 additions & 0 deletions
64
subprojects/w3w/src/test/java/com/poemfoot/w3w/W3wProviderTest.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,64 @@ | ||
package com.poemfoot.w3w; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import com.poemfoot.w3w.dto.W3wCoordinatesResponse; | ||
import com.poemfoot.w3w.dto.W3wWords; | ||
import com.poemfoot.w3w.dto.W3wWordsResponse; | ||
import java.util.Locale; | ||
import org.junit.jupiter.api.Disabled; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.CsvSource; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
|
||
@Disabled | ||
@SpringBootTest | ||
class W3wProviderTest { | ||
@Autowired | ||
private W3wProvider w3wProvider; | ||
|
||
@ParameterizedTest(name = "getWords({0}, {1}, {2})") | ||
@CsvSource(value = {"37.2,127.5,ko"}, delimiter = ',') | ||
void getWords(double latitude, double longitude, Locale locale) { | ||
// When | ||
W3wWordsResponse result = w3wProvider.getWords(latitude, longitude, locale); | ||
|
||
// Then | ||
assertAll( | ||
() -> assertThat(result).isNotNull(), | ||
() -> assertThat(result).hasFieldOrProperty("words") | ||
); | ||
|
||
W3wWords w3wWords = result.words(); | ||
|
||
assertAll( | ||
() -> assertThat(w3wWords).isNotNull(), | ||
() -> assertThat(w3wWords).hasNoNullFieldsOrProperties() | ||
); | ||
|
||
assertAll( | ||
() -> assertThat(w3wWords.word1()).isNotBlank(), | ||
() -> assertThat(w3wWords.word2()).isNotBlank(), | ||
() -> assertThat(w3wWords.word3()).isNotBlank() | ||
); | ||
} | ||
|
||
@ParameterizedTest | ||
@CsvSource(value = {"좋겠다.휴게실.이성"}, delimiter = '.') | ||
void getCoordinates(String word1, String word2, String word3) { | ||
W3wCoordinatesResponse result = w3wProvider.getCoordinates(word1, word2, word3); | ||
|
||
assertAll( | ||
() -> assertThat(result).isNotNull(), | ||
() -> assertThat(result).hasFieldOrProperty("coordinates") | ||
); | ||
|
||
assertAll( | ||
() -> assertThat(result.coordinates()).isNotNull(), | ||
() -> assertThat(result.coordinates()).hasFieldOrProperty("lat"), | ||
() -> assertThat(result.coordinates()).hasFieldOrProperty("lng") | ||
); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
subprojects/w3w/src/test/java/com/poemfoot/w3w/dto/W3wWordsTest.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,23 @@ | ||
package com.poemfoot.w3w.dto; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.CsvSource; | ||
|
||
class W3wWordsTest { | ||
|
||
@ParameterizedTest | ||
@CsvSource(value = {"word1,word2,word3"}, delimiter = ',') | ||
void testToString(String word1, String word2, String word3) { | ||
// Given | ||
W3wWords w3wWords = new W3wWords(word1, word2, word3); | ||
|
||
// Expect | ||
assertAll( | ||
() -> assertThat(w3wWords).isNotNull(), | ||
() -> assertThat(w3wWords.toString()).isEqualTo(String.join(".", word1, word2, word3)) | ||
); | ||
} | ||
} |