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; ...@@ -28,6 +28,7 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import at.ac.uibk.gitsearch.es.model.DocumentInfo; 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.SearchService;
import at.ac.uibk.gitsearch.service.StatisticsService; import at.ac.uibk.gitsearch.service.StatisticsService;
import at.ac.uibk.gitsearch.service.UserService; import at.ac.uibk.gitsearch.service.UserService;
...@@ -53,15 +54,18 @@ public class AchievementResource { ...@@ -53,15 +54,18 @@ public class AchievementResource {
private final SearchService searchService; private final SearchService searchService;
private final AchievementService achievementService;
private final StatisticsService statisticsService; private final StatisticsService statisticsService;
private final UserService userService; 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.searchService = searchService;
this.statisticsService = statisticsService; this.statisticsService = statisticsService;
this.userService = userService; this.userService = userService;
this.achievementService = achievementService;
} }
@GetMapping("/user/achievements") @GetMapping("/user/achievements")
...@@ -69,20 +73,7 @@ public class AchievementResource { ...@@ -69,20 +73,7 @@ public class AchievementResource {
public ResponseEntity<StatisticsDTO> searchUserStatistics() throws IOException { public ResponseEntity<StatisticsDTO> searchUserStatistics() throws IOException {
String email = userService.getUserWithAuthorities().get().getEmail(); String email = userService.getUserWithAuthorities().get().getEmail();
log.debug("REST request to search statistics for user {}", email); log.debug("REST request to search statistics for user {}", email);
SearchResultsDTO results = searchService.searchResultForAuthorEmail(email, 1000); StatisticsDTO toReturn = achievementService.searchUserStatistics(email);
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);
return new ResponseEntity<StatisticsDTO>(toReturn, HttpStatus.OK); 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