-
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.
* rename: DTO를 infra 모듈에서 api 모듈로 이동 * rename: 파일 관련 API DTO 및 디렉토리 변경 * feat: branch 링크 생성 API 구현 * test: branch 링크 생성 API 테스트 코드 작성 * refactor: 유튜브 링크 유효성 검사 로직 리팩토링 * test: branch API 호출 실패 케이스에 대한 테스트 코드 추가
- Loading branch information
1 parent
0ae4e77
commit 2ac9c30
Showing
21 changed files
with
340 additions
and
41 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
10 changes: 10 additions & 0 deletions
10
packy-api/src/main/java/com/dilly/admin/dto/request/BranchRequest.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,10 @@ | ||
package com.dilly.admin.dto.request; | ||
|
||
import lombok.Builder; | ||
|
||
@Builder | ||
public record BranchRequest( | ||
Long boxId | ||
) { | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
packy-api/src/main/java/com/dilly/admin/dto/response/UrlResponse.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.dilly.admin.dto.response; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.Builder; | ||
|
||
@Builder | ||
public record UrlResponse( | ||
@Schema(example = "www.example.com") | ||
String url | ||
) { | ||
|
||
public static UrlResponse from(String url) { | ||
return UrlResponse.builder() | ||
.url(url) | ||
.build(); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...esponse/YoutubeUrlValidationResponse.java → ...esponse/YoutubeUrlValidationResponse.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,4 +1,4 @@ | ||
package com.dilly.dto.response; | ||
package com.dilly.admin.dto.response; | ||
|
||
import lombok.Builder; | ||
|
||
|
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
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 |
---|---|---|
|
@@ -54,3 +54,8 @@ cloud: | |
youtube: | ||
api: | ||
key: test | ||
|
||
branch: | ||
api: | ||
key: test | ||
url: test |
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
61 changes: 61 additions & 0 deletions
61
packy-infra/src/main/java/com/dilly/application/BranchService.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,61 @@ | ||
package com.dilly.application; | ||
|
||
import com.dilly.exception.ErrorCode; | ||
import com.dilly.exception.internalserver.InternalServerException; | ||
import com.dilly.model.BranchUrl; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import lombok.AllArgsConstructor; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.web.reactive.function.client.WebClient; | ||
import org.springframework.web.reactive.function.client.WebClientException; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@AllArgsConstructor | ||
@Slf4j | ||
public class BranchService { | ||
|
||
@Value("${branch.api.key}") | ||
private String branchApiKey; | ||
|
||
@Value("${branch.api.url}") | ||
private String branchApiUrl; | ||
|
||
public String createBranchUrl(Long boxId) { | ||
WebClient webClient = WebClient.builder() | ||
.baseUrl(branchApiUrl) | ||
.defaultHeader(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE) | ||
.defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) | ||
.build(); | ||
|
||
Map<String, Object> bodyData = new HashMap<>(); | ||
|
||
bodyData.put("branch_key", branchApiKey); | ||
|
||
Map<String, String> data = new HashMap<>(); | ||
data.put("boxId", boxId.toString()); | ||
bodyData.put("data", data); | ||
|
||
try { | ||
BranchUrl branchUrl = webClient.post() | ||
.bodyValue(bodyData) | ||
.retrieve() | ||
.bodyToMono(BranchUrl.class) | ||
.block(); | ||
|
||
if (branchUrl == null) { | ||
throw new InternalServerException(ErrorCode.BRANCH_SERVER_ERROR); | ||
} | ||
|
||
return branchUrl.url(); | ||
} catch (WebClientException e) { | ||
throw new InternalServerException(ErrorCode.BRANCH_SERVER_ERROR); | ||
} | ||
} | ||
} |
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
17 changes: 0 additions & 17 deletions
17
packy-infra/src/main/java/com/dilly/dto/request/FileRequest.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.