Commit de63d87be5d0117171162a27b09d6c93336c1b74
1 parent
366049c0
Exists in
master
Adicionando listagens
Showing
10 changed files
with
119 additions
and
2 deletions
Show diff stats
codigos/backend/docs/diagram.asta
No preview for this file type
codigos/backend/docs/diagram.jpg
codigos/backend/docs/diagram.jpg.bak
No preview for this file type
codigos/backend/src/main/java/com/srh/api/controller/ItemRatingController.java
| ... | ... | @@ -73,4 +73,17 @@ public class ItemRatingController { |
| 73 | 73 | itemRatingService.delete(id); |
| 74 | 74 | return ResponseEntity.noContent().build(); |
| 75 | 75 | } |
| 76 | + | |
| 77 | + @GetMapping("/itens/{itemId}") | |
| 78 | + public ResponseEntity<Page<ItemRatingDto>> listItensRatingsByItem(@PathVariable Integer itemId, Pageable pageInfo) { | |
| 79 | + Page<ItemRating> itensRatings = itemRatingService.listItensRatingsByItem(itemId, pageInfo); | |
| 80 | + return ResponseEntity.ok(ItemRatingDto.convert(itensRatings)); | |
| 81 | + } | |
| 82 | + | |
| 83 | + @GetMapping("/tags/{tagId}") | |
| 84 | + public ResponseEntity<Page<ItemRatingDto>> listItensRatingsByTag(@PathVariable Integer tagId, | |
| 85 | + Pageable pageInfo) { | |
| 86 | + Page<ItemRating> itensRatings = itemRatingService.listItensRAtingsByTag(tagId, pageInfo); | |
| 87 | + return ResponseEntity.ok(ItemRatingDto.convert(itensRatings)); | |
| 88 | + } | |
| 76 | 89 | } | ... | ... |
codigos/backend/src/main/java/com/srh/api/controller/RecommendationController.java
| ... | ... | @@ -70,4 +70,28 @@ public class RecommendationController { |
| 70 | 70 | return ResponseEntity.noContent().build(); |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | + @GetMapping("/performances/{algorithmId}") | |
| 74 | + public ResponseEntity<Page<RecommendationDto>> listRecommendationsPerformance( | |
| 75 | + @PathVariable Integer algorithmId, Pageable pageInfo) { | |
| 76 | + Page<Recommendation> recommendations = recommendationService.listRecommendationsByAlgorithm( | |
| 77 | + algorithmId, pageInfo | |
| 78 | + ); | |
| 79 | + return ResponseEntity.ok(RecommendationDto.convert(recommendations)); | |
| 80 | + } | |
| 81 | + | |
| 82 | + @GetMapping("/matrices/{matrixId}") | |
| 83 | + public ResponseEntity<Page<RecommendationDto>> listRecommendationsMatrix( | |
| 84 | + @PathVariable Integer matrixId, Pageable pageInfo) { | |
| 85 | + Page<Recommendation> recommendations = recommendationService.listRecommendationsByMatrixId( | |
| 86 | + matrixId, pageInfo); | |
| 87 | + return ResponseEntity.ok(RecommendationDto.convert(recommendations)); | |
| 88 | + } | |
| 89 | + | |
| 90 | + @GetMapping("/tags/{tagId}") | |
| 91 | + public ResponseEntity<Page<RecommendationDto>> listRecommendationsByTag( | |
| 92 | + @PathVariable Integer tagId, Pageable pageInfo | |
| 93 | + ) { | |
| 94 | + Page<Recommendation> recommendations = recommendationService.listRecommendationsByTag(tagId, pageInfo); | |
| 95 | + return ResponseEntity.ok(RecommendationDto.convert(recommendations)); | |
| 96 | + } | |
| 73 | 97 | } | ... | ... |
codigos/backend/src/main/java/com/srh/api/repository/ItemRatingRepository.java
| 1 | 1 | package com.srh.api.repository; |
| 2 | 2 | |
| 3 | +import com.srh.api.model.Item; | |
| 3 | 4 | import com.srh.api.model.ItemRating; |
| 4 | 5 | import org.springframework.data.repository.PagingAndSortingRepository; |
| 5 | 6 | |
| 7 | +import java.util.List; | |
| 8 | + | |
| 6 | 9 | public interface ItemRatingRepository extends PagingAndSortingRepository<ItemRating, Integer> { |
| 10 | + List<ItemRating> findByItem(Item item); | |
| 7 | 11 | } | ... | ... |
codigos/backend/src/main/java/com/srh/api/repository/ItemRepository.java
| ... | ... | @@ -2,10 +2,12 @@ package com.srh.api.repository; |
| 2 | 2 | |
| 3 | 3 | import com.srh.api.model.Item; |
| 4 | 4 | import com.srh.api.model.Project; |
| 5 | +import com.srh.api.model.Tag; | |
| 5 | 6 | import org.springframework.data.repository.PagingAndSortingRepository; |
| 6 | 7 | |
| 7 | 8 | import java.util.List; |
| 8 | 9 | |
| 9 | 10 | public interface ItemRepository extends PagingAndSortingRepository<Item, Integer> { |
| 10 | 11 | List<Item> findByProject(Project project); |
| 12 | + List<Item> findByTags(Tag tag); | |
| 11 | 13 | } | ... | ... |
codigos/backend/src/main/java/com/srh/api/repository/RecommendationRepository.java
| 1 | 1 | package com.srh.api.repository; |
| 2 | 2 | |
| 3 | +import com.srh.api.model.Algorithm; | |
| 3 | 4 | import com.srh.api.model.Recommendation; |
| 5 | +import org.springframework.data.domain.Page; | |
| 4 | 6 | import org.springframework.data.repository.PagingAndSortingRepository; |
| 5 | 7 | |
| 8 | +import java.util.List; | |
| 9 | + | |
| 6 | 10 | public interface RecommendationRepository extends PagingAndSortingRepository<Recommendation, Integer> { |
| 11 | + List<Recommendation> findByAlgorithm(Algorithm algorithm); | |
| 12 | + List<Recommendation> findByMatrixId(Integer matrixId); | |
| 13 | + List<Recommendation> findByItem(Integer itemId); | |
| 7 | 14 | } | ... | ... |
codigos/backend/src/main/java/com/srh/api/service/ItemRatingService.java
| ... | ... | @@ -3,7 +3,10 @@ package com.srh.api.service; |
| 3 | 3 | import com.srh.api.model.Item; |
| 4 | 4 | import com.srh.api.model.ItemRating; |
| 5 | 5 | import com.srh.api.model.Evaluator; |
| 6 | +import com.srh.api.model.Tag; | |
| 6 | 7 | import com.srh.api.repository.ItemRatingRepository; |
| 8 | +import com.srh.api.repository.ItemRepository; | |
| 9 | +import com.srh.api.utils.PageUtil; | |
| 7 | 10 | import lombok.Setter; |
| 8 | 11 | import org.hibernate.ObjectNotFoundException; |
| 9 | 12 | import org.springframework.beans.factory.annotation.Autowired; |
| ... | ... | @@ -11,6 +14,8 @@ import org.springframework.data.domain.Page; |
| 11 | 14 | import org.springframework.data.domain.Pageable; |
| 12 | 15 | import org.springframework.stereotype.Service; |
| 13 | 16 | |
| 17 | +import java.util.ArrayList; | |
| 18 | +import java.util.List; | |
| 14 | 19 | import java.util.Optional; |
| 15 | 20 | |
| 16 | 21 | @Service |
| ... | ... | @@ -19,11 +24,17 @@ public class ItemRatingService { |
| 19 | 24 | private ItemRatingRepository itemRatingRepository; |
| 20 | 25 | |
| 21 | 26 | @Autowired |
| 27 | + private ItemRepository itemRepository; | |
| 28 | + | |
| 29 | + @Autowired | |
| 22 | 30 | private EvaluatorService evaluatorService; |
| 23 | 31 | |
| 24 | 32 | @Autowired |
| 25 | 33 | private ItemService itemService; |
| 26 | 34 | |
| 35 | + @Autowired | |
| 36 | + private TagService tagService; | |
| 37 | + | |
| 27 | 38 | @Setter |
| 28 | 39 | private String authorizationHeaderValue; |
| 29 | 40 | |
| ... | ... | @@ -62,4 +73,24 @@ public class ItemRatingService { |
| 62 | 73 | find(id); |
| 63 | 74 | itemRatingRepository.deleteById(id); |
| 64 | 75 | } |
| 76 | + | |
| 77 | + public Page<ItemRating> listItensRatingsByItem(Integer itemId, Pageable pageInfo) { | |
| 78 | + Item item = itemService.find(itemId); | |
| 79 | + List<ItemRating> itensRatings = itemRatingRepository.findByItem(item); | |
| 80 | + PageUtil<ItemRating> pageUtil = new PageUtil<>(pageInfo, itensRatings); | |
| 81 | + return pageUtil.getPage(); | |
| 82 | + } | |
| 83 | + | |
| 84 | + public Page<ItemRating> listItensRAtingsByTag(Integer tagId, Pageable pageInfo) { | |
| 85 | + Tag tag = tagService.find(tagId); | |
| 86 | + List<Item> itensWithTag = itemRepository.findByTags(tag); | |
| 87 | + List<ItemRating> itensRatings = new ArrayList<>(); | |
| 88 | + | |
| 89 | + for (Item item: itensWithTag) { | |
| 90 | + itensRatings.addAll(item.getItemRatings()); | |
| 91 | + } | |
| 92 | + | |
| 93 | + PageUtil<ItemRating> pageUtil = new PageUtil<>(pageInfo, itensRatings); | |
| 94 | + return pageUtil.getPage(); | |
| 95 | + } | |
| 65 | 96 | } | ... | ... |
codigos/backend/src/main/java/com/srh/api/service/RecommendationService.java
| ... | ... | @@ -4,9 +4,10 @@ import com.srh.api.algorithms.AlgorithmCalc; |
| 4 | 4 | import com.srh.api.algorithms.AlgorithmStrategy; |
| 5 | 5 | import com.srh.api.algorithms.structure.RecommendationsByUser; |
| 6 | 6 | import com.srh.api.dto.resource.RecommendationForm; |
| 7 | -import com.srh.api.model.Evaluator; | |
| 8 | -import com.srh.api.model.Recommendation; | |
| 7 | +import com.srh.api.model.*; | |
| 8 | +import com.srh.api.repository.ItemRepository; | |
| 9 | 9 | import com.srh.api.repository.RecommendationRepository; |
| 10 | +import com.srh.api.utils.PageUtil; | |
| 10 | 11 | import org.hibernate.ObjectNotFoundException; |
| 11 | 12 | import org.springframework.beans.factory.annotation.Autowired; |
| 12 | 13 | import org.springframework.data.domain.Page; |
| ... | ... | @@ -22,6 +23,15 @@ public class RecommendationService { |
| 22 | 23 | @Autowired |
| 23 | 24 | private RecommendationRepository recommendationRepository; |
| 24 | 25 | |
| 26 | + @Autowired | |
| 27 | + private ItemRepository itemRepository; | |
| 28 | + | |
| 29 | + @Autowired | |
| 30 | + private TagService tagService; | |
| 31 | + | |
| 32 | + @Autowired | |
| 33 | + private AlgorithmService algorithmService; | |
| 34 | + | |
| 25 | 35 | public Recommendation find(Integer id) { |
| 26 | 36 | Optional<Recommendation> recommendation = recommendationRepository.findById(id); |
| 27 | 37 | |
| ... | ... | @@ -53,4 +63,30 @@ public class RecommendationService { |
| 53 | 63 | AlgorithmCalc algorithm = AlgorithmStrategy.findInstance(recommendationInfo.getAlgorithmId()); |
| 54 | 64 | return algorithm.calc(recommendationInfo); |
| 55 | 65 | } |
| 66 | + | |
| 67 | + public Page<Recommendation> listRecommendationsByAlgorithm(Integer algorithmId, Pageable pageInfo) { | |
| 68 | + Algorithm algorithm = algorithmService.find(algorithmId); | |
| 69 | + List<Recommendation> recommendations = recommendationRepository.findByAlgorithm(algorithm); | |
| 70 | + PageUtil<Recommendation> pageUtil = new PageUtil<>(pageInfo, recommendations); | |
| 71 | + return pageUtil.getPage(); | |
| 72 | + } | |
| 73 | + | |
| 74 | + public Page<Recommendation> listRecommendationsByMatrixId(Integer matrixId, Pageable pageInfo) { | |
| 75 | + List<Recommendation> recommendations = recommendationRepository.findByMatrixId(matrixId); | |
| 76 | + PageUtil<Recommendation> pageUtil = new PageUtil<>(pageInfo, recommendations); | |
| 77 | + return pageUtil.getPage(); | |
| 78 | + } | |
| 79 | + | |
| 80 | + public Page<Recommendation> listRecommendationsByTag(Integer tagId, Pageable pageInfo) { | |
| 81 | + Tag tag = tagService.find(tagId); | |
| 82 | + List<Item> itens = itemRepository.findByTags(tag); | |
| 83 | + List<Recommendation> recommendations = new ArrayList<>(); | |
| 84 | + | |
| 85 | + for (Item item : itens) { | |
| 86 | + recommendations.addAll(item.getRecommendations()); | |
| 87 | + } | |
| 88 | + | |
| 89 | + PageUtil<Recommendation> pageUtil = new PageUtil<>(pageInfo, recommendations); | |
| 90 | + return pageUtil.getPage(); | |
| 91 | + } | |
| 56 | 92 | } | ... | ... |