-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #91 from Yanol-Market/feature/88
Feature/88 상품등록을 위한 야놀자 로그인
- Loading branch information
Showing
9 changed files
with
129 additions
and
19 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
src/main/java/site/goldenticket/common/api/RestTemplateConfig.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,14 @@ | ||
package site.goldenticket.common.api; | ||
|
||
import org.springframework.beans.factory.annotation.Configurable; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
@Configurable | ||
public class RestTemplateConfig { | ||
|
||
@Bean | ||
public RestTemplate restTemplate() { | ||
return new RestTemplate(); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/site/goldenticket/common/api/RestTemplateService.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,8 @@ | ||
package site.goldenticket.common.api; | ||
|
||
import java.util.Optional; | ||
|
||
public interface RestTemplateService { | ||
|
||
<T, R> Optional<T> get(String url, R request, Class<T> type); | ||
} |
40 changes: 40 additions & 0 deletions
40
src/main/java/site/goldenticket/common/api/RestTemplateServiceImpl.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 site.goldenticket.common.api; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.http.HttpEntity; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.client.HttpClientErrorException; | ||
import org.springframework.web.client.RestTemplate; | ||
import site.goldenticket.common.exception.CustomException; | ||
|
||
import java.util.Optional; | ||
|
||
import static org.springframework.http.MediaType.APPLICATION_JSON; | ||
import static site.goldenticket.common.response.ErrorCode.COMMON_SYSTEM_ERROR; | ||
|
||
@Slf4j | ||
@Component | ||
@RequiredArgsConstructor | ||
public class RestTemplateServiceImpl implements RestTemplateService { | ||
|
||
private final RestTemplate restTemplate; | ||
|
||
@Override | ||
public <T, R> Optional<T> get(String url, R request, Class<T> type) { | ||
HttpHeaders headers = new HttpHeaders(); | ||
headers.setContentType(APPLICATION_JSON); | ||
HttpEntity<R> entity = new HttpEntity<>(request, headers); | ||
|
||
try { | ||
return Optional.ofNullable(restTemplate.postForObject(url, entity, type)); | ||
} catch (HttpClientErrorException e) { | ||
log.error("RestTemplate Get Exception Message = {}", e.getMessage()); | ||
return Optional.empty(); | ||
} catch (Exception e) { | ||
log.error("RestTemplate Get Exception", e); | ||
throw new CustomException(COMMON_SYSTEM_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
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