Skip to content
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

socket user 조회 api 수정 #142

Merged
merged 3 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/docs/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ include::{snippets}/sample-controller-test/샘플_전체_조회/auto-section.ado
== user API

include::{snippets}/user-controller-test/유저_조회/auto-section.adoc[]
include::{snippets}/user-controller-test/코스_동시_접속_유저_조회/auto-section.adoc[]

=== Get socket users API

include::{snippets}/../../src/docs/custom-snippets/socket/user/get-socket-user-request.adoc[]
include::{snippets}/../../src/docs/custom-snippets/socket/user/get-socket-user-response.adoc[]

== pin API

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[source,http,options="nowrap"]
----
SEND /pub/{courseId}/user
EX /pub/1/user
----
18 changes: 18 additions & 0 deletions src/docs/custom-snippets/socket/user/get-socket-user-response.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[source,http,options="nowrap"]
----
SUBSCRIBE /sub/{courseId}/user
EX /sub/1/user
Content-Type: application/json
{
"code" : 0,
"message" : "실행에 성공했습니다.",
"data" : {
"total" : 1,
"users" : [
{
"userId": 1
}
]
}
}
----
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public BasicResponse<UserGetRes> getUser(

@GetMapping("/course")
public BasicResponse<UserGetResList> getCourseUser(@RequestParam Long courseId) {
// TODO delete
return BasicResponse.success(userService.getUsers(courseId));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.pcb.audy.domain.user.controller;

import com.pcb.audy.domain.user.dto.response.UserGetResList;
import com.pcb.audy.domain.user.service.UserService;
import com.pcb.audy.global.response.BasicResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.messaging.handler.annotation.DestinationVariable;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
public class UserSocketController {
private final UserService userService;

@MessageMapping("/{courseId}/user")
@SendTo("/sub/{courseId}/user")
public BasicResponse<UserGetResList> getCourseUser(@DestinationVariable Long courseId) {
return BasicResponse.success(userService.getUsers(courseId));
}
}
11 changes: 7 additions & 4 deletions src/main/java/com/pcb/audy/domain/user/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,13 @@ public UserGetResList getUsers(Long courseId) {
String key = COURSE_PREFIX + courseId;

List<SocketUserGetRes> users =
UserServiceMapper.INSTANCE.toUserGetResList(
redisProvider.getValues(key).stream()
.map(user -> objectMapper.convertValue(user, User.class))
.toList());
redisProvider.getValues(key).stream()
.map(
user ->
SocketUserGetRes.builder()
.userId(objectMapper.convertValue(user, Long.class))
.build())
.toList();

return UserGetResList.builder().users(users).total(users.size()).build();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.pcb.audy.domain.user.service;

import com.pcb.audy.domain.user.dto.response.SocketUserGetRes;
import com.pcb.audy.domain.user.dto.response.UserGetRes;
import com.pcb.audy.domain.user.entity.User;
import java.util.List;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

Expand All @@ -12,6 +10,4 @@ public interface UserServiceMapper {
UserServiceMapper INSTANCE = Mappers.getMapper(UserServiceMapper.class);

UserGetRes toUserGetRes(User user);

List<SocketUserGetRes> toUserGetResList(List<User> users);
}
Loading