This is the codeAbility Sharing Platform! Learn more about the codeAbility Sharing Platform.

Skip to content
Snippets Groups Projects
Commit 1fffc6cd authored by Eduard Frankford's avatar Eduard Frankford
Browse files

refactored the searchUserStatistics method

parent 8228d7a6
2 merge requests!188Merging Peer Reviewing et. al to Master,!164211 peer reviewing functionality
......@@ -28,6 +28,7 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import at.ac.uibk.gitsearch.es.model.DocumentInfo;
import at.ac.uibk.gitsearch.service.AchievementService;
import at.ac.uibk.gitsearch.service.SearchService;
import at.ac.uibk.gitsearch.service.StatisticsService;
import at.ac.uibk.gitsearch.service.UserService;
......@@ -53,15 +54,18 @@ public class AchievementResource {
private final SearchService searchService;
private final AchievementService achievementService;
private final StatisticsService statisticsService;
private final UserService userService;
public AchievementResource(SearchService searchService, StatisticsService statisticsService, UserService userService) {
public AchievementResource(SearchService searchService, StatisticsService statisticsService, UserService userService, AchievementService achievementService) {
this.searchService = searchService;
this.statisticsService = statisticsService;
this.userService = userService;
this.achievementService = achievementService;
}
@GetMapping("/user/achievements")
......@@ -69,20 +73,7 @@ public class AchievementResource {
public ResponseEntity<StatisticsDTO> searchUserStatistics() throws IOException {
String email = userService.getUserWithAuthorities().get().getEmail();
log.debug("REST request to search statistics for user {}", email);
SearchResultsDTO results = searchService.searchResultForAuthorEmail(email, 1000);
int totalAmountOfViews = 0;
int totalAmountOfDownloads = 0;
for (SearchResultDTO result : results.getSearchResult()) {
Optional<StatisticsDTO> statisticsDTO = statisticsService.findOneByExerciseID((Long.parseLong(result.getExerciseId())));
if (statisticsDTO.isPresent()) {
StatisticsDTO newStats = statisticsDTO.get();
totalAmountOfViews += newStats.getViews();
totalAmountOfDownloads += newStats.getDownloads();
}
}
StatisticsDTO toReturn = new StatisticsDTO();
toReturn.setViews(totalAmountOfViews);
toReturn.setDownloads(totalAmountOfDownloads);
StatisticsDTO toReturn = achievementService.searchUserStatistics(email);
return new ResponseEntity<StatisticsDTO>(toReturn, HttpStatus.OK);
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment