Intitial PR - #1
Conversation
| import java.util.UUID; | ||
|
|
||
| @RestController | ||
| @RequestMapping({"admin"}) |
There was a problem hiding this comment.
When there is only one endpoint please don't use {}
| userSigninReqDTO.getPassword()); | ||
| var authentication = authenticationManager.authenticate(credentials); | ||
| var payload = tokenService.generateToken(authentication); | ||
| return new GenericResDTO<TokenResDTO>(payload, new BasicResDTO("Login Successful", HttpStatus.OK)); |
There was a problem hiding this comment.
Move the String literal to common constants
| @GetMapping("renew-token") | ||
| public GenericResDTO<TokenResDTO> refresh(Authentication authentication) { | ||
| var payload = tokenService.generateToken(authentication); | ||
| return new GenericResDTO<TokenResDTO>(payload, new BasicResDTO("Token Renewed", HttpStatus.OK)); |
There was a problem hiding this comment.
Move the String literal to common constants
| ResponseDTO verifyOtp(@RequestParam String mailId, @RequestParam String otp) { | ||
| if (otpService.verifyOtp(mailId, otp)) | ||
| return userService.MakeVerified(mailId); | ||
| return new ResponseDTO( new BasicResDTO("OTP is wrong", HttpStatus.NOT_FOUND)); |
There was a problem hiding this comment.
Invalid OTP
Move the String literal to common constants
| this.messageService = messageService; | ||
| } | ||
| @GetMapping("messages") | ||
| public GenericResDTO<List<PublicMessagesResDTO>> getAllMessages(){ |
There was a problem hiding this comment.
Please add pagination, as there might be a lot of entries in the DB
| adminMessagesResDTO.setDate(messageDAO.getPostedOn()); | ||
| adminMessagesResDTO.setUser(messageDAO.getUser()); | ||
| } | ||
| return new GenericResDTO<>(AdminMessagesResDTOList, new BasicResDTO("Messages fetched successfully", HttpStatus.OK)); |
There was a problem hiding this comment.
Add String to common constants
| List<AdminMessagesResDTO> AdminMessagesResDTOList = new ArrayList<>(); | ||
|
|
||
| for (MessageDAO messageDAO : messageDAOList) { | ||
| AdminMessagesResDTO adminMessagesResDTO = new AdminMessagesResDTO(); |
There was a problem hiding this comment.
Consider using ModelMapper to simplify object mapping and improve code readability.
| AdminMessagesResDTO adminMessagesResDTO = new AdminMessagesResDTO(); | |
| AdminMessagesResDTO adminMessagesResDTO = modelMapper.map(messageDAO,AdminMessagesResDTO.class); |
| import org.springframework.stereotype.Service; | ||
|
|
||
| @Service | ||
| public class EmailService { |
There was a problem hiding this comment.
Create an interface for this and then implement it
| } | ||
| OTP otp = OTP.generateOTP(optionalUserDAO.get().getEmailId()); | ||
| saveOTP(optionalUserDAO.get().getId().toString(), otp); | ||
| return emailService.sendEmail(optionalUserDAO.get().getEmailId(), "GRATITUDE BOARD VERIFY EMAIL", "Your OTP is for Verifying is " + otp.getValue()); |
There was a problem hiding this comment.
"Your OTP is for Verifying is "
something wrong in the grammer
| public static String generateRandomString(int len) { | ||
| StringBuilder sb = new StringBuilder(len); | ||
| for (int i = 0; i < len; i++) { | ||
| sb.append(random.nextInt(10)); |
There was a problem hiding this comment.
Need to improve the logic to generate the OTPs
Features
AuthenticationandAuthorization.OTP - Verificationfor ensuring onlygitammail id users.getall messages, users,deleteusers and their messages,promoteausertoadminand demoteadmintouser.