Skip to content

Commit

Permalink
Add user controller
Browse files Browse the repository at this point in the history
  • Loading branch information
juncevich committed Dec 13, 2023
1 parent 0c73e38 commit 8ba8fde
Showing 1 changed file with 40 additions and 0 deletions.
@@ -0,0 +1,40 @@
package com.relay.chatservice.user;

import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;

@Service
@RequiredArgsConstructor
public class UserController {
private final UserService userService;

@MessageMapping("/user.addUser")
@SendTo("/user/topic")
public User addUser(
@Payload User user
) {
userService.saveUser(user);
return user;
}

@MessageMapping("/user.disconnect")
@SendTo("/user/topic")
public User disconnect(
@Payload User user
) {
userService.disconnect(user);
return user;
}

@GetMapping("/users")
public ResponseEntity<List<User>> findConnectedUsers() {
return ResponseEntity.ok(userService.findConnectedUsers());
}
}

0 comments on commit 8ba8fde

Please sign in to comment.