Skip to content

Commit

Permalink
Api-Release-v0.0.2-18
Browse files Browse the repository at this point in the history
Api-Release-v0.0.2-18
  • Loading branch information
imenuuu authored Dec 12, 2023
2 parents 04159d1 + 0e14264 commit c0656b4
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package com.example.matchapi.common;

import com.example.matchapi.common.security.JwtService;
import com.example.matchcommon.reponse.CommonResponse;
import com.example.matchinfrastructure.aligo.service.AligoInfraService;
import com.example.matchinfrastructure.match_aligo.dto.AlimTalkDto;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.context.annotation.Profile;
import org.springframework.web.bind.annotation.*;

import static com.example.matchinfrastructure.aligo.dto.AlimType.EXECUTION;
import static com.example.matchinfrastructure.aligo.dto.AlimType.PAYMENT;

@RestController
@RequiredArgsConstructor
@Profile("localDev")
@RequestMapping("/test")
public class TestController {
private final AligoInfraService aligoInfraService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ private void configureAuthorizationRequests(HttpSecurity httpSecurity) throws Ex
.antMatchers("/payments/web-hook").permitAll()
.antMatchers("/payments/validate").permitAll()
.antMatchers("/payments/info").permitAll()
.antMatchers("/test").permitAll()
.antMatchers("/test/**").permitAll()
.and()
.apply(new JwtSecurityConfig(jwtService));
}
Expand Down
12 changes: 0 additions & 12 deletions Match-Api/src/main/resources/ehcache.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,6 @@
<persistence strategy="localTempSwap" />
</cache>

<cache name="portOneTokenCache"
maxEntriesLocalHeap="100"
maxEntriesLocalDisk="100"
eternal="false"
diskSpoolBufferSizeMB="5"
timeToIdleSeconds="900"
timeToLiveSeconds="900"
memoryStoreEvictionPolicy="LFU"
transactionalMode="off">
<persistence strategy="localTempSwap" />
</cache>

<cache name="bannerCache"
maxEntriesLocalHeap="100"
maxEntriesLocalDisk="100"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public RedisCacheManager redisCacheManager(RedisConnectionFactory redisConnectio

Map<String, RedisCacheConfiguration> cacheConfiguration = new HashMap<>();
cacheConfiguration.put("flameCache", redisCacheConfiguration.entryTtl(Duration.ofMinutes(10L)));
cacheConfiguration.put("portOneTokenCache", redisCacheConfiguration.entryTtl(Duration.ofMinutes(20L)));
cacheConfiguration.remove("portOneTokenCache"); // 또는 적절한 TTL로 설정 변경

return RedisCacheManager.RedisCacheManagerBuilder
.fromConnectionFactory(redisConnectionFactory)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,59 @@
import com.example.matchinfrastructure.pay.portone.client.PortOneFeignClient;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.redis.cache.RedisCacheManager;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import java.time.Duration;

@Service
@Slf4j
@RequiredArgsConstructor
public class PortOneAuthService {
private final PortOneFeignClient portOneFeignClient;
private final PortOneProperties portOneProperties;
private final StringRedisTemplate stringRedisTemplate;


@Cacheable(value = "portOneTokenCache", key = "#profile", cacheManager = "redisCacheManager")
public String getToken(String profile) {
log.info("request token");
return getTokens(profile);
String cachedToken = stringRedisTemplate.opsForValue().get("portOneTokenCache::" + profile);
if (cachedToken != null) {
return cachedToken;
}

return requestNewToken(profile);
}

@CachePut(value = "portOneTokenCache", key = "#profile", cacheManager = "redisCacheManager")
public String getTokens(String profile) {
PortOneResponse<PortOneAuth> portOneResponse = portOneFeignClient.getAccessToken(
PortOneAuthReq.builder()
.imp_key(portOneProperties.getKey())
.imp_secret(portOneProperties.getSecret())
.build());
public String requestNewToken(String profile) {
PortOneResponse<PortOneAuth> portOneResponse = getPortOneToken();

long ttl = portOneResponse.getResponse().getExpired_at()-portOneResponse.getResponse().getNow();

log.info("token ttl : " + ttl);

String newToken = portOneResponse.getResponse().getAccess_token();

stringRedisTemplate.opsForValue().set("portOneTokenCache::" + profile, newToken, Duration.ofSeconds(ttl));

return portOneResponse.getResponse().getAccess_token();
}


public String getAuthToken() {
PortOneResponse<PortOneAuth> portOneResponse = portOneFeignClient.getAccessToken(PortOneAuthReq.builder().imp_key(portOneProperties.getKey()).imp_secret(portOneProperties.getSecret()).build());
return portOneResponse.getResponse().getAccess_token();
return getPortOneToken().getResponse().getAccess_token();
}


private PortOneResponse<PortOneAuth> getPortOneToken() {
return portOneFeignClient.getAccessToken(PortOneAuthReq.builder().imp_key(portOneProperties.getKey()).imp_secret(portOneProperties.getSecret()).build());
}
/*
@Scheduled(fixedRate = 1200000)
public void refreshAuthToken() {
String refreshToken = getTokens();
log.info("refresh token {} ", refreshToken);
}*/

}

0 comments on commit c0656b4

Please sign in to comment.