Skip to content

Commit

Permalink
feat: StoreServiceAdapter 추상화
Browse files Browse the repository at this point in the history
  • Loading branch information
juno-junho committed Sep 12, 2023
1 parent 6a48119 commit abad8f6
Show file tree
Hide file tree
Showing 5 changed files with 195 additions and 0 deletions.
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 src/main/java/com/ray/pominowner/global/config/Testfq.java
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 src/main/java/com/ray/pominowner/global/config/TokenProvider.java
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;
}

}
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();
}

}
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);

}

0 comments on commit abad8f6

Please sign in to comment.