-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: 인게임 입장 시 세션 ID 업데이트 로직 추가 * feat: 실시간 접속자 현황 파악 기능 구현 --------- Co-authored-by: marooo326 <[email protected]>
- Loading branch information
1 parent
a18549b
commit afc2ee5
Showing
8 changed files
with
140 additions
and
6 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
27 changes: 27 additions & 0 deletions
27
api/src/main/java/com/pgms/api/domain/online/OnlineController.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,27 @@ | ||
package com.pgms.api.domain.online; | ||
|
||
import java.util.Set; | ||
|
||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import com.pgms.api.domain.online.dto.OnlineMemberGetResponse; | ||
import com.pgms.coredomain.response.ApiResponse; | ||
import com.pgms.coresecurity.resolver.Account; | ||
import com.pgms.coresecurity.resolver.CurrentAccount; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
public class OnlineController { | ||
|
||
private final OnlineService onlineService; | ||
|
||
@GetMapping("/api/v1/online") | ||
public ResponseEntity<ApiResponse<Set<OnlineMemberGetResponse>>> getOnlineMembers( | ||
@CurrentAccount Account account) { | ||
return ResponseEntity.ok(ApiResponse.of(onlineService.getOnlineMembers(account))); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
api/src/main/java/com/pgms/api/domain/online/OnlineService.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,46 @@ | ||
package com.pgms.api.domain.online; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import com.pgms.api.domain.online.dto.OnlineMemberGetResponse; | ||
import com.pgms.coredomain.repository.GameRoomMemberRepository; | ||
import com.pgms.coreinfraredis.entity.OnlineMember; | ||
import com.pgms.coreinfraredis.repository.OnlineMemberRepository; | ||
import com.pgms.coresecurity.resolver.Account; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@Service | ||
@Transactional | ||
@RequiredArgsConstructor | ||
public class OnlineService { | ||
|
||
private final GameRoomMemberRepository gameRoomMemberRepository; | ||
private final OnlineMemberRepository onlineMemberRepository; | ||
|
||
public Set<OnlineMemberGetResponse> getOnlineMembers(Account account) { | ||
HashSet<OnlineMemberGetResponse> onlineMembers = new HashSet<>(); | ||
|
||
OnlineMember currentMember = new OnlineMember(account.id(), account.nickname()); | ||
onlineMemberRepository.save(currentMember); | ||
|
||
gameRoomMemberRepository.findAll() | ||
.forEach(gameRoomMember -> onlineMembers.add(new OnlineMemberGetResponse( | ||
gameRoomMember.getMemberId(), | ||
gameRoomMember.getNickname()))); | ||
|
||
Iterable<OnlineMember> onlineMembersIterable = onlineMemberRepository.findAll(); | ||
onlineMembersIterable.forEach(onlineMember -> { | ||
if (onlineMember != null) { | ||
onlineMembers.add(new OnlineMemberGetResponse( | ||
onlineMember.getId(), | ||
onlineMember.getNickname())); | ||
} | ||
}); | ||
return onlineMembers; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
api/src/main/java/com/pgms/api/domain/online/dto/OnlineMemberGetResponse.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,27 @@ | ||
package com.pgms.api.domain.online.dto; | ||
|
||
import java.util.Objects; | ||
|
||
public record OnlineMemberGetResponse( | ||
Long memberId, | ||
String nickname | ||
) { | ||
public static OnlineMemberGetResponse of(Long memberId, String nickname) { | ||
return new OnlineMemberGetResponse(memberId, nickname); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) | ||
return true; | ||
if (o == null || getClass() != o.getClass()) | ||
return false; | ||
OnlineMemberGetResponse that = (OnlineMemberGetResponse)o; | ||
return Objects.equals(memberId, that.memberId) && Objects.equals(nickname, that.nickname); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(memberId, nickname); | ||
} | ||
} |
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
17 changes: 17 additions & 0 deletions
17
core/core-infra-redis/src/main/java/com/pgms/coreinfraredis/entity/OnlineMember.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,17 @@ | ||
package com.pgms.coreinfraredis.entity; | ||
|
||
import org.springframework.data.redis.core.RedisHash; | ||
|
||
import jakarta.persistence.Id; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
@RedisHash(value = "onlineMember", timeToLive = 20L) | ||
public class OnlineMember { | ||
@Id | ||
private Long id; | ||
|
||
private String nickname; | ||
} |
8 changes: 8 additions & 0 deletions
8
...-infra-redis/src/main/java/com/pgms/coreinfraredis/repository/OnlineMemberRepository.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,8 @@ | ||
package com.pgms.coreinfraredis.repository; | ||
|
||
import org.springframework.data.repository.CrudRepository; | ||
|
||
import com.pgms.coreinfraredis.entity.OnlineMember; | ||
|
||
public interface OnlineMemberRepository extends CrudRepository<OnlineMember, Long> { | ||
} |