| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.web.controller;
|
1 |
package com.spice.profitmandi.web.controller;
|
| 2 |
|
2 |
|
| 3 |
import java.time.LocalDateTime;
|
3 |
import java.time.LocalDateTime;
|
| - |
|
4 |
import java.util.Comparator;
|
| - |
|
5 |
import java.util.List;
|
| - |
|
6 |
import java.util.stream.Collectors;
|
| 4 |
|
7 |
|
| 5 |
import javax.servlet.http.HttpServletRequest;
|
8 |
import javax.servlet.http.HttpServletRequest;
|
| 6 |
|
9 |
|
| 7 |
import org.json.JSONObject;
|
10 |
import org.json.JSONObject;
|
| 8 |
import org.apache.logging.log4j.Logger;
|
11 |
import org.apache.logging.log4j.Logger;
|
| Line 21... |
Line 24... |
| 21 |
import com.spice.profitmandi.common.model.ProfitMandiResponse;
|
24 |
import com.spice.profitmandi.common.model.ProfitMandiResponse;
|
| 22 |
import com.spice.profitmandi.common.model.ResponseStatus;
|
25 |
import com.spice.profitmandi.common.model.ResponseStatus;
|
| 23 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
26 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
| 24 |
import com.spice.profitmandi.dao.model.LimitedMasterDataPojo;
|
27 |
import com.spice.profitmandi.dao.model.LimitedMasterDataPojo;
|
| 25 |
import com.spice.profitmandi.dao.repository.dtr.Mongo;
|
28 |
import com.spice.profitmandi.dao.repository.dtr.Mongo;
|
| - |
|
29 |
import com.spice.profitmandi.dao.repository.inventory.StateRepository;
|
| 26 |
|
30 |
|
| 27 |
import io.swagger.annotations.ApiImplicitParam;
|
31 |
import io.swagger.annotations.ApiImplicitParam;
|
| 28 |
import io.swagger.annotations.ApiImplicitParams;
|
32 |
import io.swagger.annotations.ApiImplicitParams;
|
| 29 |
import io.swagger.annotations.ApiOperation;
|
33 |
import io.swagger.annotations.ApiOperation;
|
| 30 |
|
34 |
|
| Line 36... |
Line 40... |
| 36 |
@Autowired
|
40 |
@Autowired
|
| 37 |
private Mongo mongoClient;
|
41 |
private Mongo mongoClient;
|
| 38 |
|
42 |
|
| 39 |
@Autowired
|
43 |
@Autowired
|
| 40 |
private ResponseSender<?> responseSender;
|
44 |
private ResponseSender<?> responseSender;
|
| - |
|
45 |
|
| - |
|
46 |
@Autowired
|
| - |
|
47 |
private StateRepository stateRepository;
|
| 41 |
|
48 |
|
| 42 |
|
49 |
|
| 43 |
@RequestMapping(value = ProfitMandiConstants.URL_MASTER_DATA, method=RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
|
50 |
@RequestMapping(value = ProfitMandiConstants.URL_MASTER_DATA, method=RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
|
| 44 |
@ApiImplicitParams({
|
51 |
@ApiImplicitParams({
|
| 45 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token",
|
52 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token",
|
| 46 |
required = true, dataType = "string", paramType = "header")
|
53 |
required = true, dataType = "string", paramType = "header")
|
| 47 |
})
|
54 |
})
|
| 48 |
@ApiOperation(value = "Get limited info of master data for skuBundleId")
|
55 |
@ApiOperation(value = "Get limited info of master data for skuBundleId")
|
| 49 |
public ResponseEntity<?> getMasterDataBySkuBundleId(HttpServletRequest request, @PathVariable(value="id") long skuBundleId) throws Exception{
|
56 |
public ResponseEntity<?> getMasterDataBySkuBundleId(HttpServletRequest request, @PathVariable(value="id") long skuBundleId) throws Exception{
|
| 50 |
|
57 |
|
| 51 |
JSONObject jsonObject = mongoClient.getItemsByBundleId(skuBundleId);
|
58 |
JSONObject jsonObject = mongoClient.getItemsByBundleId(skuBundleId);
|
| 52 |
LimitedMasterDataPojo masterData = new Gson().fromJson(jsonObject.toString(), LimitedMasterDataPojo.class);
|
59 |
LimitedMasterDataPojo masterData = new Gson().fromJson(jsonObject.toString(), LimitedMasterDataPojo.class);
|
| 53 |
return responseSender.ok(masterData);
|
60 |
return responseSender.ok(masterData);
|
| 54 |
}
|
61 |
}
|
| - |
|
62 |
|
| - |
|
63 |
/**
|
| - |
|
64 |
* The canonical state list, straight from inventory.statemaster.
|
| - |
|
65 |
*
|
| - |
|
66 |
* <p>Clients must render their state pickers from this rather than carrying their own list.
|
| - |
|
67 |
* Every stored state string is later resolved back through the same master by name, so a
|
| - |
|
68 |
* client-side list that has drifted writes values nothing can resolve - which is how invoices
|
| - |
|
69 |
* ended up with states like "Daman & Diu" that no longer exist in the master. Serving the
|
| - |
|
70 |
* list here means a correction to the master reaches every client without an app release.
|
| - |
|
71 |
*/
|
| - |
|
72 |
@RequestMapping(value = ProfitMandiConstants.URL_MASTER_STATES, method=RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
|
| - |
|
73 |
@ApiImplicitParams({
|
| - |
|
74 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token",
|
| - |
|
75 |
required = true, dataType = "string", paramType = "header")
|
| - |
|
76 |
})
|
| - |
|
77 |
@ApiOperation(value = "Canonical state list (name + GST state code)")
|
| - |
|
78 |
public ResponseEntity<?> getStates(HttpServletRequest request) throws Exception {
|
| - |
|
79 |
List<StateModel> states = stateRepository.selectAll().stream()
|
| - |
|
80 |
.map(state -> new StateModel(state.getName(), state.getCode()))
|
| - |
|
81 |
.sorted(Comparator.comparing(StateModel::getName))
|
| - |
|
82 |
.collect(Collectors.toList());
|
| - |
|
83 |
return responseSender.ok(states);
|
| - |
|
84 |
}
|
| - |
|
85 |
|
| - |
|
86 |
/** A state as clients need it: the name they must store, and its GST state code. */
|
| - |
|
87 |
public static class StateModel {
|
| - |
|
88 |
|
| - |
|
89 |
private final String name;
|
| - |
|
90 |
private final String code;
|
| - |
|
91 |
|
| - |
|
92 |
StateModel(String name, String code) {
|
| - |
|
93 |
this.name = name;
|
| - |
|
94 |
this.code = code;
|
| - |
|
95 |
}
|
| - |
|
96 |
|
| - |
|
97 |
public String getName() {
|
| - |
|
98 |
return name;
|
| - |
|
99 |
}
|
| - |
|
100 |
|
| - |
|
101 |
public String getCode() {
|
| - |
|
102 |
return code;
|
| - |
|
103 |
}
|
| 55 |
|
104 |
}
|
| - |
|
105 |
|
| 56 |
}
|
106 |
}
|