diff --git a/src/main/java/com/walking/api/web/controller/traffic/TrafficController.java b/src/main/java/com/walking/api/web/controller/traffic/TrafficController.java index d3f5a95..7b4f853 100644 --- a/src/main/java/com/walking/api/web/controller/traffic/TrafficController.java +++ b/src/main/java/com/walking/api/web/controller/traffic/TrafficController.java @@ -1,7 +1,5 @@ package com.walking.api.web.controller.traffic; -import com.walking.api.data.entity.BaseEntity; -import com.walking.api.repository.dao.traffic.TrafficRepository; import com.walking.api.security.authentication.token.TokenUserDetails; import com.walking.api.security.authentication.token.TokenUserDetailsService; import com.walking.api.security.filter.token.AccessTokenResolver; @@ -14,12 +12,11 @@ import com.walking.api.traffic.dto.SearchTrafficsUseCaseIn; import com.walking.api.traffic.dto.SearchTrafficsUseCaseOut; import com.walking.api.traffic.dto.UpdateFavoriteTrafficUseCaseIn; -import com.walking.api.traffic.service.TrafficPredictService; -import com.walking.api.traffic.service.dto.TPQuery; import com.walking.api.traffic.service.model.PredictTargetTraffic; import com.walking.api.traffic.usecase.AddFavoriteTrafficUseCase; import com.walking.api.traffic.usecase.BrowseFavoriteTrafficsUseCase; import com.walking.api.traffic.usecase.DeleteFavoriteTrafficUseCase; +import com.walking.api.traffic.usecase.InfoFavoriteTrafficUseCase; import com.walking.api.traffic.usecase.ReadTrafficsUseCase; import com.walking.api.traffic.usecase.SearchTrafficsUseCase; import com.walking.api.traffic.usecase.UpdateFavoriteTrafficUseCase; @@ -30,10 +27,8 @@ import com.walking.api.web.support.ApiResponse.SuccessBody; import com.walking.api.web.support.ApiResponseGenerator; import com.walking.api.web.support.MessageCode; -import java.util.List; import java.util.Map; import java.util.Objects; -import java.util.stream.Collectors; import javax.servlet.http.HttpServletRequest; import javax.validation.Valid; import javax.validation.constraints.Min; @@ -70,8 +65,7 @@ public class TrafficController { private final DeleteFavoriteTrafficUseCase deleteFavoriteTrafficUseCase; private final UpdateFavoriteTrafficUseCase updateFavoriteTrafficUseCase; - private final TrafficRepository trafficRepository; - private final TrafficPredictService trafficPredictService; + private final InfoFavoriteTrafficUseCase infoFavoriteTrafficUseCase; @GetMapping() public ApiResponse> searchTraffics( @@ -154,11 +148,7 @@ public ApiResponse deleteFavoriteTraffic( @GetMapping("/info") public ApiResponse>> infoFavoriteTraffic() { - List allIds = - trafficRepository.findAll().stream().map(BaseEntity::getId).collect(Collectors.toList()); - TPQuery query = new TPQuery(allIds); - Map predictData = - trafficPredictService.execute(query).getPredictedData(); + Map predictData = infoFavoriteTrafficUseCase.execute(); return ApiResponseGenerator.success(predictData, HttpStatus.OK, MessageCode.SUCCESS); } } diff --git a/src/main/kotlin/com/walking/api/traffic/usecase/InfoFavoriteTrafficUseCase.kt b/src/main/kotlin/com/walking/api/traffic/usecase/InfoFavoriteTrafficUseCase.kt new file mode 100644 index 0000000..effc3d6 --- /dev/null +++ b/src/main/kotlin/com/walking/api/traffic/usecase/InfoFavoriteTrafficUseCase.kt @@ -0,0 +1,22 @@ +package com.walking.api.traffic.usecase + +import com.walking.api.repository.dao.traffic.TrafficRepository +import com.walking.api.traffic.service.TrafficPredictService +import com.walking.api.traffic.service.dto.TPQuery +import com.walking.api.traffic.service.model.PredictTargetTraffic +import org.springframework.stereotype.Service +import java.util.stream.Collectors + +@Service +class InfoFavoriteTrafficUseCase( + private val trafficRepository: TrafficRepository, + private val trafficPredictService: TrafficPredictService +) { + fun execute(): Map { + val allIds: List = trafficRepository.findAll().stream() + .map { it.id } + .collect(Collectors.toList()) + val query = TPQuery(allIds) + return trafficPredictService.execute(query).predictedData + } +} \ No newline at end of file