forked from solid-connection/solid-connect-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChatController.java
More file actions
62 lines (55 loc) · 2.52 KB
/
ChatController.java
File metadata and controls
62 lines (55 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package com.example.solidconnection.chat.controller;
import com.example.solidconnection.chat.dto.ChatMessageResponse;
import com.example.solidconnection.chat.dto.ChatParticipantResponse;
import com.example.solidconnection.chat.dto.ChatRoomListResponse;
import com.example.solidconnection.chat.service.ChatService;
import com.example.solidconnection.common.dto.SliceResponse;
import com.example.solidconnection.common.resolver.AuthorizedUser;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.PageableDefault;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequiredArgsConstructor
@RequestMapping("/chats")
public class ChatController {
private final ChatService chatService;
@GetMapping("/rooms")
public ResponseEntity<ChatRoomListResponse> getChatRooms(
@AuthorizedUser long siteUserId
) {
ChatRoomListResponse chatRoomListResponse = chatService.getChatRooms(siteUserId);
return ResponseEntity.ok(chatRoomListResponse);
}
@GetMapping("/rooms/{room-id}")
public ResponseEntity<SliceResponse<ChatMessageResponse>> getChatMessages(
@AuthorizedUser long siteUserId,
@PathVariable("room-id") Long roomId,
@PageableDefault(size = 20, sort = "createdAt", direction = Sort.Direction.DESC) Pageable pageable
) {
SliceResponse<ChatMessageResponse> response = chatService.getChatMessages(siteUserId, roomId, pageable);
return ResponseEntity.ok(response);
}
@GetMapping("rooms/{room-id}/partner")
public ResponseEntity<ChatParticipantResponse> getChatPartner(
@AuthorizedUser long siteUserId,
@PathVariable("room-id") Long roomId
) {
ChatParticipantResponse response = chatService.getChatPartner(siteUserId, roomId);
return ResponseEntity.ok(response);
}
@PutMapping("/rooms/{room-id}/read")
public ResponseEntity<Void> markChatMessagesAsRead(
@AuthorizedUser long siteUserId,
@PathVariable("room-id") Long roomId
) {
chatService.markChatMessagesAsRead(siteUserId, roomId);
return ResponseEntity.ok().build();
}
}