Skip to content

Commit

Permalink
Merge pull request #89 from catchroom/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
sungjiwoon authored Jan 27, 2024
2 parents 476cb67 + a39bdf3 commit ddfebe3
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public class ChatRoomListGetResponse implements Serializable {

private ChatMessageDto lastChatmessageDto;

private Boolean isNego;


public void updateChatMessageDto(ChatMessageDto chatMessageDto) {
this.lastChatmessageDto = chatMessageDto;
Expand All @@ -53,10 +55,31 @@ public void changePartnerInfo() {
this.myNickName = partnerNickName;
this.partnerNickName = tmp;

if (loginUserIdentity.equals(UserIdentity.SELLER)) {
if (this.loginUserIdentity.equals(UserIdentity.SELLER)) {
this.loginUserIdentity = UserIdentity.BUYER;
} else if (loginUserIdentity.equals(UserIdentity.BUYER)) {
} else if (this.loginUserIdentity.equals(UserIdentity.BUYER)) {
this.loginUserIdentity = UserIdentity.SELLER;
}
}

@Override
public String toString() {
return "ChatRoomListGetResponse{" +
"chatRoomNumber='" + chatRoomNumber + '\'' +
", buyerId=" + buyerId +
", sellerId=" + sellerId +
", productId=" + productId +
", accommodationName='" + accommodationName + '\'' +
", sellPrice=" + sellPrice +
", loginUserIdentity=" + loginUserIdentity +
", accommodationUrl='" + accommodationUrl + '\'' +
", myNickName='" + myNickName + '\'' +
", partnerNickName='" + partnerNickName + '\'' +
", dealState=" + dealState +
", buyerState=" + buyerState +
", sellerState=" + sellerState +
", lastChatmessageDto=" + lastChatmessageDto +
", isNego=" + isNego +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory connec
redisTemplate.setKeySerializer(new StringRedisSerializer());
redisTemplate.setValueSerializer(new Jackson2JsonRedisSerializer<>(String.class));

redisTemplate.setHashKeySerializer(new StringRedisSerializer());
redisTemplate.setHashValueSerializer(new Jackson2JsonRedisSerializer<>(Object.class));

return redisTemplate;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import com.catchroom.chat.chatroom.dto.ChatRoomListGetResponse;
import com.catchroom.chat.message.dto.ChatMessageDto;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.annotation.Resource;
import java.util.Arrays;
Expand Down Expand Up @@ -38,6 +36,8 @@ public class ChatRoomRedisRepository {

private final RedisTemplate<String, Object> redisTemplate;

private final ObjectMapper objectMapper;

@Resource(name = "redisTemplate")
private HashOperations<String, String, ChatRoomListGetResponse> opsHashChatRoom;

Expand Down Expand Up @@ -78,11 +78,11 @@ public void deleteChatRoom(Long userId, String roomId) {
}

public ChatRoomListGetResponse getChatRoom(Long userId, String roomId) {
return opsHashChatRoom.get(getChatRoomKey(userId), roomId);
return objectMapper.convertValue(opsHashChatRoom.get(getChatRoomKey(userId), roomId), ChatRoomListGetResponse.class);
}

public List<ChatRoomListGetResponse> getChatRoomList(Long userId) {
return opsHashChatRoom.values(getChatRoomKey(userId));
return objectMapper.convertValue(opsHashChatRoom.values(getChatRoomKey(userId)), new TypeReference<>() {});
}


Expand All @@ -91,7 +91,7 @@ public void setLastChatMessage(String roomId, ChatMessageDto chatMessageDto) {
}

public ChatMessageDto getLastMessage(String roomId) {
return opsHashLastChatMessage.get(CHAT_ROOM, roomId);
return objectMapper.convertValue(opsHashLastChatMessage.get(CHAT_ROOM, roomId), ChatMessageDto.class);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,12 @@ private void setNewChatRoomInfo(ChatMessageDto chatMessage, ChatRoomListGetRespo
newChatRoomListResponse.changePartnerInfo(); //๋‹‰๋„ค์ž„ ์ฒด์ธ์ง€
chatRoomRedisRepository.setChatRoom(newChatRoomListResponse.getBuyerId(), chatMessage.getRoomId(), newChatRoomListResponse);

} else {
} else if (newChatRoomListResponse.getLoginUserIdentity().equals(UserIdentity.BUYER)){
if (!chatMessage.getType().equals(MessageType.DELETE)) {
chatRoomRedisRepository.setChatRoom(newChatRoomListResponse.getBuyerId(),
chatMessage.getRoomId(), newChatRoomListResponse);
}

newChatRoomListResponse.changePartnerInfo(); //๋‹‰๋„ค์ž„ ์ฒด์ธ์ง€
chatRoomRedisRepository.setChatRoom(newChatRoomListResponse.getSellerId(), chatMessage.getRoomId(), newChatRoomListResponse);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.catchroom.chat.message.repository;

import static org.junit.jupiter.api.Assertions.*;

import com.catchroom.chat.chatroom.dto.ChatRoomListGetResponse;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.List;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
class ChatRoomRedisRepositoryTest {

@Autowired
private ChatRoomRedisRepository chatRoomRedisRepository;

@Autowired
ObjectMapper objectMapper;

Logger log = (Logger) LoggerFactory.getLogger(ChatRoomRedisRepositoryTest.class);

@Test
void ์ฑ„ํŒ…๋ฐฉ_๊ฐ’_์ €์žฅ() {
Long userId = 68L;
}

@Test
void ์ฑ„ํŒ…๋ฐฉ_๊ฐ’์ด_์ œ๋Œ€๋กœ_์ €์žฅ๋์„๊นŒ() {
Long userId = 10000L;
List<ChatRoomListGetResponse> chatRoomListGetResponseList = chatRoomRedisRepository.getChatRoomList(userId);
for (ChatRoomListGetResponse chatRoomListGetResponse : chatRoomListGetResponseList) {
log.info(
chatRoomListGetResponse.toString()
);
}
}

@Test
void ์ฑ„ํŒ…๋ฐฉ_๊ฐ’์ด_์ œ๋Œ€๋กœ_๋ถˆ๋Ÿฌ์™€์งˆ๊นŒ() {
Long userId = 10000L;
ChatRoomListGetResponse chatRoomListGetResponse = chatRoomRedisRepository.getChatRoom(userId, "c29cd80e-d289-49ff-ac91-f3b32dd4b633");
log.info(chatRoomListGetResponse.toString());
}
}

0 comments on commit ddfebe3

Please sign in to comment.