-
Notifications
You must be signed in to change notification settings - Fork 0
[Refactor] 보행등 코드 커버리지 높이기 #229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
The head ref may contain hidden characters: "refactor/215-\uBCF4\uD589\uB4F1-\uCF54\uB4DC-\uCEE4\uBC84\uB9AC\uC9C0-\uB192\uC774\uAE30"
Changes from 7 commits
f6d2d5b
5cd28e2
b50c8d3
ac3e9d3
586eed4
1b941f0
e87d422
0dffb17
df847bf
25000ea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,53 +22,69 @@ | |
@Transactional(readOnly = true) | ||
public class TrafficService { | ||
|
||
private static final String TRAFFIC_REDIS_KEY = "traffic:info"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 사용하지 않는 변수는 이제 필요없으니 삭제하면 좋을 거 같아요 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 헉 그러게요..! 바로 삭제할게요! |
||
|
||
private final CustomTrafficRepositoryImpl customTrafficRepository; | ||
private final TrafficRedisRepository trafficRedisRepository; | ||
private final TrafficRepository trafficRepository; | ||
private final RedisTemplate<Object, Object> redisTemplate; | ||
|
||
public List<TrafficResponse> searchAndSaveTraffic(Double lat, Double lng, int radius){ | ||
|
||
log.debug("주변 보행등 정보 - lat = {}, lng = {}, radius = {}", lat, lng, radius); | ||
List<TrafficResponse> responseDB; | ||
|
||
boolean exists = Boolean.TRUE.equals(redisTemplate.hasKey("traffic:info")); | ||
boolean exists = Boolean.TRUE.equals(redisTemplate.hasKey(TRAFFIC_REDIS_KEY)); | ||
DongminL marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if (exists) { | ||
double kiloRadius = (double) radius/1000; | ||
return trafficRedisRepository.findNearbyTraffics(lat, lng, kiloRadius); | ||
List<TrafficResponse> responseRedis = trafficRedisRepository.findNearbyTraffics(lat, lng, kiloRadius); | ||
|
||
log.info("redis 주변 보행등 데이터 : redis data 갯수 = {} ", responseRedis.size()); | ||
return responseRedis; | ||
} | ||
|
||
try { | ||
responseDB = customTrafficRepository.findNearestTraffics(lat, lng, radius); | ||
|
||
log.info("주변 보행등 정보 캐싱 : DB data 갯수 = {} ", responseDB.size()); | ||
for (TrafficResponse response : responseDB) { | ||
trafficRedisRepository.save(response); | ||
} | ||
|
||
log.info("DB 주변 보행등 데이터 캐싱 성공"); | ||
DongminL marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return responseDB; | ||
|
||
} catch (NullPointerException e) { | ||
log.error("❌ traffic Not Found : {}", e.getMessage(), e); | ||
} catch (Exception e) { | ||
log.error("주변 보행등 조회 실패 : lat = {}, lng = {}, radius = {}, error = {}", lat, lng, radius, e.getMessage()); | ||
throw new BusinessException(TrafficErrorCode.NOT_FOUND_TRAFFIC); | ||
} | ||
} | ||
|
||
public TrafficResponse trafficFindById(Long id) { | ||
|
||
log.debug("보행등 세부정보 찾기 - id = {}", id); | ||
|
||
TrafficResponse responseRedis = trafficRedisRepository.findById( id ); | ||
|
||
if(responseRedis != null) { | ||
log.info("redis 보행등 세부정보 : redis data = {} ", responseRedis); | ||
return responseRedis; | ||
} | ||
|
||
try{ | ||
|
||
TrafficResponse responseDB = new TrafficResponse(trafficRepository.findByTrafficSignalId(id)); | ||
|
||
log.info("보행등 세부정보 : DB data = {} ", responseDB); | ||
|
||
trafficRedisRepository.save(responseDB); | ||
|
||
log.info("보행등 세부정보 캐싱 성공"); | ||
return responseDB; | ||
|
||
} catch (NullPointerException e) { | ||
log.error("❌ traffic Not Found : {}", e.getMessage(), e); | ||
} catch (Exception e) { | ||
log.error("보행등 세부정보 조회 실패 : {}", e.getMessage(), e); | ||
throw new BusinessException(TrafficErrorCode.NOT_FOUND_TRAFFIC); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이 코드처럼 DTO 자체를 직렬화 시켜서 저장시킬 수 있습니다. 이때 저장하려는 DTO는
Serializable
을 상속받으면 돼요!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오...변경해서 다시올려볼게요! 감사합니다!