-
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.
Merge branch 'develop' into feat/#30
- Loading branch information
Showing
63 changed files
with
1,012 additions
and
160 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
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
43 changes: 43 additions & 0 deletions
43
src/main/java/com/acon/server/common/auth/jwt/JwtUtils.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,43 @@ | ||
package com.acon.server.common.auth.jwt; | ||
|
||
import com.acon.server.common.auth.jwt.config.JwtConfig; | ||
import io.jsonwebtoken.Jwts; | ||
import io.jsonwebtoken.SignatureAlgorithm; | ||
import io.jsonwebtoken.security.Keys; | ||
import java.util.Date; | ||
import java.util.List; | ||
import javax.crypto.SecretKey; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class JwtUtils { | ||
|
||
private final SecretKey secretKey; | ||
private static final long ACCESS_TOKEN_EXPIRE_TIME = 1000 * 60 * 30; // 30분 | ||
private static final long REFRESH_TOKEN_EXPIRE_TIME = 1000 * 60 * 60 * 24 * 30L; // 30일 | ||
private static final String JWT_KEY = "memberId"; | ||
|
||
public JwtUtils(JwtConfig jwtConfig) { | ||
byte[] keyBytes = jwtConfig.getSecretKey().getBytes(); | ||
this.secretKey = Keys.hmacShaKeyFor(keyBytes); | ||
} | ||
|
||
public List<String> createToken(Long memberId) { | ||
long now = (new Date()).getTime(); | ||
Date accessTokenExpiryTime = new Date(now + ACCESS_TOKEN_EXPIRE_TIME); | ||
Date refreshTokenExpiryTime = new Date(now + REFRESH_TOKEN_EXPIRE_TIME); | ||
|
||
String accessToken = Jwts.builder() | ||
.claim(JWT_KEY, memberId) | ||
.setExpiration(accessTokenExpiryTime) | ||
.signWith(secretKey, SignatureAlgorithm.HS512) | ||
.compact(); | ||
|
||
String refreshToken = Jwts.builder() | ||
.setExpiration(refreshTokenExpiryTime) | ||
.signWith(secretKey, SignatureAlgorithm.HS512) | ||
.compact(); | ||
|
||
return List.of(accessToken, refreshToken); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/acon/server/common/auth/jwt/config/JwtConfig.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,15 @@ | ||
package com.acon.server.common.auth.jwt.config; | ||
|
||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.Setter; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
|
||
@ConfigurationProperties(prefix = "jwt") | ||
@RequiredArgsConstructor | ||
@Getter | ||
@Setter | ||
public class JwtConfig { | ||
|
||
private final String secretKey; | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/com/acon/server/global/config/AppStartupConfig.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,25 @@ | ||
package com.acon.server.global.config; | ||
|
||
import com.acon.server.spot.application.service.SpotService; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.boot.ApplicationRunner; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class AppStartupConfig { | ||
|
||
private final SpotService spotService; | ||
|
||
@Bean | ||
public ApplicationRunner applicationRunner() { | ||
return args -> { | ||
log.info("애플리케이션 시작 시 Spot 데이터를 업데이트하는 작업을 시작합니다."); | ||
spotService.updateNullCoordinatesForSpots(); | ||
log.info("Spot 데이터 업데이트 작업이 완료되었습니다."); | ||
}; | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/acon/server/global/config/OpenFeignConfig.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,12 @@ | ||
package com.acon.server.global.config; | ||
|
||
import com.acon.server.ServerApplication; | ||
import org.springframework.cloud.openfeign.EnableFeignClients; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
@EnableFeignClients(basePackageClasses = ServerApplication.class) | ||
public class OpenFeignConfig { | ||
|
||
// TODO: 타임아웃 설정 추가, 서킷 브레이커 적용하기 | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/acon/server/global/config/SchedulingConfig.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.acon.server.global.config; | ||
|
||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.scheduling.annotation.EnableScheduling; | ||
|
||
@Configuration | ||
@EnableScheduling | ||
public class SchedulingConfig { | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/com/acon/server/global/config/properties/NaverMapsProperties.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,16 @@ | ||
package com.acon.server.global.config.properties; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@Getter | ||
@Setter | ||
@ConfigurationProperties(prefix = "naver.maps") | ||
public class NaverMapsProperties { | ||
|
||
private String clientId; | ||
private String clientSecret; | ||
} |
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
8 changes: 8 additions & 0 deletions
8
src/main/java/com/acon/server/global/external/GeoCodingResponse.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 com.acon.server.global.external; | ||
|
||
public record GeoCodingResponse( | ||
String latitude, | ||
String longitude | ||
) { | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/com/acon/server/global/external/NaverMapsAdapter.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,30 @@ | ||
package com.acon.server.global.external; | ||
|
||
import com.acon.server.global.exception.BusinessException; | ||
import com.acon.server.global.exception.ErrorType; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class NaverMapsAdapter { | ||
|
||
private final NaverMapsClient naverMapsClient; | ||
|
||
public GeoCodingResponse getGeoCodingResult(String address) { | ||
// TODO: try-catch로 감싸기 | ||
return Optional.ofNullable(naverMapsClient.getGeoCode(address)) | ||
.map(response -> (List<Map<String, Object>>) response.get("addresses")) | ||
.filter(addresses -> !addresses.isEmpty()) | ||
.map(addresses -> addresses.get(0)) | ||
.map(firstAddress -> new GeoCodingResponse( | ||
(String) firstAddress.get("x"), | ||
(String) firstAddress.get("y") | ||
)) | ||
.orElseThrow( | ||
() -> new BusinessException(ErrorType.NAVER_MAPS_GEOCODING_API_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
20 changes: 20 additions & 0 deletions
20
src/main/java/com/acon/server/global/external/NaverMapsFeignConfig.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.acon.server.global.external; | ||
|
||
import com.acon.server.global.config.properties.NaverMapsProperties; | ||
import feign.RequestInterceptor; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.context.annotation.Bean; | ||
|
||
@RequiredArgsConstructor | ||
public class NaverMapsFeignConfig { | ||
|
||
private final NaverMapsProperties naverMapsProperties; | ||
|
||
@Bean | ||
public RequestInterceptor requestInterceptor() { | ||
return requestTemplate -> { | ||
requestTemplate.header("X-NCP-APIGW-API-KEY-ID", naverMapsProperties.getClientId()); | ||
requestTemplate.header("X-NCP-APIGW-API-KEY", naverMapsProperties.getClientSecret()); | ||
}; | ||
} | ||
} |
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
23 changes: 23 additions & 0 deletions
23
src/main/java/com/acon/server/global/scheduler/SpotScheduler.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,23 @@ | ||
package com.acon.server.global.scheduler; | ||
|
||
import com.acon.server.spot.application.service.SpotService; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.scheduling.annotation.Scheduled; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class SpotScheduler { | ||
|
||
private final SpotService spotService; | ||
|
||
// 매 시 정각에 실행 | ||
@Scheduled(cron = "0 0 * * * *") | ||
public void scheduleUpdateCoordinates() { | ||
log.info("스케줄링 작업: 위도 또는 경도 정보가 비어 있는 Spot 데이터 업데이트 시작"); | ||
spotService.updateNullCoordinatesForSpots(); | ||
log.info("스케줄링 작업: Spot 데이터 업데이트 완료"); | ||
} | ||
} |
Oops, something went wrong.