| 27417 |
tejbeer |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
|
|
3 |
import java.time.LocalDateTime;
|
|
|
4 |
|
|
|
5 |
import javax.servlet.http.HttpServletRequest;
|
|
|
6 |
|
|
|
7 |
import org.apache.logging.log4j.LogManager;
|
|
|
8 |
import org.apache.logging.log4j.Logger;
|
|
|
9 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
10 |
import org.springframework.http.MediaType;
|
|
|
11 |
import org.springframework.http.ResponseEntity;
|
|
|
12 |
import org.springframework.stereotype.Controller;
|
|
|
13 |
import org.springframework.transaction.annotation.Transactional;
|
|
|
14 |
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
15 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
16 |
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
17 |
|
|
|
18 |
import com.google.gson.Gson;
|
|
|
19 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
|
|
20 |
import com.spice.profitmandi.dao.entity.dtr.HyperTrackKeyModel;
|
|
|
21 |
import com.spice.profitmandi.dao.entity.dtr.HypertrackKey;
|
|
|
22 |
import com.spice.profitmandi.dao.repository.user.HypertrackKeyRepository;
|
|
|
23 |
|
|
|
24 |
import io.swagger.annotations.ApiImplicitParam;
|
|
|
25 |
import io.swagger.annotations.ApiImplicitParams;
|
|
|
26 |
import io.swagger.annotations.ApiOperation;
|
|
|
27 |
|
|
|
28 |
@Controller
|
|
|
29 |
@Transactional(rollbackFor = Throwable.class)
|
|
|
30 |
public class HyperTrackController {
|
|
|
31 |
|
|
|
32 |
private static final Logger LOGGER = LogManager.getLogger(HyperTrackController.class);
|
|
|
33 |
|
|
|
34 |
@Autowired
|
|
|
35 |
ResponseSender<?> responseSender;
|
|
|
36 |
|
|
|
37 |
@Autowired
|
|
|
38 |
Gson gson;
|
|
|
39 |
|
|
|
40 |
@Autowired
|
|
|
41 |
private HypertrackKeyRepository hypertrackKeyRepository;
|
|
|
42 |
|
|
|
43 |
private static final String ACCOUNT_ID = "aZ6flHhrgPIEl18buHdPBdueEN4";
|
|
|
44 |
private static final String SECRET_KEY = "a7rsX5B4UNNfTTx1-IJ19qdH48BT4YvBKlQJg3n3_KKNe7WWych55g";
|
|
|
45 |
|
|
|
46 |
@RequestMapping(value = "/devices/hypertrackId", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
47 |
@ApiImplicitParams({
|
|
|
48 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
|
|
49 |
@ApiOperation(value = "")
|
|
|
50 |
public ResponseEntity<?> deviceHypertrackId(HttpServletRequest request,
|
|
|
51 |
@RequestBody HyperTrackKeyModel hyperTrackKeyModel) {
|
|
|
52 |
HypertrackKey hyperTrackKey = hypertrackKeyRepository.selectByUserIdAndDeviceId(hyperTrackKeyModel.getUserId(),
|
|
|
53 |
hyperTrackKeyModel.getDeviceId());
|
|
|
54 |
if (hyperTrackKey == null) {
|
|
|
55 |
hyperTrackKey = new HypertrackKey();
|
|
|
56 |
hyperTrackKey.setDeviceId(hyperTrackKeyModel.getDeviceId());
|
|
|
57 |
hyperTrackKey.setUserId(hyperTrackKeyModel.getUserId());
|
|
|
58 |
}
|
|
|
59 |
hyperTrackKey.setHypertrackKeyId(hyperTrackKeyModel.getHyperTrackId());
|
|
|
60 |
hyperTrackKey.setCreatedTimestamp(LocalDateTime.now());
|
|
|
61 |
hyperTrackKey.setUpdatedTimestamp(LocalDateTime.now());
|
|
|
62 |
hypertrackKeyRepository.persist(hyperTrackKey);
|
|
|
63 |
return responseSender.ok(true);
|
|
|
64 |
}
|
|
|
65 |
|
|
|
66 |
}
|