Skip to content

Commit

Permalink
refactor: usecase로 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
belljun3395 committed Aug 19, 2024
1 parent 514618c commit fa05d33
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<ApiResponse.SuccessBody<SearchTrafficsUseCaseOut>> searchTraffics(
Expand Down Expand Up @@ -154,11 +148,7 @@ public ApiResponse<ApiResponse.Success> deleteFavoriteTraffic(

@GetMapping("/info")
public ApiResponse<SuccessBody<Map<Long, PredictTargetTraffic>>> infoFavoriteTraffic() {
List<Long> allIds =
trafficRepository.findAll().stream().map(BaseEntity::getId).collect(Collectors.toList());
TPQuery query = new TPQuery(allIds);
Map<Long, PredictTargetTraffic> predictData =
trafficPredictService.execute(query).getPredictedData();
Map<Long, PredictTargetTraffic> predictData = infoFavoriteTrafficUseCase.execute();
return ApiResponseGenerator.success(predictData, HttpStatus.OK, MessageCode.SUCCESS);
}
}
Original file line number Diff line number Diff line change
@@ -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<Long, PredictTargetTraffic> {
val allIds: List<Long> = trafficRepository.findAll().stream()
.map { it.id }
.collect(Collectors.toList())
val query = TPQuery(allIds)
return trafficPredictService.execute(query).predictedData
}
}

0 comments on commit fa05d33

Please sign in to comment.