Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V4 ws #86

Merged
merged 10 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ on:
push:
branches:
- v3
pull_request:
branches:
- v3

permissions:
contents: read
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.chat.yourway.controller.websocket;


import com.chat.yourway.dto.request.MessageRequestDto;
import com.chat.yourway.dto.response.MessageResponseDto;
import com.chat.yourway.service.MessageService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.messaging.handler.annotation.DestinationVariable;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Controller;

import java.util.UUID;

@Controller
@Slf4j
@RequiredArgsConstructor
public class ChatController {

private final SimpMessagingTemplate messagingTemplate;
private final MessageService messageService;

@MessageMapping("/app/topic/public/{topicId}")
public void sendMessage(@DestinationVariable UUID topicId, MessageRequestDto message) {

log.info("Received message for topic ID: {}", topicId);

MessageResponseDto savedMessage = messageService.sendToTopic(topicId, message);
Copy link
Contributor

Choose a reason for hiding this comment

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

Ця строчка не де не примається, треба лише messageService.sendToTopic(topicId, message);

Copy link
Author

Choose a reason for hiding this comment

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

Oк. Зрозумів, виправлю

log.info("Message was saved in DB");

messagingTemplate.convertAndSend("/topic/public/" + topicId, message);
log.info("Message sent to topic ID: {}", topicId) ;

}
}
Loading