From 4aaac4aae4bb83f1b344c1f8a840c91546e6447d Mon Sep 17 00:00:00 2001 From: nivetha <nivetha.mariappan@tarento.com> Date: Tue, 5 Apr 2022 17:44:40 +0530 Subject: [PATCH] API to delete user device token --- .../tarento/retail/controller/UserController.java | 12 ++++++++++++ src/main/java/com/tarento/retail/dao/UserDao.java | 2 ++ .../com/tarento/retail/dao/impl/UserDaoImpl.java | 11 +++++++++++ .../java/com/tarento/retail/service/UserService.java | 2 ++ .../tarento/retail/service/impl/UserServiceImpl.java | 5 +++++ .../java/com/tarento/retail/util/PathRoutes.java | 1 + src/main/java/com/tarento/retail/util/Sql.java | 1 + 7 files changed, 34 insertions(+) diff --git a/src/main/java/com/tarento/retail/controller/UserController.java b/src/main/java/com/tarento/retail/controller/UserController.java index 502c790..787f013 100644 --- a/src/main/java/com/tarento/retail/controller/UserController.java +++ b/src/main/java/com/tarento/retail/controller/UserController.java @@ -587,4 +587,16 @@ public class UserController { return ResponseGenerator.failureResponse("Check your request params"); } + @RequestMapping(value = PathRoutes.UserRoutes.DELETE_USER_DEVICE_TOKEN, method = RequestMethod.DELETE) + public String deleteDeviceToken(@RequestParam String deviceId, + @RequestHeader(value = "x-user-info", required = true) String xUserInfo) throws JsonProcessingException { + Gson gson = new GsonBuilder().setPrettyPrinting().create(); + User thisUser = gson.fromJson(xUserInfo, User.class); + + Boolean response = userService.deleteDeviceToken(thisUser.getId(), deviceId); + if (response) + return ResponseGenerator.successResponse("Success"); + + return ResponseGenerator.failureResponse(HttpStatus.UNPROCESSABLE_ENTITY.toString()); + } } diff --git a/src/main/java/com/tarento/retail/dao/UserDao.java b/src/main/java/com/tarento/retail/dao/UserDao.java index 42273d3..ed4f3f0 100644 --- a/src/main/java/com/tarento/retail/dao/UserDao.java +++ b/src/main/java/com/tarento/retail/dao/UserDao.java @@ -262,4 +262,6 @@ public interface UserDao { public Boolean validateUserPin(int pin, String username); + public Boolean deleteDeviceToken(Long userId, String deviceId); + } diff --git a/src/main/java/com/tarento/retail/dao/impl/UserDaoImpl.java b/src/main/java/com/tarento/retail/dao/impl/UserDaoImpl.java index 3526520..a20161e 100644 --- a/src/main/java/com/tarento/retail/dao/impl/UserDaoImpl.java +++ b/src/main/java/com/tarento/retail/dao/impl/UserDaoImpl.java @@ -1014,4 +1014,15 @@ public class UserDaoImpl implements UserDao { } return Boolean.FALSE; } + + @Override + public Boolean deleteDeviceToken(Long userId, String deviceId) { + try { + jdbcTemplate.update(UserQueries.DELETE_DEVICE_TOKEN, new Object[] { userId, deviceId }); + return Boolean.TRUE; + } catch (Exception e) { + LOGGER.error(String.format(Constants.EXCEPTION_METHOD, "deleteDeviceToken", e.getMessage())); + } + return Boolean.FALSE; + } } diff --git a/src/main/java/com/tarento/retail/service/UserService.java b/src/main/java/com/tarento/retail/service/UserService.java index 6a65f85..bad0433 100644 --- a/src/main/java/com/tarento/retail/service/UserService.java +++ b/src/main/java/com/tarento/retail/service/UserService.java @@ -241,4 +241,6 @@ public interface UserService { public Boolean validateUserPin(String username, int pin); + public Boolean deleteDeviceToken(Long userId, String deviceId); + } \ No newline at end of file diff --git a/src/main/java/com/tarento/retail/service/impl/UserServiceImpl.java b/src/main/java/com/tarento/retail/service/impl/UserServiceImpl.java index e4dfcad..bbff912 100644 --- a/src/main/java/com/tarento/retail/service/impl/UserServiceImpl.java +++ b/src/main/java/com/tarento/retail/service/impl/UserServiceImpl.java @@ -607,4 +607,9 @@ public class UserServiceImpl implements UserDetailsService, UserService { return userDao.validateUserPin(pin, username); } + @Override + public Boolean deleteDeviceToken(Long userId, String deviceId) { + return userDao.deleteDeviceToken(userId, deviceId); + } + } diff --git a/src/main/java/com/tarento/retail/util/PathRoutes.java b/src/main/java/com/tarento/retail/util/PathRoutes.java index aed37d7..697fc84 100644 --- a/src/main/java/com/tarento/retail/util/PathRoutes.java +++ b/src/main/java/com/tarento/retail/util/PathRoutes.java @@ -41,6 +41,7 @@ public interface PathRoutes { final String NUMBER_OF_USERS_ROLES_GET = "/getNumberOfUsersAndRoles"; final String GET_USER_DEVICE_TOKEN = "getDeviceTokenForUserIds"; final String GENERATE_PIN = "/generatePin"; + final String DELETE_USER_DEVICE_TOKEN = "/deleteDeviceToken"; } public interface AuthenticationRoutes { diff --git a/src/main/java/com/tarento/retail/util/Sql.java b/src/main/java/com/tarento/retail/util/Sql.java index da91a8b..7da9170 100644 --- a/src/main/java/com/tarento/retail/util/Sql.java +++ b/src/main/java/com/tarento/retail/util/Sql.java @@ -178,6 +178,7 @@ public interface Sql { final String GET_NUMBER_USER_ROLES = "SELECT count(*) as 'numberOfUsers', r.role_name as 'roleName' from user usr LEFT JOIN user_role ur ON usr.id = ur.user_id LEFT JOIN role r ON ur.role_id = r.id where r.id > 2090 group by r.role_name "; final String SET_USER_PIN = "UPDATE user SET pin=? WHERE id= ?"; final String GET_USER_PIN = "SELECT pin FROM user where username = ?"; + final String DELETE_DEVICE_TOKEN = "DELETE FROM user_device WHERE user_id= ? AND device_id =?"; } public interface NamedUserQueries { -- GitLab