Package api.mpba.rastvdmy.controller
Class MessageController
java.lang.Object
api.mpba.rastvdmy.controller.MessageController
@RestController
@PreAuthorize("hasAnyRole(\'ROLE_ADMIN\', \'ROLE_DEFAULT\')")
@RequestMapping(path="/api/v1/messages")
public class MessageController
extends Object
Controller for handling message-related requests.
This class provides endpoints for sending and retrieving messages. It utilizes the
MessageService
for business logic and MessageMapper
for mapping
between request and response objects. Messages are also sent to a Kafka topic for
further processing.
-
Constructor Summary
ConstructorDescriptionMessageController
(MessageService messageService, org.springframework.kafka.core.KafkaTemplate<String, String> kafkaTemplate, MessageMapper messageMapper) Constructor for the MessageController. -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.http.ResponseEntity
<List<MessageResponse>> Retrieves a list of messages.org.springframework.http.ResponseEntity
<MessageResponse> sendMessage
(jakarta.servlet.http.HttpServletRequest request, @Valid MessageRequest messageRequest) Sends a message to a recipient and publishes it to Kafka.
-
Constructor Details
-
MessageController
public MessageController(MessageService messageService, org.springframework.kafka.core.KafkaTemplate<String, String> kafkaTemplate, MessageMapper messageMapper) Constructor for the MessageController.- Parameters:
messageService
- The service to handle message operations.kafkaTemplate
- The template to send messages to Kafka.messageMapper
- The mapper for converting between request and response objects.
-
-
Method Details
-
getMessages
@GetMapping(produces="application/json") public org.springframework.http.ResponseEntity<List<MessageResponse>> getMessages()Retrieves a list of messages.- Returns:
- A
ResponseEntity
containing a list ofMessageResponse
.
-
sendMessage
@PostMapping(consumes="application/json", produces="application/json") public org.springframework.http.ResponseEntity<MessageResponse> sendMessage(jakarta.servlet.http.HttpServletRequest request, @Valid @RequestBody @Valid MessageRequest messageRequest) throws Exception Sends a message to a recipient and publishes it to Kafka.- Parameters:
request
- The HTTP servlet request containing user information.messageRequest
- The request body containing message details.- Returns:
- A
ResponseEntity
containing the sentMessageResponse
. - Throws:
Exception
- if there is an error sending the message.
-