I'm trying to save new phone number in database
First by another method get phone number and temporary save it and send a code to user then by following methods check if user entered correct code
The controller:
@GetMapping("/check-code/{code}")
public Boolean checkPhoneNumberCode(@PathVariable("code") int code){
return phoneService.validateCode(code);
}
The service:
@Override
public Boolean validateCode(int code) {
Integer phoneNumberCode = cacheService.getPhoneNumberCode(phoneNumber.toString());
if (!phoneNumberCode.equals(code)) {
resendCode();
return false;
}
updateUser();
clear();
return true;
}
after the code was ok updateUser() method will call:
@Override
public void updateUser() {
User user = userRepository.findByIdAndIsDeletedFalse(userId).get();
user.setPhoneNumber(phoneNumber);
userRepository.save(user);
}
The UserRepository:
public interface UserRepository extends MongoRepository<User, String> {
And at the end of updateUser()
method data must be updated and it updated
but when updateUser()
method finishes
and validateCode()
method finishes
I've checked, before checkPhoneNumberCode()
method finishes, data still updated (before "}" finishes and program exit from debug mode) but when program exit from debug mode (checkPhoneNumberCode()
method completes) data will reset and back to what was before
I'm using Intellij as IDE and Java for back-end and MongoDB for database I don't think it relates to front-end but I'm using angular for front-end
Controller: src -> main -> ToDoWeb -> controller -> PhoneController
;
Service: src -> main -> ToDoWeb -> service -> impl -> PhoneServiceImpl
;
Repository: src -> main -> ToDoWeb -> repository -> UserRepository
;