February 2019
Intermediate to advanced
442 pages
11h 46m
English
A user sends the data in JSON format and it must be validated before entering into the system to avoid any backend errors. Instead of imposing a full list of validations, we will implement a few basic validations. For example, validating an existing username,the role list has invalid values other than ROLR_USER and ROLE_ADMIN. The code looks as follows:
if (userRegistrationDto.username != null) { var existingUser : User? = userRepository?.findByUsername( userRegistrationDto.username) if (existingUser != null) { errors.reject("Existing username","User is already exist with username '${userRegistrationDto.username}'. ") }}if( userRegistrationDto.roleList.isEmpty()){ errors.reject("No Roles provided","Please provide roles")}else ...