Class MessageServiceImpl

java.lang.Object
api.mpba.rastvdmy.service.impl.MessageServiceImpl
All Implemented Interfaces:
MessageService

@Service public class MessageServiceImpl extends Object implements MessageService
Implementation of the MessageService interface for managing messages between users. This service provides methods for sending and retrieving messages, including message encryption and decryption functionalities.
  • Constructor Details

    • MessageServiceImpl

      @Autowired public MessageServiceImpl(MessageRepository messageRepository, UserProfileRepository userProfileRepository, TokenVerifierService tokenVerifierService)
      Constructor for MessageServiceImpl.
      Parameters:
      messageRepository - the message repository to be used
      userProfileRepository - the user profile repository to be used
      tokenVerifierService - the service for extracting user token and getting user data from the request
  • Method Details

    • getMessages

      public List<Message> getMessages()
      Retrieves all messages, decrypting their content before returning.
      Specified by:
      getMessages in interface MessageService
      Returns:
      a list of decrypted messages
    • sendMessage

      public Message sendMessage(jakarta.servlet.http.HttpServletRequest request, String receiverEmail, String content) throws Exception
      Sends a message from the sender to the specified receiver.
      Specified by:
      sendMessage in interface MessageService
      Parameters:
      request - the HTTP request containing user data
      receiverEmail - the email of the receiver
      content - the content of the message
      Returns:
      the saved Message object
      Throws:
      Exception - if an error occurs during message sending