-
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
Feat #54 이미지 추가해서 반환 #54
The head ref may contain hidden characters: "feat/#47/\uC774\uBBF8\uC9C0-\uCD94\uAC00\uD574\uC11C-\uBC18\uD658"
Changes from all commits
f5aa92f
a75841a
b9b304c
d477c7c
2129b55
8dca3d8
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,10 @@ | ||
package com.gachtaxi.domain.chat.dto.response; | ||
|
||
public record ChattingRoomCountResponse( | ||
Long roomId, | ||
Long totalParticipantCount | ||
) { | ||
public static ChattingRoomCountResponse of(Long roomId, Long totalParticipantCount) { | ||
return new ChattingRoomCountResponse(roomId, totalParticipantCount); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,35 @@ | ||
package com.gachtaxi.domain.chat.service; | ||
|
||
import com.gachtaxi.domain.chat.exception.ChattingRoomNotFoundException; | ||
import com.gachtaxi.domain.chat.exception.UnSubscriptionException; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.redis.core.RedisTemplate; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.Optional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class ChattingRedisService { | ||
public static final String REDIS_CHAT_KEY_PREFIX = "ROOM:"; | ||
|
||
private final RedisTemplate<String, Object> chatRoomRedisTemplate; | ||
|
||
public void saveSubscribeMember(long roomId, long senderId) { | ||
public void saveSubscribeMember(long roomId, long senderId, String profilePicture) { | ||
String key = getKey(roomId); | ||
|
||
chatRoomRedisTemplate.opsForSet().add(key, senderId); | ||
chatRoomRedisTemplate.opsForHash().put(key, String.valueOf(senderId), profilePicture); | ||
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. 기존 opsForSet을 활용하여 사용자 정보를 저장하던 방식을 opsForHash를 사용해서 사용자의 프로필 사진을 함께 저장하는 로직으로 변경된걸 확인했습니다 ! 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. 이벤트 리스너를 구현을 해서, 웹소켓 구독 해제시 데이터가 제거 되도록 구현했고, 테스트도 완료했습니다! |
||
} | ||
|
||
public boolean isActive(long roomId, long senderId) { | ||
String key = getKey(roomId); | ||
|
||
return Boolean.TRUE.equals(chatRoomRedisTemplate.opsForSet().isMember(key, senderId)); | ||
return Boolean.TRUE.equals(chatRoomRedisTemplate.opsForHash().hasKey(key, String.valueOf(senderId))); | ||
} | ||
|
||
public void removeSubscribeMember(long roomId, long senderId) { | ||
String key = getKey(roomId); | ||
|
||
chatRoomRedisTemplate.opsForSet().remove(key, senderId); | ||
chatRoomRedisTemplate.opsForHash().delete(key, String.valueOf(senderId)); | ||
} | ||
|
||
public void checkSubscriptionStatus(long roomId, long senderId) { | ||
|
@@ -40,13 +41,15 @@ public void checkSubscriptionStatus(long roomId, long senderId) { | |
public long getSubscriberCount(long roomId) { | ||
String key = getKey(roomId); | ||
|
||
Long size = chatRoomRedisTemplate.opsForSet().size(key); | ||
return chatRoomRedisTemplate.opsForHash().size(key); | ||
} | ||
|
||
if (size == null) { | ||
throw new ChattingRoomNotFoundException(); | ||
} | ||
public String getProfilePicture(long roomId, long senderId) { | ||
String key = getKey(roomId); | ||
|
||
return size; | ||
return Optional.ofNullable(chatRoomRedisTemplate.opsForHash().get(key, String.valueOf(senderId))) | ||
.map(Object::toString) | ||
.orElse(null); | ||
} | ||
|
||
private String getKey(long roomId) { | ||
|
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.
사진도 함께 저장하는군요!!
좋은 방식인 것 같습니다!!