-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Conflicts: # src/main/java/com/tukorea/planding/domain/group/service/GroupInviteService.java
- Loading branch information
Showing
13 changed files
with
155 additions
and
55 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
19 changes: 19 additions & 0 deletions
19
src/main/java/com/tukorea/planding/domain/group/dto/response/GroupInviteMessageResponse.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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.tukorea.planding.domain.group.dto.response; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@AllArgsConstructor | ||
@Data | ||
@NoArgsConstructor | ||
public class GroupInviteMessageResponse { | ||
private String inviteCode; | ||
private Long groupRoomId; | ||
private String invitedUserCode; | ||
private Long invitingUserId; | ||
|
||
public static GroupInviteMessageResponse create(String inviteCode, Long groupRoomId, String invitedUserCode, Long invitingUserId) { | ||
return new GroupInviteMessageResponse(inviteCode, groupRoomId, invitedUserCode, invitingUserId); | ||
} | ||
} |
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
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
65 changes: 65 additions & 0 deletions
65
src/main/java/com/tukorea/planding/domain/group/service/RedisGroupInviteService.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 |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package com.tukorea.planding.domain.group.service; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.tukorea.planding.domain.group.dto.response.GroupInviteMessageResponse; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.redis.core.StringRedisTemplate; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.stream.Collectors; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class RedisGroupInviteService { | ||
|
||
private final StringRedisTemplate redisTemplate; | ||
private final ObjectMapper objectMapper; | ||
|
||
// ์ด๋ ์์ฑ | ||
public void createInvitation(String userCode, GroupInviteMessageResponse inviteDTO) { | ||
String key = "userInvites:" + userCode; // ์ ์ ๋ณ ํค | ||
String field = inviteDTO.getInviteCode(); // ์ด๋ ์ฝ๋๋ฅผ ํ๋๋ก ์ฌ์ฉ | ||
String value = convertObjectToJson(inviteDTO); // ์ด๋ ์ ๋ณด๋ฅผ JSON ๋ฌธ์์ด๋ก ๋ณํ | ||
|
||
if (value != null) { | ||
redisTemplate.opsForHash().put(key, field, value); | ||
redisTemplate.expire(key, 3, TimeUnit.HOURS); | ||
} | ||
} | ||
|
||
// ์ ์ ๋ณ ๋ชจ๋ ์ด๋ ์กฐํ | ||
public List<GroupInviteMessageResponse> getAllInvitations(String userCode) { | ||
String key = "userInvites:" + userCode; | ||
List<Object> values = redisTemplate.opsForHash().values(key); | ||
|
||
return values.stream() | ||
.map(value -> convertJsonToObject((String) value, GroupInviteMessageResponse.class)) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
// ํน์ ์ด๋ ์ญ์ | ||
public void deleteInvitation(String userCode, String inviteCode) { | ||
String key = "userInvites:" + userCode; | ||
redisTemplate.opsForHash().delete(key, inviteCode); | ||
} | ||
|
||
private String convertObjectToJson(Object obj) { | ||
try { | ||
return objectMapper.writeValueAsString(obj); | ||
} catch (JsonProcessingException e) { | ||
return null; | ||
} | ||
} | ||
|
||
private <T> T convertJsonToObject(String json, Class<T> clazz) { | ||
try { | ||
return objectMapper.readValue(json, clazz); | ||
} catch (IOException e) { | ||
return null; | ||
} | ||
} | ||
} |
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