Skip to content

Intitial PR - #1

Open
punith-dandluri wants to merge 2 commits into
c-code-x:mainfrom
punith-dandluri:main
Open

Intitial PR#1
punith-dandluri wants to merge 2 commits into
c-code-x:mainfrom
punith-dandluri:main

Conversation

@punith-dandluri

Copy link
Copy Markdown

Features

  • Added User Authentication and Authorization.
  • OTP - Verification for ensuring only gitam mail id users.
  • No restriction on viewing messages.
  • Only authenticated users can post a message.
  • Admin can get all messages, users, delete users and their messages, promote a user to admin and demote admin to user.

import java.util.UUID;

@RestController
@RequestMapping({"admin"})

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Invalid OTP

Move the String literal to common constants

this.messageService = messageService;
}
@GetMapping("messages")
public GenericResDTO<List<PublicMessagesResDTO>> getAllMessages(){

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add String to common constants

List<AdminMessagesResDTO> AdminMessagesResDTOList = new ArrayList<>();

for (MessageDAO messageDAO : messageDAOList) {
AdminMessagesResDTO adminMessagesResDTO = new AdminMessagesResDTO();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using ModelMapper to simplify object mapping and improve code readability.

Suggested change
AdminMessagesResDTO adminMessagesResDTO = new AdminMessagesResDTO();
AdminMessagesResDTO adminMessagesResDTO = modelMapper.map(messageDAO,AdminMessagesResDTO.class);

import org.springframework.stereotype.Service;

@Service
public class EmailService {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"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));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to improve the logic to generate the OTPs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants