| 21292 |
ashik.ali |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
| 21448 |
ashik.ali |
3 |
import java.util.Set;
|
|
|
4 |
|
| 21292 |
ashik.ali |
5 |
import javax.servlet.http.HttpServletRequest;
|
|
|
6 |
|
| 21463 |
ashik.ali |
7 |
import org.apache.thrift.TException;
|
|
|
8 |
import org.apache.thrift.transport.TTransportException;
|
| 21292 |
ashik.ali |
9 |
import org.slf4j.Logger;
|
|
|
10 |
import org.slf4j.LoggerFactory;
|
|
|
11 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
12 |
import org.springframework.http.ResponseEntity;
|
|
|
13 |
import org.springframework.stereotype.Controller;
|
| 21692 |
amit.gupta |
14 |
import org.springframework.transaction.annotation.Transactional;
|
| 21309 |
ashik.ali |
15 |
import org.springframework.web.bind.annotation.RequestBody;
|
| 21292 |
ashik.ali |
16 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
17 |
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
18 |
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
19 |
|
|
|
20 |
import com.spice.profitmandi.common.ResponseCodeHolder;
|
|
|
21 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
|
|
22 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 21463 |
ashik.ali |
23 |
import com.spice.profitmandi.common.model.UserInfo;
|
| 21740 |
ashik.ali |
24 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
| 21735 |
ashik.ali |
25 |
import com.spice.profitmandi.dao.entity.dtr.Brand;
|
|
|
26 |
import com.spice.profitmandi.dao.entity.dtr.Document;
|
|
|
27 |
import com.spice.profitmandi.dao.entity.dtr.Retailer;
|
|
|
28 |
import com.spice.profitmandi.dao.entity.dtr.RetailerBrand;
|
|
|
29 |
import com.spice.profitmandi.dao.entity.dtr.RetailerRegisteredAddress;
|
|
|
30 |
import com.spice.profitmandi.dao.entity.dtr.Shop;
|
|
|
31 |
import com.spice.profitmandi.dao.entity.dtr.ShopAddress;
|
|
|
32 |
import com.spice.profitmandi.dao.entity.dtr.User;
|
|
|
33 |
import com.spice.profitmandi.dao.entity.user.Address;
|
|
|
34 |
import com.spice.profitmandi.dao.repository.dtr.BrandRepository;
|
|
|
35 |
import com.spice.profitmandi.dao.repository.dtr.DocumentRepository;
|
|
|
36 |
import com.spice.profitmandi.dao.repository.dtr.RetailerAddressRepository;
|
|
|
37 |
import com.spice.profitmandi.dao.repository.dtr.RetailerBrandRepository;
|
|
|
38 |
import com.spice.profitmandi.dao.repository.dtr.RetailerRegisteredAddressRepository;
|
|
|
39 |
import com.spice.profitmandi.dao.repository.dtr.RetailerRepository;
|
|
|
40 |
import com.spice.profitmandi.dao.repository.dtr.ShopAddressRepository;
|
|
|
41 |
import com.spice.profitmandi.dao.repository.dtr.ShopRepository;
|
|
|
42 |
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
|
|
|
43 |
import com.spice.profitmandi.dao.repository.user.AddressRepository;
|
| 21463 |
ashik.ali |
44 |
import com.spice.profitmandi.thrift.clients.UserClient;
|
| 21431 |
ashik.ali |
45 |
import com.spice.profitmandi.web.req.Category;
|
| 21426 |
ashik.ali |
46 |
import com.spice.profitmandi.web.req.CreateRetailerAddressRequest;
|
|
|
47 |
import com.spice.profitmandi.web.req.CreateRetailerRequest;
|
|
|
48 |
import com.spice.profitmandi.web.req.RetailerAddBrandRequest;
|
| 21292 |
ashik.ali |
49 |
|
| 21463 |
ashik.ali |
50 |
import in.shop2020.model.v1.user.Sex;
|
|
|
51 |
import in.shop2020.model.v1.user.UserContextException;
|
| 21302 |
ashik.ali |
52 |
import io.swagger.annotations.ApiImplicitParam;
|
|
|
53 |
import io.swagger.annotations.ApiImplicitParams;
|
|
|
54 |
import io.swagger.annotations.ApiOperation;
|
|
|
55 |
|
| 21292 |
ashik.ali |
56 |
@Controller
|
| 21692 |
amit.gupta |
57 |
@Transactional
|
| 21292 |
ashik.ali |
58 |
public class RetailerController {
|
|
|
59 |
|
|
|
60 |
private static final Logger LOGGER=LoggerFactory.getLogger(RetailerController.class);
|
|
|
61 |
|
|
|
62 |
@Autowired
|
| 21463 |
ashik.ali |
63 |
UserRepository userRepository;
|
|
|
64 |
|
|
|
65 |
@Autowired
|
| 21440 |
ashik.ali |
66 |
ResponseSender<?> responseSender;
|
|
|
67 |
|
|
|
68 |
@Autowired
|
| 21292 |
ashik.ali |
69 |
RetailerRepository retailerRepository;
|
|
|
70 |
|
| 21390 |
ashik.ali |
71 |
@Autowired
|
|
|
72 |
BrandRepository brandRepository;
|
|
|
73 |
|
|
|
74 |
@Autowired
|
|
|
75 |
AddressRepository addressRepository;
|
|
|
76 |
|
|
|
77 |
@Autowired
|
|
|
78 |
DocumentRepository documentRepository;
|
|
|
79 |
|
|
|
80 |
@Autowired
|
|
|
81 |
ShopRepository shopRepository;
|
|
|
82 |
|
|
|
83 |
@Autowired
|
|
|
84 |
RetailerRegisteredAddressRepository retailerRegisteredAddressRepository;
|
|
|
85 |
|
|
|
86 |
@Autowired
|
| 21426 |
ashik.ali |
87 |
RetailerAddressRepository retailerAddressRepository;
|
|
|
88 |
|
|
|
89 |
@Autowired
|
| 21390 |
ashik.ali |
90 |
ShopAddressRepository shopAddressRepository;
|
|
|
91 |
|
|
|
92 |
@Autowired
|
|
|
93 |
RetailerBrandRepository retailerBrandRepository;
|
|
|
94 |
|
| 21302 |
ashik.ali |
95 |
@ApiImplicitParams({
|
|
|
96 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token",
|
|
|
97 |
required = true, dataType = "string", paramType = "header")
|
|
|
98 |
})
|
| 21309 |
ashik.ali |
99 |
|
| 21302 |
ashik.ali |
100 |
@ApiOperation(value = "Create Retailer")
|
|
|
101 |
@RequestMapping(value = ProfitMandiConstants.URL_RETAILER, method=RequestMethod.POST)
|
| 21426 |
ashik.ali |
102 |
public ResponseEntity<?> createRetailer(HttpServletRequest request, @RequestBody CreateRetailerRequest createRetailerRequest){
|
| 21292 |
ashik.ali |
103 |
LOGGER.info("requested url : "+request.getRequestURL().toString());
|
| 21440 |
ashik.ali |
104 |
try{
|
| 21691 |
amit.gupta |
105 |
UserInfo userInfo = (UserInfo)request.getAttribute("userInfo");
|
| 21463 |
ashik.ali |
106 |
User user = userRepository.selectById(userInfo.getUserId());
|
|
|
107 |
this.createRetailer(user.getEmailId(), createRetailerRequest);
|
| 21440 |
ashik.ali |
108 |
return responseSender.ok(ResponseCodeHolder.getMessage("RTLR_OK_1000"));
|
|
|
109 |
}catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
|
|
110 |
LOGGER.error("ProfitMandi error: ", profitMandiBusinessException);
|
|
|
111 |
return responseSender.badRequest(profitMandiBusinessException);
|
|
|
112 |
}
|
|
|
113 |
}
|
|
|
114 |
|
| 21463 |
ashik.ali |
115 |
private void createRetailer(String emailId, CreateRetailerRequest createRetailerRequest)
|
| 21440 |
ashik.ali |
116 |
throws ProfitMandiBusinessException{
|
| 21390 |
ashik.ali |
117 |
Retailer retailer = new Retailer();
|
| 21426 |
ashik.ali |
118 |
retailer.setName(createRetailerRequest.getName());
|
|
|
119 |
retailer.setNumber(createRetailerRequest.getNumber());
|
|
|
120 |
retailer.setType(createRetailerRequest.getType());
|
|
|
121 |
retailer.setMonthlySaleValue(createRetailerRequest.getMonthlySaleValue());
|
|
|
122 |
retailer.setSmartphoneSaleValue(createRetailerRequest.getSmartphoneSaleValue());
|
|
|
123 |
retailer.setRecharge(createRetailerRequest.getLineOfBusiness().isRecharge());
|
|
|
124 |
retailer.setMobile(createRetailerRequest.getLineOfBusiness().isMobile());
|
|
|
125 |
retailer.setAccessories(createRetailerRequest.getLineOfBusiness().isAccessories());
|
| 21431 |
ashik.ali |
126 |
retailer.setOther1(createRetailerRequest.getLineOfBusiness().getOther1());
|
|
|
127 |
retailer.setOther2(createRetailerRequest.getLineOfBusiness().getOther2());
|
| 21440 |
ashik.ali |
128 |
Document retailerDocument = documentRepository.selectById(createRetailerRequest.getDocumentId());
|
|
|
129 |
if(retailerRepository.isExistByDocumentId(retailerDocument.getId())){
|
|
|
130 |
LOGGER.error("documet is already mapped with another retailer");
|
| 21448 |
ashik.ali |
131 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.DOCUMENT_ID, retailerDocument.getId(), "DCMNT_1000");
|
| 21440 |
ashik.ali |
132 |
}
|
|
|
133 |
retailer.setDocumentId(retailerDocument.getId());
|
|
|
134 |
final Document shopDocument = documentRepository.selectById(createRetailerRequest.getShop().getDocumentId());
|
|
|
135 |
if(shopRepository.isExistByDocumentId(shopDocument.getId())){
|
| 21448 |
ashik.ali |
136 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.DOCUMENT_ID, shopDocument.getId(), "DCMNT_1000");
|
| 21440 |
ashik.ali |
137 |
}
|
| 21463 |
ashik.ali |
138 |
documentRepository.markDocumentAsPersisted(retailerDocument.getId());
|
| 21448 |
ashik.ali |
139 |
if(retailerRepository.isExistByNumberAndType(retailer.getNumber(), retailer.getType())){
|
|
|
140 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.NUMBER + ", " + ProfitMandiConstants.TYPE, retailer.getNumber() + ", " + retailer.getType(), "RTLR_1001");
|
|
|
141 |
}
|
| 21463 |
ashik.ali |
142 |
documentRepository.markDocumentAsPersisted(shopDocument.getId());
|
|
|
143 |
retailer.setId(this.createSololicUser(emailId));
|
| 21440 |
ashik.ali |
144 |
retailerRepository.persist(retailer);
|
|
|
145 |
Shop shop = new Shop();
|
|
|
146 |
shop.setName(createRetailerRequest.getShop().getName());
|
|
|
147 |
shop.setDocumentId(shopDocument.getId());
|
|
|
148 |
shop.setRetailerId(retailer.getId());
|
|
|
149 |
shopRepository.persist(shop);
|
| 21448 |
ashik.ali |
150 |
this.addBrandWithRetailer(retailer.getId(), createRetailerRequest.getCategories());
|
| 21440 |
ashik.ali |
151 |
final Address addressRetailer = this.createAddress(createRetailerRequest.getAddress());
|
| 21706 |
amit.gupta |
152 |
addressRetailer.setRetaierId(retailer.getId());
|
| 21426 |
ashik.ali |
153 |
|
| 21440 |
ashik.ali |
154 |
if(!addressRepository.isExist(addressRetailer)){
|
|
|
155 |
addressRepository.persist(addressRetailer);
|
| 21292 |
ashik.ali |
156 |
}
|
| 21440 |
ashik.ali |
157 |
final RetailerRegisteredAddress retailerRegisteredAddress = new RetailerRegisteredAddress();
|
|
|
158 |
retailerRegisteredAddress.setRetailerId(retailer.getId());
|
|
|
159 |
retailerRegisteredAddress.setAddressId(addressRetailer.getId());
|
|
|
160 |
retailerRegisteredAddressRepository.persist(retailerRegisteredAddress);
|
| 21463 |
ashik.ali |
161 |
if(!createRetailerRequest.isShopAddressSameAsRetailerAddress() && createRetailerRequest.getAddress() == null){
|
|
|
162 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.ADDRESS, "", "");
|
| 21440 |
ashik.ali |
163 |
}
|
| 21463 |
ashik.ali |
164 |
if(createRetailerRequest.isShopAddressSameAsRetailerAddress()){
|
|
|
165 |
ShopAddress shopAddress = new ShopAddress();
|
|
|
166 |
shopAddress.setShopId(shop.getId());
|
|
|
167 |
shopAddress.setAddressId(addressRetailer.getId());
|
|
|
168 |
shopAddressRepository.persist(shopAddress);
|
|
|
169 |
}else{
|
|
|
170 |
final Address addressShop = this.createAddress(createRetailerRequest.getShop().getAddress());
|
|
|
171 |
if(!addressRepository.isExist(addressShop)){
|
|
|
172 |
addressRepository.persist(addressShop);
|
|
|
173 |
}
|
|
|
174 |
ShopAddress shopAddress = new ShopAddress();
|
|
|
175 |
shopAddress.setShopId(shop.getId());
|
|
|
176 |
shopAddress.setAddressId(addressShop.getId());
|
|
|
177 |
shopAddressRepository.persist(shopAddress);
|
|
|
178 |
}
|
| 21292 |
ashik.ali |
179 |
}
|
|
|
180 |
|
| 21463 |
ashik.ali |
181 |
private int createSololicUser(String emailId) throws ProfitMandiBusinessException{
|
|
|
182 |
in.shop2020.model.v1.user.User user = new in.shop2020.model.v1.user.User();
|
|
|
183 |
user.setEmail(emailId);
|
|
|
184 |
user.setPassword("");
|
|
|
185 |
user.setCommunicationEmail(emailId);
|
|
|
186 |
user.setSex(Sex.WONT_SAY);
|
|
|
187 |
|
|
|
188 |
try {
|
|
|
189 |
UserClient userContextServiceClient = new UserClient();
|
|
|
190 |
in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
|
|
|
191 |
user = userClient.createUser(user);
|
|
|
192 |
return (int)user.getUserId();
|
|
|
193 |
}catch (UserContextException ux){
|
|
|
194 |
LOGGER.error("Unable to register user: " + ux.getMessage());
|
|
|
195 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.EMAIL_ID, emailId, "");
|
|
|
196 |
} catch (TTransportException e) {
|
|
|
197 |
LOGGER.error("Unable to register user." + e);
|
|
|
198 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.EMAIL_ID, emailId, "");
|
|
|
199 |
}catch (TException e) {
|
|
|
200 |
LOGGER.error("Unable to register user." + e);
|
|
|
201 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.EMAIL_ID, emailId, "");
|
|
|
202 |
}
|
|
|
203 |
}
|
| 21448 |
ashik.ali |
204 |
private void addBrandWithRetailer(int retailerId, Set<Category> categories)
|
|
|
205 |
throws ProfitMandiBusinessException{
|
|
|
206 |
for(Category category : categories){
|
|
|
207 |
for(com.spice.profitmandi.web.req.Brand brandModel : category.getBrands()){
|
|
|
208 |
Brand brand = brandRepository.selectByIdAndName(brandModel.getId(), brandModel.getName());
|
|
|
209 |
final RetailerBrand retailerBrand = new RetailerBrand();
|
|
|
210 |
retailerBrand.setRetailerId(retailerId);
|
|
|
211 |
retailerBrand.setBrandId(brand.getId());
|
|
|
212 |
retailerBrandRepository.persist(retailerBrand);
|
|
|
213 |
}
|
|
|
214 |
}
|
|
|
215 |
}
|
| 21292 |
ashik.ali |
216 |
@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_ALL,method=RequestMethod.GET)
|
| 21496 |
ashik.ali |
217 |
public ResponseEntity<?> getAll(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.PAGE_NUMBER) int pageNumber, @RequestParam(name = ProfitMandiConstants.PAGE_SIZE) int pageSize){
|
| 21292 |
ashik.ali |
218 |
LOGGER.info("requested url : "+request.getRequestURL().toString());
|
| 21496 |
ashik.ali |
219 |
return responseSender.ok(retailerRepository.selectAll(pageNumber, pageSize));
|
| 21292 |
ashik.ali |
220 |
}
|
|
|
221 |
@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_ID, method=RequestMethod.GET)
|
| 21431 |
ashik.ali |
222 |
public ResponseEntity<?> getById(HttpServletRequest request, @RequestParam(name = "id") int id){
|
| 21292 |
ashik.ali |
223 |
LOGGER.info("requested url : "+request.getRequestURL().toString());
|
|
|
224 |
try {
|
| 21440 |
ashik.ali |
225 |
return responseSender.ok(retailerRepository.selectById(id));
|
|
|
226 |
}catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
|
|
227 |
LOGGER.error("ProfitMandi error: ", profitMandiBusinessException);
|
|
|
228 |
return responseSender.badRequest(profitMandiBusinessException);
|
| 21292 |
ashik.ali |
229 |
}
|
|
|
230 |
}
|
|
|
231 |
|
|
|
232 |
@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_NAME, method=RequestMethod.GET)
|
|
|
233 |
public ResponseEntity<?> getByName(HttpServletRequest request, @RequestParam(name = "name") String name){
|
|
|
234 |
LOGGER.info("requested url : "+request.getRequestURL().toString());
|
|
|
235 |
try {
|
| 21440 |
ashik.ali |
236 |
return responseSender.ok(retailerRepository.selectByName(name));
|
|
|
237 |
}catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
|
|
238 |
LOGGER.error("ProfitMandi error: ", profitMandiBusinessException);
|
|
|
239 |
return responseSender.badRequest(profitMandiBusinessException);
|
| 21292 |
ashik.ali |
240 |
}
|
|
|
241 |
}
|
|
|
242 |
|
|
|
243 |
|
|
|
244 |
@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_ID,method=RequestMethod.DELETE)
|
| 21431 |
ashik.ali |
245 |
public ResponseEntity<?> removeById(HttpServletRequest request, @RequestParam(name = "id") int id){
|
| 21292 |
ashik.ali |
246 |
LOGGER.info("requested url : "+request.getRequestURL().toString());
|
|
|
247 |
try {
|
|
|
248 |
retailerRepository.deleteById(id);
|
| 21440 |
ashik.ali |
249 |
return responseSender.ok(ResponseCodeHolder.getMessage("API_OK_1001"));
|
|
|
250 |
}catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
|
|
251 |
LOGGER.error("ProfitMandi error: ", profitMandiBusinessException);
|
|
|
252 |
return responseSender.badRequest(profitMandiBusinessException);
|
| 21292 |
ashik.ali |
253 |
}
|
|
|
254 |
}
|
|
|
255 |
|
| 21426 |
ashik.ali |
256 |
@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_SHOP_ADD, method=RequestMethod.POST)
|
| 21431 |
ashik.ali |
257 |
public ResponseEntity<?> addShop(HttpServletRequest request, @RequestBody com.spice.profitmandi.web.req.Shop createShop, @RequestParam(name = "retailerId") int retailerId){
|
| 21426 |
ashik.ali |
258 |
LOGGER.info("requested url : "+request.getRequestURL().toString());
|
|
|
259 |
try {
|
|
|
260 |
Document document = documentRepository.selectById(createShop.getDocumentId());
|
|
|
261 |
if(shopRepository.isExistByDocumentId(createShop.getDocumentId())){
|
|
|
262 |
LOGGER.error("documet is already mapped with another shop");
|
|
|
263 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.DOCUMENT_ID, document.getId(), "");
|
|
|
264 |
}
|
|
|
265 |
retailerRepository.selectById(retailerId);
|
|
|
266 |
Shop shop = new Shop();
|
|
|
267 |
shop.setRetailerId(retailerId);
|
|
|
268 |
Address address = this.createAddress(createShop.getAddress());
|
|
|
269 |
addressRepository.persist(address);
|
|
|
270 |
shop.setAddressId(address.getId());
|
|
|
271 |
shop.setDocumentId(document.getId());
|
|
|
272 |
shopRepository.persist(shop);
|
|
|
273 |
ShopAddress shopAddress = new ShopAddress();
|
|
|
274 |
shopAddress.setAddressId(address.getId());
|
|
|
275 |
shopAddress.setShopId(shop.getId());
|
|
|
276 |
shopAddressRepository.persist(shopAddress);
|
| 21440 |
ashik.ali |
277 |
return responseSender.ok(ResponseCodeHolder.getMessage("API_OK_1001"));
|
|
|
278 |
}catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
|
|
279 |
LOGGER.error("ProfitMandi error: ", profitMandiBusinessException);
|
|
|
280 |
return responseSender.badRequest(profitMandiBusinessException);
|
| 21426 |
ashik.ali |
281 |
}
|
|
|
282 |
}
|
|
|
283 |
|
|
|
284 |
|
| 21302 |
ashik.ali |
285 |
@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_SHOP_REMOVE, method=RequestMethod.DELETE)
|
| 21431 |
ashik.ali |
286 |
public ResponseEntity<?> removeShop(HttpServletRequest request, @RequestParam(name = "shopId") int shopId, @RequestParam(name = "retailerId") int retailerId){
|
| 21292 |
ashik.ali |
287 |
LOGGER.info("requested url : "+request.getRequestURL().toString());
|
|
|
288 |
try {
|
|
|
289 |
retailerRepository.removeShop(shopId, retailerId);
|
| 21440 |
ashik.ali |
290 |
return responseSender.ok(ResponseCodeHolder.getMessage("API_OK_1001"));
|
|
|
291 |
}catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
|
|
292 |
LOGGER.error("ProfitMandi error: ", profitMandiBusinessException);
|
|
|
293 |
return responseSender.badRequest(profitMandiBusinessException);
|
| 21292 |
ashik.ali |
294 |
}
|
|
|
295 |
}
|
|
|
296 |
|
| 21426 |
ashik.ali |
297 |
private Address createAddress(com.spice.profitmandi.web.req.Address createAddress){
|
|
|
298 |
Address address = new Address();
|
|
|
299 |
address.setName(createAddress.getName());
|
|
|
300 |
address.setLine1(createAddress.getLine1());
|
|
|
301 |
address.setLine2(createAddress.getLine2());
|
|
|
302 |
address.setLandmark(createAddress.getLandmark());
|
|
|
303 |
address.setCity(createAddress.getCity());
|
|
|
304 |
address.setState(createAddress.getState());
|
|
|
305 |
address.setPinCode(createAddress.getPinCode());
|
|
|
306 |
address.setCountry(createAddress.getCountry());
|
|
|
307 |
address.setPhoneNumber(createAddress.getPhoneNumber());
|
| 21706 |
amit.gupta |
308 |
|
| 21426 |
ashik.ali |
309 |
return address;
|
|
|
310 |
}
|
| 21440 |
ashik.ali |
311 |
|
| 21426 |
ashik.ali |
312 |
@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_ADDRESS_ADD, method=RequestMethod.POST)
|
|
|
313 |
public ResponseEntity<?> addAddress(HttpServletRequest request, @RequestBody CreateRetailerAddressRequest createRetailerAddress){
|
|
|
314 |
LOGGER.info("requested url : "+request.getRequestURL().toString());
|
|
|
315 |
try {
|
|
|
316 |
retailerRepository.addAddress(this.createAddress(createRetailerAddress.getAddress()), createRetailerAddress.getRetailerId());
|
| 21440 |
ashik.ali |
317 |
return responseSender.ok(ResponseCodeHolder.getMessage("API_OK_1001"));
|
|
|
318 |
}catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
|
|
319 |
LOGGER.error("ProfitMandi error: ", profitMandiBusinessException);
|
|
|
320 |
return responseSender.badRequest(profitMandiBusinessException);
|
| 21426 |
ashik.ali |
321 |
}
|
|
|
322 |
}
|
| 21292 |
ashik.ali |
323 |
|
| 21426 |
ashik.ali |
324 |
@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_ADDRESS_REMOVE, method=RequestMethod.DELETE)
|
| 21431 |
ashik.ali |
325 |
public ResponseEntity<?> removeAddress(HttpServletRequest request, @RequestParam(name = "addressId") int addressId, @RequestParam(name = "retailerId") int retailerId){
|
| 21426 |
ashik.ali |
326 |
LOGGER.info("requested url : "+request.getRequestURL().toString());
|
|
|
327 |
try {
|
|
|
328 |
retailerRepository.removeAddress(addressId, retailerId);
|
| 21440 |
ashik.ali |
329 |
return responseSender.ok(ResponseCodeHolder.getMessage("API_OK_1001"));
|
|
|
330 |
}catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
|
|
331 |
LOGGER.error("ProfitMandi error: ", profitMandiBusinessException);
|
|
|
332 |
return responseSender.badRequest(profitMandiBusinessException);
|
| 21426 |
ashik.ali |
333 |
}
|
|
|
334 |
}
|
|
|
335 |
|
|
|
336 |
@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_BRAND_ADD, method=RequestMethod.POST)
|
|
|
337 |
public ResponseEntity<?> addBrand(HttpServletRequest request, @RequestBody RetailerAddBrandRequest retailerAddBrandRequest){
|
|
|
338 |
LOGGER.info("requested url : "+request.getRequestURL().toString());
|
|
|
339 |
try {
|
| 21448 |
ashik.ali |
340 |
retailerRepository.selectById(retailerAddBrandRequest.getRetailerId());
|
|
|
341 |
this.addBrandWithRetailer(retailerAddBrandRequest.getRetailerId(), retailerAddBrandRequest.getCategories());
|
| 21440 |
ashik.ali |
342 |
return responseSender.ok(ResponseCodeHolder.getMessage("API_OK_1001"));
|
|
|
343 |
}catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
|
|
344 |
LOGGER.error("ProfitMandi error: ", profitMandiBusinessException);
|
|
|
345 |
return responseSender.badRequest(profitMandiBusinessException);
|
| 21426 |
ashik.ali |
346 |
}
|
|
|
347 |
}
|
|
|
348 |
|
|
|
349 |
@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_BRAND_REMOVE, method=RequestMethod.DELETE)
|
| 21431 |
ashik.ali |
350 |
public ResponseEntity<?> removeBrand(HttpServletRequest request, @RequestParam(name = "brandId") int brandId, @RequestParam(name = "retailerId") int retailerId){
|
| 21426 |
ashik.ali |
351 |
LOGGER.info("requested url : "+request.getRequestURL().toString());
|
|
|
352 |
try {
|
|
|
353 |
brandRepository.selectById(brandId);
|
|
|
354 |
retailerRepository.selectById(retailerId);
|
| 21448 |
ashik.ali |
355 |
retailerBrandRepository.deleteByRetailerAndBrandId(retailerId, brandId);
|
| 21440 |
ashik.ali |
356 |
return responseSender.ok(ResponseCodeHolder.getMessage("API_OK_1001"));
|
|
|
357 |
}catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
|
|
358 |
LOGGER.error("ProfitMandi error: ", profitMandiBusinessException);
|
|
|
359 |
return responseSender.badRequest(profitMandiBusinessException);
|
| 21426 |
ashik.ali |
360 |
}
|
|
|
361 |
}
|
|
|
362 |
|
|
|
363 |
|
| 21448 |
ashik.ali |
364 |
@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_DOCUMENT, method=RequestMethod.GET)
|
|
|
365 |
public ResponseEntity<?> getDocumentById(HttpServletRequest request, @RequestParam(name = "retailerId") int retailerId){
|
| 21426 |
ashik.ali |
366 |
LOGGER.info("requested url : "+request.getRequestURL().toString());
|
|
|
367 |
try {
|
| 21448 |
ashik.ali |
368 |
return responseSender.ok(retailerRepository.selectDocumentById(retailerId));
|
| 21440 |
ashik.ali |
369 |
}catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
|
|
370 |
LOGGER.error("ProfitMandi error: ", profitMandiBusinessException);
|
|
|
371 |
return responseSender.badRequest(profitMandiBusinessException);
|
| 21426 |
ashik.ali |
372 |
}
|
|
|
373 |
}
|
|
|
374 |
|
| 21448 |
ashik.ali |
375 |
@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_REGISTERED_ADDRESS, method=RequestMethod.GET)
|
|
|
376 |
public ResponseEntity<?> getRegisteredAddressById(HttpServletRequest request, @RequestParam(name = "retailerId") int retailerId){
|
|
|
377 |
LOGGER.info("requested url : "+request.getRequestURL().toString());
|
|
|
378 |
try {
|
| 21698 |
amit.gupta |
379 |
return responseSender.ok(retailerRegisteredAddressRepository.selectAddressIdByRetailerId(retailerId));
|
| 21448 |
ashik.ali |
380 |
}catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
|
|
381 |
LOGGER.error("ProfitMandi error: ", profitMandiBusinessException);
|
|
|
382 |
return responseSender.badRequest(profitMandiBusinessException);
|
|
|
383 |
}
|
|
|
384 |
}
|
|
|
385 |
|
| 21426 |
ashik.ali |
386 |
@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_SHOP_ALL, method=RequestMethod.GET)
|
| 21431 |
ashik.ali |
387 |
public ResponseEntity<?> getAllShops(HttpServletRequest request, @RequestParam(name = "id") int id){
|
| 21426 |
ashik.ali |
388 |
LOGGER.info("requested url : "+request.getRequestURL().toString());
|
|
|
389 |
try {
|
| 21440 |
ashik.ali |
390 |
return responseSender.ok(shopRepository.selectByRetailerId(id));
|
|
|
391 |
}catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
|
|
392 |
LOGGER.error("ProfitMandi error: ", profitMandiBusinessException);
|
|
|
393 |
return responseSender.badRequest(profitMandiBusinessException);
|
| 21426 |
ashik.ali |
394 |
}
|
|
|
395 |
}
|
|
|
396 |
|
|
|
397 |
@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_ADDRESS_ALL, method=RequestMethod.GET)
|
| 21431 |
ashik.ali |
398 |
public ResponseEntity<?> getAllAddresses(HttpServletRequest request, @RequestParam(name = "id") int id){
|
| 21426 |
ashik.ali |
399 |
LOGGER.info("requested url : "+request.getRequestURL().toString());
|
| 21440 |
ashik.ali |
400 |
return responseSender.ok(retailerAddressRepository.selectAddressesByRetailerId(id));
|
| 21426 |
ashik.ali |
401 |
}
|
|
|
402 |
|
|
|
403 |
|
|
|
404 |
@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_BRAND_ALL, method=RequestMethod.GET)
|
| 21431 |
ashik.ali |
405 |
public ResponseEntity<?> getAllBrads(HttpServletRequest request, @RequestParam(name = "id") int id){
|
| 21426 |
ashik.ali |
406 |
LOGGER.info("requested url : "+request.getRequestURL().toString());
|
| 21440 |
ashik.ali |
407 |
return responseSender.ok(retailerBrandRepository.selectBrandNamesByRetailerId(id));
|
| 21426 |
ashik.ali |
408 |
}
|
|
|
409 |
|
| 21292 |
ashik.ali |
410 |
}
|