-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: โจ Receive Chatroom Detail Informations (#188)
* fix: chatmessage data structure changed to sorted set * fix: chat_message_service.delete() deprecated due to unnecessary * fix: chat_message hasn't responsibility about id * chore: change lecttuce debug level to debug in test profile due to test * fix: change chat_message_repository from jpa interface to concrete class * test: modify chat_message_repository test * test: add boundary value analysis test & verify sorting with same create_at time * refactor: add repository interface * rename: chat_message_service save to create * feat: add functions into chat_message_service * feat: not_found error code added in chat_member_error_code * feat: add three type of find method in chat_member_service * feat: add chat_member_res_detail dto * fix: insert joined_at field in the chat_member_res.detail dto * feat: add chat_message response dto * feat: chat_room_res.room_with_participants dto * feat: chat_room_with_paritipants mapper * feat: impl chat_room_with_participants_search_service * style: sperate from service login hard code to contants & delete annotation * test: chat_room_with_participants_search_service test case * feat: add chat_room_manager for authorization * feat: add chat_room_usecase * feat: add get_chatroom controller & api * docs: add information about recent_messages field's sorted in the chat_room_res * chore: delete lecttuce log * test: chat_room detail integration test
- Loading branch information
1 parent
6aa5578
commit 4fb271b
Showing
22 changed files
with
1,250 additions
and
199 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/chat/dto/ChatMemberRes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package kr.co.pennyway.api.apis.chat.dto; | ||
|
||
import com.fasterxml.jackson.annotation.JsonFormat; | ||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.databind.annotation.JsonSerialize; | ||
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import kr.co.pennyway.domain.domains.member.domain.ChatMember; | ||
import kr.co.pennyway.domain.domains.member.type.ChatMemberRole; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
public final class ChatMemberRes { | ||
@Schema(description = "์ฑํ ๋ฐฉ ์ฐธ์ฌ์ ์์ธ ์ ๋ณด") | ||
public record Detail( | ||
@Schema(description = "์ฑํ ๋ฐฉ ์ฐธ์ฌ์ ID", type = "long") | ||
Long id, | ||
@Schema(description = "์ฑํ ๋ฐฉ ์ฐธ์ฌ์ ์ด๋ฆ") | ||
String name, | ||
@Schema(description = "์ฑํ ๋ฐฉ ์ฐธ์ฌ์ ์ญํ ") | ||
ChatMemberRole role, | ||
@Schema(description = "์ฑํ ๋ฐฉ ์ฐธ์ฌ์ ์๋ฆผ ์ค์ ์ฌ๋ถ. ๋ด ์ ๋ณด๋ฅผ ์กฐํํ ๋๋ง ํฌํจ๋ฉ๋๋ค.") | ||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
Boolean notifyEnabled, | ||
@Schema(description = "์ฑํ ๋ฐฉ ๊ฐ์ ์ผ") | ||
@JsonSerialize(using = LocalDateTimeSerializer.class) | ||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") | ||
LocalDateTime createdAt | ||
) { | ||
public static Detail from(ChatMember chatMember, boolean isContainNotifyEnabled) { | ||
return new Detail( | ||
chatMember.getId(), | ||
chatMember.getName(), | ||
chatMember.getRole(), | ||
isContainNotifyEnabled ? chatMember.isNotifyEnabled() : null, | ||
chatMember.getCreatedAt() | ||
); | ||
} | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
pennyway-app-external-api/src/main/java/kr/co/pennyway/api/apis/chat/dto/ChatRes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package kr.co.pennyway.api.apis.chat.dto; | ||
|
||
import com.fasterxml.jackson.annotation.JsonFormat; | ||
import com.fasterxml.jackson.databind.annotation.JsonSerialize; | ||
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import kr.co.pennyway.domain.common.redis.message.domain.ChatMessage; | ||
import kr.co.pennyway.domain.common.redis.message.type.MessageCategoryType; | ||
import kr.co.pennyway.domain.common.redis.message.type.MessageContentType; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
public final class ChatRes { | ||
@Schema(description = "์ฑํ ๋ฉ์์ง ์์ธ ์ ๋ณด") | ||
public record Detail( | ||
@Schema(description = "์ฑํ ๋ฐฉ ID", type = "long") | ||
Long chatRoomId, | ||
@Schema(description = "์ฑํ ID", type = "long") | ||
Long chatId, | ||
@Schema(description = "์ฑํ ๋ด์ฉ") | ||
String content, | ||
@Schema(description = "์ฑํ ๋ด์ฉ ํ์ ") | ||
MessageContentType contentType, | ||
@Schema(description = "์ฑํ ๋ฉ์์ง ์นดํ ๊ณ ๋ฆฌ ํ์ ") | ||
MessageCategoryType categoryType, | ||
@Schema(description = "์ฑํ ์์ฑ์ผ") | ||
@JsonSerialize(using = LocalDateTimeSerializer.class) | ||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") | ||
LocalDateTime createdAt, | ||
@Schema(description = "์ฑํ ๋ณด๋ธ ์ฌ๋ ID", type = "long") | ||
Long senderId | ||
) { | ||
public static Detail from(ChatMessage message) { | ||
return new Detail( | ||
message.getChatRoomId(), | ||
message.getChatId(), | ||
message.getContent(), | ||
message.getContentType(), | ||
message.getCategoryType(), | ||
message.getCreatedAt(), | ||
message.getSender() | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...main/java/kr/co/pennyway/api/apis/chat/service/ChatRoomWithParticipantsSearchService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package kr.co.pennyway.api.apis.chat.service; | ||
|
||
import kr.co.pennyway.api.apis.chat.dto.ChatRoomRes; | ||
import kr.co.pennyway.api.apis.chat.mapper.ChatRoomMapper; | ||
import kr.co.pennyway.domain.common.redis.message.domain.ChatMessage; | ||
import kr.co.pennyway.domain.common.redis.message.service.ChatMessageService; | ||
import kr.co.pennyway.domain.domains.member.domain.ChatMember; | ||
import kr.co.pennyway.domain.domains.member.exception.ChatMemberErrorCode; | ||
import kr.co.pennyway.domain.domains.member.exception.ChatMemberErrorException; | ||
import kr.co.pennyway.domain.domains.member.service.ChatMemberService; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
@Slf4j | ||
@Service | ||
@RequiredArgsConstructor | ||
public class ChatRoomWithParticipantsSearchService { | ||
private static final int MESSAGE_LIMIT = 15; | ||
|
||
private final ChatMemberService chatMemberService; | ||
private final ChatMessageService chatMessageService; | ||
|
||
@Transactional(readOnly = true) | ||
public ChatRoomRes.RoomWithParticipants execute(Long userId, Long chatRoomId) { | ||
ChatMember myInfo = chatMemberService.readChatMember(userId, chatRoomId) | ||
.orElseThrow(() -> new ChatMemberErrorException(ChatMemberErrorCode.NOT_FOUND)); | ||
|
||
List<ChatMessage> chatMessages = chatMessageService.readRecentMessages(chatRoomId, MESSAGE_LIMIT); | ||
|
||
Set<Long> recentParticipantIds = chatMessages.stream() | ||
.map(ChatMessage::getSender) | ||
.filter(sender -> !sender.equals(userId)) | ||
.collect(Collectors.toSet()); | ||
|
||
List<ChatMember> recentParticipants = chatMemberService.readChatMembersByMemberIdIn(chatRoomId, recentParticipantIds); | ||
|
||
recentParticipantIds.add(userId); | ||
List<Long> otherMemberIds = chatMemberService.readChatMemberIdsByMemberIdNotIn(chatRoomId, recentParticipantIds); | ||
|
||
return ChatRoomMapper.toChatRoomResRoomWithParticipants(myInfo, recentParticipants, otherMemberIds, chatMessages); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
...l-api/src/main/java/kr/co/pennyway/api/common/security/authorization/ChatRoomManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package kr.co.pennyway.api.common.security.authorization; | ||
|
||
import kr.co.pennyway.domain.domains.member.service.ChatMemberService; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Slf4j | ||
@Component("chatRoomManager") | ||
@RequiredArgsConstructor | ||
public class ChatRoomManager { | ||
private final ChatMemberService chatMemberService; | ||
|
||
/** | ||
* ์ฌ์ฉ์๊ฐ ์ฑํ ๋ฐฉ์ ๋ํ ์ ๊ทผ ๊ถํ์ด ์๋์ง ํ์ธํ๋ค. | ||
*/ | ||
@Transactional(readOnly = true) | ||
public boolean hasPermission(Long userId, Long chatRoomId) { | ||
return chatMemberService.isExists(chatRoomId, userId); | ||
} | ||
} |
Oops, something went wrong.