Commit 2e51000f authored by nivetha's avatar nivetha
Browse files

Fixed issue with updating device token

Showing with 23 additions and 0 deletions
+23 -0
......@@ -211,6 +211,8 @@ public class UserController {
Gson gson = new GsonBuilder().setPrettyPrinting().create();
User thisUser = gson.fromJson(xUserInfo, User.class);
if (userService.checkUserTokenExists(thisUser.getId(), deviceToken.getDeviceToken())) {
Long authTokenRef = userService.fetchAuthTokenReference(thisUser.getAuthToken());
userService.updateDeviceAuthRef(thisUser.getId(), deviceToken.getDeviceToken(), authTokenRef);
return ResponseGenerator.successResponse("Success");
}
Long authTokenRef = userService.fetchAuthTokenReference(thisUser.getAuthToken());
......
......@@ -264,4 +264,6 @@ public interface UserDao {
public Boolean deleteDeviceToken(Long userId, String deviceId);
public Boolean updateDeviceAuthRef(Long userId, String deviceToken, Long authId);
}
......@@ -1025,4 +1025,15 @@ public class UserDaoImpl implements UserDao {
}
return Boolean.FALSE;
}
@Override
public Boolean updateDeviceAuthRef(Long userId, String deviceToken, Long authId) {
try {
jdbcTemplate.update(UserQueries.UPDATE_DEVICE_AUTH_REF, new Object[] { authId, userId, deviceToken });
return Boolean.TRUE;
} catch (Exception e) {
LOGGER.error(String.format(Constants.EXCEPTION_METHOD, "updateDeviceAuthRef", e.getMessage()));
}
return Boolean.FALSE;
}
}
......@@ -243,4 +243,6 @@ public interface UserService {
public Boolean deleteDeviceToken(Long userId, String deviceId);
public Boolean updateDeviceAuthRef(Long userId, String deviceToken, Long authId);
}
\ No newline at end of file
......@@ -612,4 +612,9 @@ public class UserServiceImpl implements UserDetailsService, UserService {
return userDao.deleteDeviceToken(userId, deviceId);
}
@Override
public Boolean updateDeviceAuthRef(Long userId, String deviceToken, Long authId) {
return userDao.updateDeviceAuthRef(userId, deviceToken, authId);
}
}
......@@ -149,6 +149,7 @@ public interface Sql {
final String INSERT_USER_DEVICE_TOKEN = "INSERT INTO user_device (user_id, device_token, device_id, created_date, user_auth_id) VALUES (?,?,?,?,?) ";
final String UPDATE_USER_DEVICE_TOKEN = "UPDATE user_device SET device_token = ?, created_date = ? WHERE user_id = ? ";
final String FETCH_USER_DEVICE_TOKEN = " SELECT device.id, device.user_id, device.device_token, auth_token FROM user_device device, user_authentication WHERE device.user_auth_id = user_authentication.id AND device.user_id IN ";
final String UPDATE_DEVICE_AUTH_REF = "UPDATE user_device SET user_auth_id= ? WHERE user_id= ? and device_token= ?";
final String USER_DEVICE_ROLE_CONDITION = " and exists (select 1 from user_role where user_id = device.user_id and role_id IN (1,2)) "
+ "and not exists (select 1 from user_role where user_id = device.user_id and role_id NOT IN (1,2)) ";
final String FETCH_AUTH_TOKEN_REF = "SELECT id FROM user_authentication WHERE auth_token = ? ";
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment