|
1 | | -package com.urunov.controller; |
2 | | - |
3 | | -import com.urunov.dto.ProductInfoDTO; |
4 | | -import com.urunov.entity.elements.info.ProductInfo; |
5 | | -import com.urunov.model.FilterAttributesResponse; |
6 | | -import com.urunov.model.HomeTabsDataResponse; |
7 | | -import com.urunov.model.MainScreenResponse; |
8 | | -import com.urunov.model.SearchSuggestionResponse; |
9 | | - |
10 | | -import com.urunov.service.interfaces.CommonDataService; |
11 | | -import com.urunov.service.interfaces.LoadFakeDataService; |
12 | | -import org.springframework.beans.factory.annotation.Autowired; |
13 | | -import org.springframework.core.env.Environment; |
14 | | -import org.springframework.http.HttpStatus; |
15 | | -import org.springframework.http.ResponseEntity; |
16 | | -import org.springframework.web.bind.annotation.GetMapping; |
17 | | -import org.springframework.web.bind.annotation.RequestParam; |
18 | | -import org.springframework.web.bind.annotation.RestController; |
19 | | - |
20 | | -import java.util.HashMap; |
21 | | -import java.util.Objects; |
22 | | - |
23 | | -/** |
24 | | - * User: hamdamboy |
25 | | - * Project: model |
26 | | - * Github: @urunov |
27 | | - */ |
28 | | - |
29 | | -@RestController |
30 | | -public class CommonDataController { |
31 | | - |
32 | | - @Autowired |
33 | | - Environment environment; |
34 | | - |
35 | | - @Autowired |
36 | | - CommonDataService commonDataService; |
37 | | - |
38 | | - @Autowired |
39 | | - LoadFakeDataService loadFakeDataService; |
40 | | - |
41 | | - public void fillWithTestDate() { |
42 | | - if (Objects.equals(environment.getProperty("ACTIVE_PROFILE"), "dev")) { |
43 | | - loadFakeDataService.loadTestData(); |
44 | | - } |
45 | | - } |
46 | | - |
47 | | - @GetMapping(value = "/products", params = "q") |
48 | | - public ResponseEntity<?> getProductsByCategories(@RequestParam("q") String queryParams) { |
49 | | - ProductInfoDTO productInfoDTO = commonDataService.getProductsByCategories(queryParams); |
50 | | - |
51 | | - if (productInfoDTO == null) { |
52 | | - return ResponseEntity.badRequest().body("Query has not followed the required format."); |
53 | | - } |
54 | | - return ResponseEntity.ok(productInfoDTO); |
55 | | - } |
56 | | - |
57 | | - @GetMapping(value = "/products", params = "product_id") |
58 | | - public ResponseEntity<?> getProductsById(@RequestParam("product_id") String queryParams) { |
59 | | - HashMap<Integer, ProductInfo> resultMap = commonDataService.getProductsById(queryParams); |
60 | | - |
61 | | - if (resultMap == null) { |
62 | | - return ResponseEntity.badRequest().body("Query has not followed the required format."); |
63 | | - } |
64 | | - |
65 | | - return ResponseEntity.ok(resultMap); |
66 | | - } |
67 | | - |
68 | | - |
69 | | - @GetMapping("/home") |
70 | | - public ResponseEntity<?> getMainScreenData() { |
71 | | - |
72 | | - MainScreenResponse mainScreenInfoList = commonDataService.getHomeScreenData("homeAPI"); |
73 | | - if (mainScreenInfoList == null) { |
74 | | - return new ResponseEntity<Error>(HttpStatus.CONFLICT); |
75 | | - } |
76 | | - |
77 | | - return ResponseEntity.ok(mainScreenInfoList); |
78 | | - } |
79 | | - |
80 | | - |
81 | | - @GetMapping("/tabs") |
82 | | - public ResponseEntity<?> getHomeTabsDataResponse(){ |
83 | | - HomeTabsDataResponse homeTabsDataResponse = commonDataService.getBrandsAndApparelsByGender("tabsAPI"); |
84 | | - if(homeTabsDataResponse == null) |
85 | | - { |
86 | | - return new ResponseEntity<Error>(HttpStatus.CONFLICT); |
87 | | - } |
88 | | - |
89 | | - return ResponseEntity.ok(homeTabsDataResponse); |
90 | | - } |
91 | | - |
92 | | - |
93 | | - @GetMapping(value = "/filter", params = "q") |
94 | | - public ResponseEntity<?> getFilterAttributesProducts(@RequestParam("g") String queryParams) { |
95 | | - String[] splitParams = queryParams.split("="); |
96 | | - if (splitParams.length >= 1 && splitParams[0].equals("productname")) { |
97 | | - queryParams = "category=all"; |
98 | | - } |
99 | | - |
100 | | - FilterAttributesResponse result = commonDataService.getFilterAttributesByProducts(queryParams); |
101 | | - |
102 | | - if (result == null) { |
103 | | - return ResponseEntity.badRequest().body("Query has not followed the required format."); |
104 | | - } |
105 | | - |
106 | | - return ResponseEntity.ok(result); |
107 | | - } |
108 | | - |
109 | | - @GetMapping("/search-suggestion-list") |
110 | | - public ResponseEntity<?> getSearchSuggestionList() { |
111 | | - SearchSuggestionResponse searchSuggestionResponse = commonDataService.getSearchSuggestionList(); |
112 | | - if (searchSuggestionResponse == null) { |
113 | | - return new ResponseEntity<Error>(HttpStatus.CONFLICT); |
114 | | - } |
115 | | - |
116 | | - return ResponseEntity.ok(searchSuggestionResponse); |
117 | | - } |
118 | | -} |
| 1 | +//package com.urunov.controller; |
| 2 | +// |
| 3 | +//import com.urunov.dto.ProductInfoDTO; |
| 4 | +//import com.urunov.entity.elements.info.ProductInfo; |
| 5 | +//import com.urunov.model.FilterAttributesResponse; |
| 6 | +//import com.urunov.model.HomeTabsDataResponse; |
| 7 | +//import com.urunov.model.MainScreenResponse; |
| 8 | +//import com.urunov.model.SearchSuggestionResponse; |
| 9 | +// |
| 10 | +//import com.urunov.service.interfaces.CommonDataService; |
| 11 | +//import com.urunov.service.interfaces.LoadFakeDataService; |
| 12 | +//import org.springframework.beans.factory.annotation.Autowired; |
| 13 | +//import org.springframework.core.env.Environment; |
| 14 | +//import org.springframework.http.HttpStatus; |
| 15 | +//import org.springframework.http.ResponseEntity; |
| 16 | +//import org.springframework.web.bind.annotation.GetMapping; |
| 17 | +//import org.springframework.web.bind.annotation.RequestParam; |
| 18 | +//import org.springframework.web.bind.annotation.RestController; |
| 19 | +// |
| 20 | +//import java.util.HashMap; |
| 21 | +//import java.util.Objects; |
| 22 | +// |
| 23 | +///** |
| 24 | +// * User: hamdamboy |
| 25 | +// * Project: model |
| 26 | +// * Github: @urunov |
| 27 | +// */ |
| 28 | +// |
| 29 | +//@RestController |
| 30 | +//public class CommonDataController { |
| 31 | +// |
| 32 | +// @Autowired |
| 33 | +// Environment environment; |
| 34 | +// |
| 35 | +// @Autowired |
| 36 | +// CommonDataService commonDataService; |
| 37 | +// |
| 38 | +// @Autowired |
| 39 | +// LoadFakeDataService loadFakeDataService; |
| 40 | +// |
| 41 | +// public void fillWithTestDate() { |
| 42 | +// if (Objects.equals(environment.getProperty("ACTIVE_PROFILE"), "dev")) { |
| 43 | +// loadFakeDataService.loadTestData(); |
| 44 | +// } |
| 45 | +// } |
| 46 | +// |
| 47 | +// @GetMapping(value = "/products", params = "q") |
| 48 | +// public ResponseEntity<?> getProductsByCategories(@RequestParam("q") String queryParams) { |
| 49 | +// ProductInfoDTO productInfoDTO = commonDataService.getProductsByCategories(queryParams); |
| 50 | +// |
| 51 | +// if (productInfoDTO == null) { |
| 52 | +// return ResponseEntity.badRequest().body("Query has not followed the required format."); |
| 53 | +// } |
| 54 | +// return ResponseEntity.ok(productInfoDTO); |
| 55 | +// } |
| 56 | +// |
| 57 | +// @GetMapping(value = "/products", params = "product_id") |
| 58 | +// public ResponseEntity<?> getProductsById(@RequestParam("product_id") String queryParams) { |
| 59 | +// HashMap<Integer, ProductInfo> resultMap = commonDataService.getProductsById(queryParams); |
| 60 | +// |
| 61 | +// if (resultMap == null) { |
| 62 | +// return ResponseEntity.badRequest().body("Query has not followed the required format."); |
| 63 | +// } |
| 64 | +// |
| 65 | +// return ResponseEntity.ok(resultMap); |
| 66 | +// } |
| 67 | +// |
| 68 | +// |
| 69 | +// @GetMapping("/home") |
| 70 | +// public ResponseEntity<?> getMainScreenData() { |
| 71 | +// |
| 72 | +// MainScreenResponse mainScreenInfoList = commonDataService.getHomeScreenData("homeAPI"); |
| 73 | +// if (mainScreenInfoList == null) { |
| 74 | +// return new ResponseEntity<Error>(HttpStatus.CONFLICT); |
| 75 | +// } |
| 76 | +// |
| 77 | +// return ResponseEntity.ok(mainScreenInfoList); |
| 78 | +// } |
| 79 | +// |
| 80 | +// |
| 81 | +// @GetMapping("/tabs") |
| 82 | +// public ResponseEntity<?> getHomeTabsDataResponse(){ |
| 83 | +// HomeTabsDataResponse homeTabsDataResponse = commonDataService.getBrandsAndApparelsByGender("tabsAPI"); |
| 84 | +// if(homeTabsDataResponse == null) |
| 85 | +// { |
| 86 | +// return new ResponseEntity<Error>(HttpStatus.CONFLICT); |
| 87 | +// } |
| 88 | +// |
| 89 | +// return ResponseEntity.ok(homeTabsDataResponse); |
| 90 | +// } |
| 91 | +// |
| 92 | +// |
| 93 | +// @GetMapping(value = "/filter", params = "q") |
| 94 | +// public ResponseEntity<?> getFilterAttributesProducts(@RequestParam("g") String queryParams) { |
| 95 | +// String[] splitParams = queryParams.split("="); |
| 96 | +// if (splitParams.length >= 1 && splitParams[0].equals("productname")) { |
| 97 | +// queryParams = "category=all"; |
| 98 | +// } |
| 99 | +// |
| 100 | +// FilterAttributesResponse result = commonDataService.getFilterAttributesByProducts(queryParams); |
| 101 | +// |
| 102 | +// if (result == null) { |
| 103 | +// return ResponseEntity.badRequest().body("Query has not followed the required format."); |
| 104 | +// } |
| 105 | +// |
| 106 | +// return ResponseEntity.ok(result); |
| 107 | +// } |
| 108 | +// |
| 109 | +// @GetMapping("/search-suggestion-list") |
| 110 | +// public ResponseEntity<?> getSearchSuggestionList() { |
| 111 | +// SearchSuggestionResponse searchSuggestionResponse = commonDataService.getSearchSuggestionList(); |
| 112 | +// if (searchSuggestionResponse == null) { |
| 113 | +// return new ResponseEntity<Error>(HttpStatus.CONFLICT); |
| 114 | +// } |
| 115 | +// |
| 116 | +// return ResponseEntity.ok(searchSuggestionResponse); |
| 117 | +// } |
| 118 | +//} |
0 commit comments