-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor: ChatCategory 변경 * refactor: Chat 데이터 100개만 Redis에 저장 - 첫 페이지 조회가 가장 많이 이루어질 것을 예상하여 최신 채팅 데이터 100개만 Redis에 저장한다. * test: 테스트 코드 변경 * refactor: 채팅방 관련 로직 변경 - ChatUser에 isDeleted 컬럼 추가 - 채팅방 나갈 때 채팅방에 아무도 없을 경우 삭제 - 내 채팅방 목록 조회
- Loading branch information
Showing
19 changed files
with
222 additions
and
95 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
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
9 changes: 6 additions & 3 deletions
9
src/main/java/com/palettee/chat/repository/ChatImageRepository.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 |
---|---|---|
@@ -1,9 +1,12 @@ | ||
package com.palettee.chat.repository; | ||
|
||
import com.palettee.chat.domain.*; | ||
import io.lettuce.core.dynamic.annotation.Param; | ||
import org.springframework.data.jpa.repository.*; | ||
|
||
public interface ChatImageRepository | ||
extends JpaRepository<ChatImage, Long> { | ||
|
||
public interface ChatImageRepository extends JpaRepository<ChatImage, Long> { | ||
@Modifying | ||
@Query("DELETE FROM ChatImage ci WHERE ci.chat IN (SELECT c FROM Chat c WHERE c.chatRoom.id = :chatRoomId)") | ||
void bulkDeleteChatImagesByChatRoomId(@Param("chatRoomId") Long chatRoomId); | ||
} | ||
|
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
25 changes: 22 additions & 3 deletions
25
src/main/java/com/palettee/chat/repository/ChatUserRepository.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 |
---|---|---|
@@ -1,13 +1,32 @@ | ||
package com.palettee.chat.repository; | ||
|
||
import com.palettee.chat.domain.*; | ||
import com.palettee.chat_room.domain.ChatRoom; | ||
import com.palettee.user.domain.User; | ||
import org.springframework.data.jpa.repository.*; | ||
import org.springframework.data.repository.query.Param; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public interface ChatUserRepository extends JpaRepository<ChatUser, Long> { | ||
Optional<ChatUser> findByChatRoomAndUser(ChatRoom chatRoom, User user); | ||
boolean existsByChatRoomAndUser(ChatRoom chatRoom, User user); | ||
@Query("SELECT cu from ChatUser cu " + | ||
"WHERE cu.chatRoom.id = :chatRoomId " + | ||
"AND cu.user.id = :userId " + | ||
"AND cu.isDeleted = :isDeleted ") | ||
Optional<ChatUser> findByChatRoomAndUser(@Param("chatRoomId") Long chatRoomId, | ||
@Param("userId") Long userId, | ||
@Param("isDeleted") boolean isDeleted); | ||
|
||
@Query("SELECT count(cu) from ChatUser cu WHERE cu.chatRoom.id = :chatRoomId And cu.isDeleted = :isDeleted") | ||
int countChatUsersByChatRoom(@Param("chatRoomId") Long chatRoomId, | ||
@Param("isDeleted") boolean isDeleted); | ||
|
||
@Modifying | ||
@Query("delete from ChatUser cu where cu.chatRoom.id = :chatRoomId") | ||
void deleteAllByChatRoomId(@Param("chatRoomId") Long chatRoomId); | ||
|
||
@Query("select cu from ChatUser cu join fetch cu.user where cu.chatRoom in " + | ||
"(select cu2.chatRoom from ChatUser cu2 where cu2.user = :user)" + | ||
"and cu.user <> :user") | ||
List<ChatUser> getChatUsersByMe(@Param("user") User user); | ||
} |
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
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,17 @@ | ||
package com.palettee.chat.service; | ||
|
||
import com.palettee.chat.repository.ChatRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
public class ChatService { | ||
private final ChatRepository chatRepository; | ||
|
||
public void deleteChats(Long chatRoomId) { | ||
chatRepository.bulkDeleteChatsByChatRoomId(chatRoomId); | ||
} | ||
} |
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
Oops, something went wrong.