-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Refactor] JSON으로 전환 #96
Open
AlbertImKr
wants to merge
3
commits into
whatever-mentoring:albertimkr
Choose a base branch
from
AlbertImKr:refactor-rest-api
base: albertimkr
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+78
−75
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,15 @@ | ||
### Origin URL 저장 | ||
POST {{baseUrl}}/shorten-url/create | ||
Content-Type: text/plain | ||
Content-Type: application/json | ||
|
||
https://www.naver.com | ||
{ | ||
"originUrl": "https://www.naver.com" | ||
} | ||
|
||
### 짧은 키워드로 Origin URL 조회 | ||
POST {{baseUrl}}/shorten-url/search | ||
Content-Type: text/plain | ||
Content-Type: application/json | ||
|
||
1 | ||
{ | ||
"shortenUrl": "1" | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/kotlin/community/whatever/onembackendkotlin/Requests.kt
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,5 @@ | ||
package community.whatever.onembackendkotlin | ||
|
||
data class ShortenUrlCreateRequest(val originUrl: String) | ||
|
||
data class ShortenUrlSearchRequest(val shortenUrl: String) |
5 changes: 5 additions & 0 deletions
5
src/main/kotlin/community/whatever/onembackendkotlin/Responses.kt
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,5 @@ | ||
package community.whatever.onembackendkotlin | ||
|
||
data class ShortenedUrlResponse(val shortenedUrl: String) | ||
|
||
data class OriginUrlResponse(val originUrl: String) |
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
17 changes: 2 additions & 15 deletions
17
src/main/kotlin/community/whatever/onembackendkotlin/UrlShortenService.kt
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,20 +1,7 @@ | ||
package community.whatever.onembackendkotlin | ||
|
||
interface UrlShortenService { | ||
/** | ||
* 아이디를 통해 원본 URL을 찾는다. | ||
* | ||
* @param id ShortenedUrl의 id이다. | ||
* @return ShortenedUrl의 id | ||
* @throws UrlNotFoundException ShortenedUrl의 id에 해당하는 ShortenedUrl이 존재하지 않으면 발생한다. | ||
*/ | ||
fun getOriginUrl(id: String): String | ||
|
||
/** | ||
* URL이 존재하면 저장된 URL의 id를 반환하고 존재하지 않으면 새롭게 URL을 저장하고 id를 반환한다. | ||
* | ||
* @param originUrl 단축할 URL이다. | ||
* @return 저장된 URL의 id이다. | ||
*/ | ||
fun saveShortenUrl(originUrl: String): String | ||
fun getOriginUrl(request: ShortenUrlSearchRequest): OriginUrlResponse | ||
fun saveShortenUrl(request: ShortenUrlCreateRequest): ShortenedUrlResponse | ||
} |
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 |
---|---|---|
|
@@ -8,6 +8,7 @@ import org.awaitility.kotlin.untilAsserted | |
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.DisplayName | ||
import org.junit.jupiter.api.Nested | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.params.ParameterizedTest | ||
import org.junit.jupiter.params.provider.CsvSource | ||
import org.springframework.beans.factory.annotation.Autowired | ||
|
@@ -42,32 +43,27 @@ class UrlShortenControllerIntegrationTest { | |
) | ||
fun `등록된 원본 URL을 키로 검색하면 해당 원본 URL을 반환한다`(originUrl: String) = runTest { | ||
// given | ||
val key = createUrl(originUrl) | ||
.expectBody(String::class.java) | ||
val key = createUrl(ShortenUrlCreateRequest(originUrl)) | ||
.expectBody(ShortenedUrlResponse::class.java) | ||
.returnResult() | ||
.responseBody!! | ||
|
||
// when | ||
val result = searchShortenUrl(key) | ||
val result = searchShortenUrl(ShortenUrlSearchRequest(key.shortenedUrl)) | ||
|
||
// then | ||
result.expectStatus().isOk() | ||
.expectBody(String::class.java) | ||
.isEqualTo(originUrl) | ||
.expectBody(OriginUrlResponse::class.java) | ||
.isEqualTo(OriginUrlResponse(originUrl)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fyi. jsonPath |
||
} | ||
|
||
@ParameterizedTest | ||
@CsvSource( | ||
"https://www.google.com", | ||
"https://www.naver.com", | ||
"https://www.daum.net" | ||
) | ||
fun `등록되지 않은 원본 URL을 키로 검색하면 404를 반환한다`(originUrl: String) = runTest { | ||
@Test | ||
fun `등록되지 않은 원본 URL을 키로 검색하면 404를 반환한다`() = runTest { | ||
// given | ||
val key = "non-exist-key" | ||
|
||
// when | ||
val result = searchShortenUrl(key) | ||
val result = searchShortenUrl(ShortenUrlSearchRequest(key)) | ||
|
||
// then | ||
result.expectStatus() | ||
|
@@ -87,14 +83,14 @@ class UrlShortenControllerIntegrationTest { | |
) | ||
fun `원본 URL을 등록하면 키를 반환한다`(originUrl: String) = runTest { | ||
// when | ||
val result = createUrl(originUrl) | ||
val result = createUrl(ShortenUrlCreateRequest(originUrl)) | ||
|
||
// then | ||
val key = result.expectStatus().isOk() | ||
.expectBody(String::class.java) | ||
val shortenedUrlResponse = result.expectStatus().isOk() | ||
.expectBody(ShortenedUrlResponse::class.java) | ||
.returnResult() | ||
.responseBody!! | ||
assertThat(key).isNotBlank() | ||
assertThat(shortenedUrlResponse.shortenedUrl).isNotBlank() | ||
} | ||
|
||
@ParameterizedTest | ||
|
@@ -104,7 +100,8 @@ class UrlShortenControllerIntegrationTest { | |
val originUrls = (1..count).map { "https://www.google.com/$it" } | ||
|
||
// when | ||
val keys = originUrls.map { async { createUrlAndReturnKey(it) } } | ||
val keys = originUrls.map { async { createUrlAndReturnKey(ShortenUrlCreateRequest(it)) } } | ||
.map { it.await() } | ||
|
||
// then | ||
await untilAsserted { assertThat(keys).hasSize(count).doesNotHaveDuplicates() } | ||
|
@@ -118,10 +115,10 @@ class UrlShortenControllerIntegrationTest { | |
) | ||
fun `등록된 원본 URL을 다시 등록하면 기존 키를 반환한다`(originUrl: String) = runTest { | ||
// given | ||
val key = createUrlAndReturnKey(originUrl) | ||
val key = createUrlAndReturnKey(ShortenUrlCreateRequest(originUrl)) | ||
|
||
// when | ||
val result = createUrl(originUrl) | ||
val result = createUrl(ShortenUrlCreateRequest(originUrl)) | ||
|
||
// then | ||
result.expectStatus().isOk() | ||
|
@@ -130,17 +127,17 @@ class UrlShortenControllerIntegrationTest { | |
} | ||
} | ||
|
||
private fun searchShortenUrl(key: String) = webTestClient.post() | ||
private fun searchShortenUrl(request: ShortenUrlSearchRequest) = webTestClient.post() | ||
.uri("/shorten-url/search") | ||
.bodyValue(key) | ||
.bodyValue(request) | ||
.exchange() | ||
|
||
private fun createUrl(originUrl: String) = webTestClient.post() | ||
private fun createUrl(request: ShortenUrlCreateRequest) = webTestClient.post() | ||
.uri("/shorten-url/create") | ||
.bodyValue(originUrl) | ||
.bodyValue(request) | ||
.exchange() | ||
|
||
private fun createUrlAndReturnKey(originUrl: String) = createUrl(originUrl) | ||
private fun createUrlAndReturnKey(request: ShortenUrlCreateRequest) = createUrl(request) | ||
.expectBody(String::class.java) | ||
.returnResult() | ||
.responseBody!! | ||
|
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit
비즈니스 레이어에 프레젠테이션 레이어의 객체가 있는 것은 선호하지 않습니다.