22
33import com .trendyol .recomengine .webservice .repositories .RecommendationRepository ;
44import com .trendyol .recomengine .webservice .resource .Recommendation ;
5+ import com .trendyol .recomengine .webservice .services .RecommendationService ;
56import org .springframework .beans .factory .annotation .Autowired ;
67import org .springframework .web .bind .annotation .GetMapping ;
78import org .springframework .web .bind .annotation .PathVariable ;
1415class RecommendationController {
1516
1617 @ Autowired
17- private RecommendationRepository repository ;
18+ RecommendationService recommendationService ;
1819
1920 /**
2021 * This method is called when a GET request happens. Fetches recommendations from database for the user that is
@@ -27,22 +28,6 @@ class RecommendationController {
2728 */
2829 @ GetMapping ("/users/{userId}/recommendations" )
2930 Recommendation getRecommendation (@ PathVariable String userId ) {
30- Recommendation fetched = repository .findBy_id (userId );
31- return fetched == null ? generateDefaultRecommendations (userId ) : fetched ;
32- }
33-
34- /**
35- * Generates a default recommendation list for the user. For now, it returns 10 products' ids but default
36- * recommendations could be generated based on a criterion.
37- *
38- * @param userId The user id of the user that is to be recommended.
39- * @return A list of recommendations that is generated for the user.
40- * @see Recommendation
41- */
42- private Recommendation generateDefaultRecommendations (String userId ) {
43- return new Recommendation (userId , new String []{
44- "100" , "101" , "102" , "103" , "104" ,
45- "105" , "106" , "107" , "108" , "109"
46- });
31+ return recommendationService .getRecommendations (userId );
4732 }
4833}
0 commit comments