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

Api: ✨ Implementing Chatroom Join API: A Bounded Context Approach #184

Merged
merged 40 commits into from
Oct 29, 2024
Merged
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
529af53
chore: external-api module messabe broker config 주입
psychology50 Oct 27, 2024
17fbd59
chore: add chat_join_event_message exchange properties
psychology50 Oct 27, 2024
f70fa0c
chore: add chat.join exchange
psychology50 Oct 27, 2024
20faf4b
style: domain service 역할을 구분하기 위한 chat_member 생성 로직 위치 수정
psychology50 Oct 27, 2024
3dd8dde
fix: modify the chat_member entity to don't check exsists member is_d…
psychology50 Oct 27, 2024
0292b30
feat: add domain logic(is_active(), is_banned_member()) in the chat_m…
psychology50 Oct 27, 2024
db98b94
feat: add ban domain method in entity
psychology50 Oct 27, 2024
74bb8b9
feat: add chat_member exception & error code
psychology50 Oct 27, 2024
7ef6be7
test: add user_fixture & chat_room_fixture within the domain test pac…
psychology50 Oct 27, 2024
57fdc46
feat: impl chat_member_repository
psychology50 Oct 27, 2024
c9869c2
feat: impl create_member business logic within chat_member_service
psychology50 Oct 27, 2024
50fcf39
test: chat_member create business logic unit test
psychology50 Oct 27, 2024
7113a65
fix: exclude nickname parameter when create chat_member
psychology50 Oct 27, 2024
5ae151f
feat: add password check and verify domain logic whitin the chat room…
psychology50 Oct 27, 2024
7f983be
feat: add chat_room error code with exception
psychology50 Oct 29, 2024
aac5895
fix: add chat_room not_found error code
psychology50 Oct 29, 2024
215b6e1
feat: chat_room_service.read_by_id()
psychology50 Oct 29, 2024
a3ce597
feat: add count_chat_member in chat_room logic
psychology50 Oct 29, 2024
27e7685
feat: chat_member_join business service impl
psychology50 Oct 29, 2024
e7aa55c
feat: add chat_room_join event handler within infra module
psychology50 Oct 29, 2024
8a94f4d
fix: when member join finish, call the chat_room join event handler
psychology50 Oct 29, 2024
9284ccc
feat: join_chat_room_usecase & fix chat_member_join_service return value
psychology50 Oct 29, 2024
57a6b48
fix: chat_member_join_service return value is adding plus 1 about cur…
psychology50 Oct 29, 2024
451cf22
feat: impl join chat room controller
psychology50 Oct 29, 2024
7379fe2
docs: write join_api swagger
psychology50 Oct 29, 2024
6218d86
fix: join_req_dto is added getter method for swagger ui presenting
psychology50 Oct 29, 2024
2793368
fix: chat_member_repository method rule find_by_chat_room_id -> find_…
psychology50 Oct 29, 2024
a12d85e
test: add chat_member_fixture in the external-api module
psychology50 Oct 29, 2024
0a67a54
test: chat_member_join_service_unit_test
psychology50 Oct 29, 2024
1ff3b7d
test: refactor & add chat_member_join_service test case
psychology50 Oct 29, 2024
96610b5
chore: prevent automatic rabbitmq connection creation during applicat…
psychology50 Oct 29, 2024
60ba5b6
fix: add two types of getter whitin chat_member_req
psychology50 Oct 29, 2024
5cdfe43
fix: add default constructor within dto
psychology50 Oct 29, 2024
1d44cb6
fix: modify distributed_lock's key correctly about the spel
psychology50 Oct 29, 2024
6981338
rename: add log within chat_member_join_service
psychology50 Oct 29, 2024
ad57c34
test: fix chat_room_id of the chat_room_fixture due to integration f…
psychology50 Oct 29, 2024
22a6d3a
rename: join_service_test (usecase package) move to (service package)
psychology50 Oct 29, 2024
c1cdbdf
fix: chat_room_join_event_hander bean create within the message_brock…
psychology50 Oct 29, 2024
9b65d96
fix: modify join_event_hander phase after_commit to before_commit due…
psychology50 Oct 29, 2024
2034cc3
test: chat_member_join integration test
psychology50 Oct 29, 2024
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
Prev Previous commit
Next Next commit
feat: chat_member_join business service impl
psychology50 committed Oct 29, 2024
commit 27e768561881b43df377de41c1877ecb46df5704
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package kr.co.pennyway.api.apis.chat.service;

import kr.co.pennyway.domain.common.redisson.DistributedLock;
import kr.co.pennyway.domain.domains.chatroom.domain.ChatRoom;
import kr.co.pennyway.domain.domains.chatroom.exception.ChatRoomErrorCode;
import kr.co.pennyway.domain.domains.chatroom.exception.ChatRoomErrorException;
import kr.co.pennyway.domain.domains.chatroom.service.ChatRoomService;
import kr.co.pennyway.domain.domains.member.service.ChatMemberService;
import kr.co.pennyway.domain.domains.user.domain.User;
import kr.co.pennyway.domain.domains.user.exception.UserErrorCode;
import kr.co.pennyway.domain.domains.user.exception.UserErrorException;
import kr.co.pennyway.domain.domains.user.service.UserService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service;

@Slf4j
@Service
@RequiredArgsConstructor
public class ChatMemberJoinService {
private static final long MAX_MEMBER_COUNT = 300;

private final UserService userService;
private final ChatRoomService chatRoomService;
private final ChatMemberService chatMemberService;

private final ApplicationEventPublisher eventPublisher;

@DistributedLock(key = "chatRoom.join.#chatRoomId")
public void execute(Long userId, Long chatRoomId, Integer password) {
ChatRoom chatRoom = chatRoomService.readChatRoom(chatRoomId).orElseThrow(() -> new ChatRoomErrorException(ChatRoomErrorCode.NOT_FOUND_CHAT_ROOM));

if (isFullRoom(chatRoomId)) {
throw new ChatRoomErrorException(ChatRoomErrorCode.FULL_CHAT_ROOM);
}

if (chatRoom.isPrivateRoom() && !chatRoom.matchPassword(password)) {
throw new ChatRoomErrorException(ChatRoomErrorCode.INVALID_PASSWORD);
}

User user = userService.readUser(userId).orElseThrow(() -> new UserErrorException(UserErrorCode.NOT_FOUND));

chatMemberService.createMember(user, chatRoom);
}

private boolean isFullRoom(Long chatRoomId) {
return chatMemberService.countActiveMembers(chatRoomId) >= MAX_MEMBER_COUNT;
}
}