| 21429 |
kshitij.so |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
|
|
3 |
import java.time.LocalDateTime;
|
| 37404 |
amit |
4 |
import java.util.Comparator;
|
|
|
5 |
import java.util.List;
|
|
|
6 |
import java.util.stream.Collectors;
|
| 21429 |
kshitij.so |
7 |
|
|
|
8 |
import javax.servlet.http.HttpServletRequest;
|
|
|
9 |
|
|
|
10 |
import org.json.JSONObject;
|
| 23568 |
govind |
11 |
import org.apache.logging.log4j.Logger;
|
|
|
12 |
import org.apache.logging.log4j.LogManager;
|
| 22173 |
amit.gupta |
13 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 21429 |
kshitij.so |
14 |
import org.springframework.http.HttpStatus;
|
|
|
15 |
import org.springframework.http.MediaType;
|
|
|
16 |
import org.springframework.http.ResponseEntity;
|
|
|
17 |
import org.springframework.stereotype.Controller;
|
|
|
18 |
import org.springframework.web.bind.annotation.PathVariable;
|
|
|
19 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
20 |
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
21 |
|
|
|
22 |
import com.google.gson.Gson;
|
|
|
23 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 21740 |
ashik.ali |
24 |
import com.spice.profitmandi.common.model.ProfitMandiResponse;
|
|
|
25 |
import com.spice.profitmandi.common.model.ResponseStatus;
|
| 22931 |
ashik.ali |
26 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
| 21429 |
kshitij.so |
27 |
import com.spice.profitmandi.dao.model.LimitedMasterDataPojo;
|
| 21735 |
ashik.ali |
28 |
import com.spice.profitmandi.dao.repository.dtr.Mongo;
|
| 37404 |
amit |
29 |
import com.spice.profitmandi.dao.repository.inventory.StateRepository;
|
| 21429 |
kshitij.so |
30 |
|
|
|
31 |
import io.swagger.annotations.ApiImplicitParam;
|
|
|
32 |
import io.swagger.annotations.ApiImplicitParams;
|
|
|
33 |
import io.swagger.annotations.ApiOperation;
|
|
|
34 |
|
|
|
35 |
@Controller
|
|
|
36 |
public class MasterDataController {
|
|
|
37 |
|
| 23568 |
govind |
38 |
private static final Logger logger=LogManager.getLogger(MasterDataController.class);
|
| 21429 |
kshitij.so |
39 |
|
| 22931 |
ashik.ali |
40 |
@Autowired
|
|
|
41 |
private Mongo mongoClient;
|
| 22173 |
amit.gupta |
42 |
|
|
|
43 |
@Autowired
|
| 22931 |
ashik.ali |
44 |
private ResponseSender<?> responseSender;
|
| 37404 |
amit |
45 |
|
|
|
46 |
@Autowired
|
|
|
47 |
private StateRepository stateRepository;
|
| 22173 |
amit.gupta |
48 |
|
|
|
49 |
|
| 21429 |
kshitij.so |
50 |
@RequestMapping(value = ProfitMandiConstants.URL_MASTER_DATA, method=RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
51 |
@ApiImplicitParams({
|
| 37404 |
amit |
52 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token",
|
| 21429 |
kshitij.so |
53 |
required = true, dataType = "string", paramType = "header")
|
|
|
54 |
})
|
|
|
55 |
@ApiOperation(value = "Get limited info of master data for skuBundleId")
|
| 22931 |
ashik.ali |
56 |
public ResponseEntity<?> getMasterDataBySkuBundleId(HttpServletRequest request, @PathVariable(value="id") long skuBundleId) throws Exception{
|
| 37404 |
amit |
57 |
|
| 22931 |
ashik.ali |
58 |
JSONObject jsonObject = mongoClient.getItemsByBundleId(skuBundleId);
|
|
|
59 |
LimitedMasterDataPojo masterData = new Gson().fromJson(jsonObject.toString(), LimitedMasterDataPojo.class);
|
|
|
60 |
return responseSender.ok(masterData);
|
| 21429 |
kshitij.so |
61 |
}
|
| 37404 |
amit |
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 |
}
|
|
|
104 |
}
|
|
|
105 |
|
| 21429 |
kshitij.so |
106 |
}
|