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