-
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
1 parent
6a48119
commit abad8f6
Showing
5 changed files
with
195 additions
and
0 deletions.
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
src/main/java/com/ray/pominowner/global/config/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,75 @@ | ||
//package com.ray.pominowner.global.config; | ||
// | ||
//import lombok.extern.slf4j.Slf4j; | ||
//import org.springframework.boot.web.client.RestTemplateBuilder; | ||
//import org.springframework.context.annotation.Bean; | ||
//import org.springframework.context.annotation.Configuration; | ||
//import org.springframework.http.HttpRequest; | ||
//import org.springframework.http.client.ClientHttpRequestExecution; | ||
//import org.springframework.http.client.ClientHttpRequestInterceptor; | ||
//import org.springframework.http.client.ClientHttpResponse; | ||
//import org.springframework.retry.policy.SimpleRetryPolicy; | ||
//import org.springframework.retry.support.RetryTemplate; | ||
//import org.springframework.web.client.RestTemplate; | ||
// | ||
//import java.io.BufferedReader; | ||
//import java.io.IOException; | ||
//import java.io.InputStreamReader; | ||
//import java.nio.charset.StandardCharsets; | ||
//import java.time.Duration; | ||
//import java.util.stream.Collectors; | ||
// | ||
//@Configuration | ||
//public class RestTemplateConfig { | ||
// | ||
// @Bean | ||
// public RestTemplate restTemplate(RestTemplateBuilder restTemplateBuilder) { | ||
// return restTemplateBuilder | ||
// .setConnectTimeout(Duration.ofSeconds(5)) | ||
// .setReadTimeout(Duration.ofSeconds(5)) | ||
// .build(); | ||
// } | ||
// | ||
// public ClientHttpRequestInterceptor clientHttpRequestInterceptor() { | ||
// return (request, body, execution) -> { | ||
// RetryTemplate retryTemplate = new RetryTemplate(); | ||
// retryTemplate.setRetryPolicy(new SimpleRetryPolicy(3)); | ||
// try { | ||
// return retryTemplate.execute(context -> execution.execute(request, body)); | ||
// } catch (Throwable throwable) { | ||
// throw new RuntimeException(throwable); | ||
// } | ||
// }; | ||
// } | ||
// | ||
// @Slf4j | ||
// static class LoggingInterceptor implements ClientHttpRequestInterceptor { | ||
// | ||
// @Override | ||
// public ClientHttpResponse intercept(HttpRequest req, byte[] body, ClientHttpRequestExecution ex) throws IOException { | ||
// final String sessionNumber = makeSessionNumber(); | ||
// printRequest(sessionNumber, req, body); | ||
// ClientHttpResponse response = ex.execute(req, body); | ||
// printResponse(sessionNumber, response); | ||
// return response; | ||
// } | ||
// | ||
// private String makeSessionNumber() { | ||
// return Integer.toString((int) (Math.random() * 1000000)); | ||
// } | ||
// | ||
// private void printRequest(final String sessionNumber, final HttpRequest req, final byte[] body) { | ||
// log.info("[{}] URI: {}, Method: {}, Headers:{}, Body:{} ", | ||
// sessionNumber, req.getURI(), req.getMethod(), req.getHeaders(), new String(body, StandardCharsets.UTF_8)); | ||
// } | ||
// | ||
// private void printResponse(final String sessionNumber, final ClientHttpResponse res) throws IOException { | ||
// String body = new BufferedReader(new InputStreamReader(res.getBody(), StandardCharsets.UTF_8)).lines() | ||
// .collect(Collectors.joining("\n")); | ||
// | ||
// log.info("[{}] Status: {}, Headers:{}, Body:{} ", | ||
// sessionNumber, res.getStatusCode(), res.getHeaders(), body); | ||
// } | ||
// } | ||
// | ||
//} |
64 changes: 64 additions & 0 deletions
64
src/main/java/com/ray/pominowner/global/config/Testfq.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.ray.pominowner.global.config; | ||
// | ||
//import com.ray.pominowner.store.controller.dto.StoreRegisterRequest; | ||
//import com.ray.pominowner.store.domain.Category; | ||
//import jakarta.validation.Valid; | ||
//import org.springframework.http.ResponseEntity; | ||
//import org.springframework.transaction.annotation.Transactional; | ||
//import org.springframework.web.bind.annotation.PostMapping; | ||
//import org.springframework.web.bind.annotation.RequestBody; | ||
// | ||
//import java.net.URI; | ||
//import java.util.List; | ||
//import java.util.stream.Collectors; | ||
// | ||
//public class Testfq | ||
// @PostMapping("/info") | ||
// public ResponseEntity<Void> registerStore(@RequestBody @Valid StoreRegisterRequest request) { | ||
// | ||
// List<Category> caches = categoryCache.getCategoryCache(); | ||
// List<String> categories = request.categories(); | ||
// | ||
// // validate // categories에 이상한 값 있으면 예외 | ||
// categories.stream() | ||
// .filter(category -> caches.stream().noneMatch(cache -> cache.hasSameName(category))) // cache의 카테고리 이름과 다른것이 통과 | ||
// .findAny() | ||
// .ifPresent(category -> { | ||
// throw new IllegalArgumentException("존재하지 않는 카테고리가 있습니다."); | ||
// }); | ||
// | ||
// // category -> Category 엔티티로 변환 필요 | ||
// categories.stream() | ||
// .map(category -> caches.stream() | ||
// .filter(cache -> cache.hasSameName(category)) | ||
// .findAny() | ||
// .orElseThrow(() -> new IllegalArgumentException("존재하지 않는 카테고리가 있습니다."))) | ||
// .collect(Collectors.toSet()); | ||
// | ||
// | ||
// Long storeId = storeService.registerStore(request.toEntity(converted)); | ||
// return ResponseEntity.created(URI.create("/api/v1/stores/info/" + storeId)).build(); | ||
// }{ | ||
//} | ||
// | ||
// | ||
//@Transactional | ||
//public Long registerStore(Store store) { | ||
//// validateBusinessNumber(store.getBusinessNumber()); | ||
// return storeRepository.save(store).getId(); | ||
// } | ||
// | ||
//public void validateBusinessNumber(Long businessNumber) throws JsonProcessingException { | ||
// RestTemplate restTemplate = new RestTemplate(); | ||
//final String url = "https://api.odcloud.kr/api/nts-businessman/v1/status?serviceKey=Oi7tL9wqUvkSCM6cn7PAcTwbvKh8AjqkVXzX3TTdOqu9NVVfVNIslDIiQz%2BEFvZyoO0MMpeaei%2BDlmEGzBgPIg%3D%3D&returnType=JSON"; | ||
// | ||
// Map<String, List<Long>> request = new HashMap<>(); | ||
// request.put("b_no", List.of(businessNumber)); | ||
// | ||
// String msg = objectMapper.writeValueAsString(request); | ||
// log.info("message = {}-----------",msg); | ||
// String string = restTemplate.postForObject(url, request, String.class); | ||
// | ||
// log.info("string = {}-----------",string); | ||
// | ||
// } |
20 changes: 20 additions & 0 deletions
20
src/main/java/com/ray/pominowner/global/config/TokenProvider.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.ray.pominowner.global.config; | ||
|
||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.PropertySource; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Getter | ||
@Component | ||
@PropertySource("classpath:sub/application-token.yml") | ||
public class TokenProvider { | ||
|
||
private final String businessNumberServiceKey; | ||
|
||
public TokenProvider(@Value("${api.token.business:''}") String businessNumberServiceKey) { | ||
this.businessNumberServiceKey = businessNumberServiceKey; | ||
} | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/com/ray/pominowner/global/config/WebSecurityConfig.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.ray.pominowner.global.config; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.security.config.annotation.web.builders.HttpSecurity; | ||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; | ||
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer; | ||
import org.springframework.security.web.SecurityFilterChain; | ||
|
||
@Configuration | ||
@EnableWebSecurity | ||
public class WebSecurityConfig { | ||
|
||
@Bean | ||
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { | ||
return http. | ||
authorizeHttpRequests(auth -> auth.anyRequest().authenticated()) | ||
.csrf(AbstractHttpConfigurer::disable) | ||
.build(); | ||
} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/com/ray/pominowner/store/service/adapter/StoreServiceAdapter.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 com.ray.pominowner.store.service.adapter; | ||
|
||
import com.ray.pominowner.store.domain.Category; | ||
import com.ray.pominowner.store.domain.Store; | ||
|
||
import java.util.List; | ||
|
||
public interface StoreServiceAdapter { | ||
|
||
List<Category> getCategories(); | ||
|
||
void storeCategories(Store store, List<String> categoryRequest); | ||
|
||
} |