-
Notifications
You must be signed in to change notification settings - Fork 0
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
Refact/#207 chatroom domain #214
Changes from all commits
2c0fc07
ca0a17a
49a33e6
356a21c
2aeb253
49ead95
3d658fe
4932e67
29844c4
313a92a
87a4ee0
6791371
48d1fc9
7b3b8f4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
services: | ||
mogakgo-db: | ||
image: mysql:8.2.0 | ||
container_name: mogakgo-mysql | ||
environment: | ||
MYSQL_ROOT_PASSWORD: root! | ||
MYSQL_DATABASE: mogakgo | ||
ports: | ||
- "3306:3306" | ||
mogakgo-redis: | ||
image: redis:latest | ||
container_name: mogakgo-redis | ||
ports: | ||
- "6379:6379" | ||
mogakgo-mongodb: | ||
image: mongo:latest | ||
container_name: mogakgo-mongodb | ||
environment: | ||
MONGI_INIT_DATABSE: mogakgo | ||
ports: | ||
- "27017:27017" |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,22 +2,19 @@ | |
|
||
import io.oeid.mogakgo.common.base.CursorPaginationInfoReq; | ||
import io.oeid.mogakgo.common.base.CursorPaginationResult; | ||
import io.oeid.mogakgo.domain.chat.application.dto.req.ChatRoomCreateReq; | ||
import io.oeid.mogakgo.domain.chat.application.dto.res.ChatDataRes; | ||
import io.oeid.mogakgo.domain.chat.application.dto.res.ChatRoomCreateRes; | ||
import io.oeid.mogakgo.domain.chat.application.dto.res.ChatRoomDataRes; | ||
import io.oeid.mogakgo.domain.chat.application.dto.res.ChatRoomPublicRes; | ||
import io.oeid.mogakgo.domain.chat.entity.ChatRoom; | ||
import io.oeid.mogakgo.domain.chat.infrastructure.ChatRepository; | ||
import io.oeid.mogakgo.domain.chat.infrastructure.ChatRoomRoomJpaRepository; | ||
import io.oeid.mogakgo.domain.chat.infrastructure.ChatUserJpaRepository; | ||
import io.oeid.mogakgo.domain.matching.exception.MatchingException; | ||
import io.oeid.mogakgo.domain.project.domain.entity.Project; | ||
import io.oeid.mogakgo.domain.project.exception.ProjectException; | ||
import io.oeid.mogakgo.domain.project.infrastructure.ProjectJpaRepository; | ||
import io.oeid.mogakgo.domain.user.application.UserCommonService; | ||
import io.oeid.mogakgo.domain.user.domain.User; | ||
import io.oeid.mogakgo.exception.code.ErrorCode404; | ||
import java.util.List; | ||
import java.util.UUID; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
|
@@ -31,55 +28,59 @@ public class ChatService { | |
|
||
private final UserCommonService userCommonService; | ||
private final ChatRoomRoomJpaRepository chatRoomRepository; | ||
private final ChatUserJpaRepository chatUserRepository; | ||
private final ChatRepository chatRepository; | ||
private final ProjectJpaRepository projectRepository; | ||
|
||
// μ±ν λ°© 리μ€νΈ μ‘°ν | ||
// TODO λ§μ§λ§ μ±ν κΈ°λ‘ κ°μ Έμ€κΈ° ꡬν | ||
public List<ChatRoomPublicRes> findAllChatRoomByUserId(Long userId) { | ||
findUserById(userId); | ||
return chatRoomRepository.findAllChatRoomByUserId(userId); | ||
public CursorPaginationResult<ChatRoomPublicRes> findAllChatRoomByUserId(Long userId, | ||
CursorPaginationInfoReq pageable) { | ||
log.info("findAllChatRoomByUserId - userId: {}", userId); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ππ» μ΄μ λ‘κ·Έ μ°λκ±° μΆκ°ν΄μΌνλλ° μ΄ λΆλΆλ 컨벀μ κ³ λ―Όν΄λ³΄λ©΄ μ’μ λ― ν©λλ€~ |
||
var chatRoomList = chatRoomRepository.getChatRoomList(userId, pageable.getCursorId(), | ||
pageable.getPageSize()); | ||
var result = chatRoomList.stream().map( | ||
chatRoom -> { | ||
var user = chatRoom.getOppositeUser(userId); | ||
ChatRoomPublicRes res = ChatRoomPublicRes.of(chatRoom, user); | ||
var chatMessage = chatRepository.findLastChatByCollection( | ||
chatRoom.getId().toString()); | ||
chatMessage.ifPresent( | ||
message -> res.addLastMessage(message.getMessage(), message.getCreatedAt())); | ||
return res; | ||
} | ||
).toList(); | ||
return CursorPaginationResult.fromDataWithExtraItemForNextCheck(result, | ||
pageable.getPageSize()); | ||
} | ||
|
||
// μ±ν λ°© μμ± | ||
@Transactional | ||
public ChatRoomCreateRes createChatRoom(Long creatorId, ChatRoomCreateReq request) { | ||
Project project = projectRepository.findById(request.getProjectId()) | ||
.orElseThrow(() -> new MatchingException(ErrorCode404.PROJECT_NOT_FOUND)); | ||
User creator = findUserById(creatorId); | ||
User sender = findUserById(request.getSenderId()); | ||
ChatRoom chatRoom = chatRoomRepository.save( | ||
ChatRoom.builder().project(project).creator(creator).sender(sender).build()); | ||
chatRepository.createCollection(chatRoom.getId()); | ||
return ChatRoomCreateRes.from(chatRoom); | ||
public void createChatRoom(Project project, User creator, User sender) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. μμ μ½λμμλ μ ν¨μ±μ κ²μ¬νλ λ‘μ§μ΄ μμλλ° μλ‘ λ°λ λ‘μ§μλ μλ κ² κ°μμ νΉμ μΌλΆλ¬ μ κ±°ν μ΄μ κ° μμκΉμ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. μ΄λ―Έ 맀μΉμλΉμ€μμ μ ν¨μ± κ²μ¬λ₯Ό μ§νν΄μ μΆκ°μ μΌλ‘ μ§νν νμκ° μλ€κ³ νλ¨νμ΅λλ€! |
||
ChatRoom chatRoom = chatRoomRepository.save(new ChatRoom(project)); | ||
chatUserRepository.save(chatRoom.join(creator)); | ||
chatUserRepository.save(chatRoom.join(sender)); | ||
chatRepository.createCollection(chatRoom.getId().toString()); | ||
} | ||
|
||
@Transactional | ||
public void leaveChatroom(Long userId, String chatRoomId) { | ||
var user = findUserById(userId); | ||
var chatRoom = findChatRoomById(chatRoomId); | ||
|
||
chatRoom.leaveUser(user); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. μ±ν λλ©μΈ 리ν©ν΄μ μ¬λ €μ£Όλ©΄ μ±ν λ°© λκ°κΈ° λ‘μ§ μμ νκ² λ€κ³ μκΈ°νμλλ° μ΄λ―Έ ꡬνμ΄ λ€ λμ΄μκ΅°μ,,,! μμΌλ‘λ 미리 μ§κ² λ€κ³ λ§ν΄μ£Όλ©΄ μ’μ κ² κ°μμπ |
||
// μ±ν λ°© λΉνμ±ν | ||
chatRoom.closeChat(); | ||
|
||
chatRoom.leave(user); | ||
} | ||
|
||
// μ±ν λ°© μ‘°ν | ||
public CursorPaginationResult<ChatDataRes> findAllChatInChatRoom(Long userId, String chatRoomId, CursorPaginationInfoReq pageable) { | ||
var user = findUserById(userId); | ||
var chatRoom = findChatRoomById(chatRoomId); | ||
chatRoom.validateContainsUser(user); | ||
public CursorPaginationResult<ChatDataRes> findAllChatInChatRoom(Long userId, String chatRoomId, | ||
CursorPaginationInfoReq pageable) { | ||
verifyChatUser(chatRoomId, userId); | ||
return chatRepository.findAllByCollection(chatRoomId, pageable); | ||
} | ||
|
||
public ChatRoomDataRes findChatRoomDetailData(Long userId, String chatRoomId) { | ||
var user = findUserById(userId); | ||
var chatRoom = findChatRoomById(chatRoomId); | ||
chatRoom.validateContainsUser(user); | ||
var project = projectRepository.findById(chatRoom.getProject().getId()) | ||
.orElseThrow(() -> new ProjectException(ErrorCode404.PROJECT_NOT_FOUND)); | ||
return ChatRoomDataRes.from(project.getMeetingInfo()); | ||
log.info("findChatRoomDetailData - userId: {}, chatRoomId: {}", userId, chatRoomId); | ||
verifyChatUser(chatRoomId, userId); | ||
return chatRoomRepository.getChatDetailData(userId, UUID.fromString(chatRoomId)); | ||
} | ||
|
||
private ChatRoom findChatRoomById(String chatRoomId) { | ||
|
@@ -91,4 +92,14 @@ private User findUserById(Long userId) { | |
return userCommonService.getUserById(userId); | ||
} | ||
|
||
private void verifyChatUser(String chatRoomIdStr, Long userId) { | ||
log.info("verifyChatUser - chatRoomId: {}, userId: {}", chatRoomIdStr, userId); | ||
UUID chatRoomId = UUID.fromString(chatRoomIdStr); | ||
chatUserRepository.findByChatRoomIdAndUserId(chatRoomId, userId) | ||
.ifPresentOrElse(null, | ||
() -> { | ||
throw new MatchingException(ErrorCode404.CHAT_USER_NOT_FOUND); | ||
}); | ||
} | ||
|
||
} |
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sort.Directionκ³Ό Directionμ μ°¨μ΄κ° λκ°μ? (κΆκΈ)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
λμΌν ν΄λμ€μμ!