Add methods for group chats for ChatController
@@ -3,6 +3,9 @@ package greencity.controller;
import greencity.dto.ChatMessageDto;
import greencity.dto.ChatRoomDto;
import greencity.dto.ParticipantDto;
+import greencity.entity.ChatRoom;
+import greencity.enums.ChatType;
+import greencity.repository.ChatRoomRepo;
import greencity.service.ChatMessageService;
import greencity.service.ChatRoomService;
import greencity.service.ParticipantService;
@@ -22,6 +25,7 @@ public class ChatController {
private final ChatRoomService chatRoomService;
private final ParticipantService participantService;
private final ChatMessageService chatMessageService;
+ private final ChatRoomRepo chatRoomRepo;
/**
* {@inheritDoc}
@@ -32,6 +36,12 @@ public class ChatController {
.body(chatRoomService.findAllByParticipantName(principal.getName()));
}
+ @GetMapping("/rooms/visible")
+ public ResponseEntity<List<ChatRoomDto>> findAllVisibleRooms(Principal principal) {
+ return ResponseEntity.status(HttpStatus.OK)
+ .body(chatRoomService.findAllVisibleRooms(principal.getName()));
+ }
+
/**
* {@inheritDoc}
*/
@@ -82,6 +92,19 @@ public class ChatController {
.body(participantService.findAllParticipantsByQuery(query, principal.getName()));
}
+ /**
+ * {@inheritDoc}
+ */
+ @GetMapping(value = {"/rooms", "/rooms/{query}"})
+ public ResponseEntity<List<ChatRoomDto>> getAllChatRoomsBy(
+ @PathVariable(required = false, value = "query") String query, Principal principal) {
+ if (StringUtils.isEmpty(query)) {
+ return this.findAllVisibleRooms(principal);
+ }
+ return ResponseEntity.status(HttpStatus.OK)
+ .body(chatRoomService.findAllChatRoomsByQuery(query, participantService.findByEmail(principal.getName())));
+ }
+
/**
* {@inheritDoc}
*/
@@ -91,6 +114,27 @@ public class ChatController {
.body(chatMessageService.findTopByOrderByIdDesc().getId());
}
+ /**
+ * {@inheritDoc}
+ */
+ @GetMapping("/users/{ids}/room/{room_name}")
+ public ResponseEntity<List<ChatRoomDto>> getGroupChatRoomsWithUsers(@PathVariable("ids") List<Long> ids,
+ @PathVariable("room_name") String chatName,
+ Principal principal) {
+ return ResponseEntity.status(HttpStatus.OK)
+ .body(chatRoomService.findGroupByParticipants(ids, principal.getName(), chatName));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @GetMapping("/groups")
+ public ResponseEntity<List<ChatRoomDto>> getGroupChats(Principal principal) {
+ List<ChatRoom> list = chatRoomRepo.findGroupChats(participantService.findByEmail(principal.getName()), ChatType.GROUP);
+ return ResponseEntity.status(HttpStatus.OK)
+ .body(chatRoomService.findGroupChatRooms(participantService.findByEmail(principal.getName()),ChatType.GROUP));
+ }
+
/**
* {@inheritDoc}
*/
