Skip to content

Commit

Permalink
feat: 모임 참여자 정보 조회 기능을 구현 (#192)
Browse files Browse the repository at this point in the history
* feat: 모임 참여자 정보 조회 API 기능 구현 (#178)

* test: 테스트 코드 구현 및 테스트 (#178)
  • Loading branch information
choidongkuen authored Feb 11, 2024
1 parent 53d28ce commit 016c3c5
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/main/java/net/teumteum/alert/app/AlertHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private String toCommaString(List<Long> ids) {
for (int i = 0; i < ids.size() - 1; i++) {
stringBuilder.append(ids.get(i)).append(",");
}
stringBuilder.append(ids.getLast());
stringBuilder.append(ids.get(ids.size() - 1));
return stringBuilder.toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import net.teumteum.meeting.domain.Topic;
import net.teumteum.meeting.domain.request.CreateMeetingRequest;
import net.teumteum.meeting.domain.request.UpdateMeetingRequest;
import net.teumteum.meeting.domain.response.MeetingParticipantsResponse;
import net.teumteum.meeting.domain.response.MeetingResponse;
import net.teumteum.meeting.domain.response.MeetingsResponse;
import net.teumteum.meeting.model.PageDto;
Expand Down Expand Up @@ -97,6 +98,12 @@ public void deleteParticipant(@PathVariable("meetingId") Long meetingId) {
meetingService.cancelParticipant(meetingId, userId);
}

@GetMapping("/{meetingId}/participants")
@ResponseStatus(HttpStatus.OK)
public List<MeetingParticipantsResponse> getParticipants(@PathVariable("meetingId") Long meetingId) {
return meetingService.getParticipants(meetingId);
}

@PostMapping("/{meetingId}/reports")
@ResponseStatus(HttpStatus.CREATED)
public void reportMeeting(@PathVariable("meetingId") Long meetingId) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package net.teumteum.meeting.domain.response;

import net.teumteum.user.domain.User;

public record MeetingParticipantsResponse(
Long id,
Long characterId,
String name,
String job
) {

public static MeetingParticipantsResponse of(
User user
) {
return new MeetingParticipantsResponse(
user.getId(),
user.getCharacterId(),
user.getName(),
user.getJob().getDetailJobClass()
);
}

}
15 changes: 15 additions & 0 deletions src/main/java/net/teumteum/meeting/service/MeetingService.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.teumteum.meeting.service;

import java.util.List;
import java.util.Optional;
import java.util.Set;
import lombok.RequiredArgsConstructor;
import net.teumteum.meeting.domain.ImageUpload;
Expand All @@ -11,9 +12,11 @@
import net.teumteum.meeting.domain.Topic;
import net.teumteum.meeting.domain.request.CreateMeetingRequest;
import net.teumteum.meeting.domain.request.UpdateMeetingRequest;
import net.teumteum.meeting.domain.response.MeetingParticipantsResponse;
import net.teumteum.meeting.domain.response.MeetingResponse;
import net.teumteum.meeting.domain.response.MeetingsResponse;
import net.teumteum.meeting.model.PageDto;
import net.teumteum.user.domain.UserConnector;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
Expand All @@ -27,6 +30,7 @@ public class MeetingService {

private final MeetingRepository meetingRepository;
private final ImageUpload imageUpload;
private final UserConnector userConnector;

@Transactional
public MeetingResponse createMeeting(List<MultipartFile> images, CreateMeetingRequest meetingRequest, Long userId) {
Expand Down Expand Up @@ -148,6 +152,17 @@ public void cancelParticipant(Long meetingId, Long userId) {
existMeeting.cancelParticipant(userId);
}

@Transactional(readOnly = true)
public List<MeetingParticipantsResponse> getParticipants(Long meetingId) {
var existMeeting = getMeeting(meetingId);

return existMeeting.getParticipantUserIds().stream()
.map(userConnector::findUserById)
.flatMap(Optional::stream)
.map(MeetingParticipantsResponse::of)
.toList();
}

@Transactional
public void addBookmark(Long meetingId, Long userId) {
var existMeeting = getMeeting(meetingId);
Expand Down
8 changes: 8 additions & 0 deletions src/test/java/net/teumteum/integration/Api.java
Original file line number Diff line number Diff line change
Expand Up @@ -213,4 +213,12 @@ ResponseSpec registerUserReview(String accessToken, Long meetingId, ReviewRegist
.bodyValue(request)
.exchange();
}

ResponseSpec getMeetingParticipants(String accessToken, Long meetingId) {
return webTestClient
.get()
.uri("/meetings/" + meetingId + "/participants")
.header(HttpHeaders.AUTHORIZATION, accessToken)
.exchange();
}
}
19 changes: 17 additions & 2 deletions src/test/java/net/teumteum/integration/MeetingIntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
class MeetingIntegrationTest extends IntegrationTest {

public static final int DEFAULT_QUERY_SIZE = 5;
public static final Pageable FIRST_PAGE_NATION = PageRequest.of(0, DEFAULT_QUERY_SIZE, Sort.Direction.DESC, "id");
private static final String VALID_TOKEN = "VALID_TOKEN";
private static final String INVALID_TOKEN = "IN_VALID_TOKEN";
public static final Pageable FIRST_PAGE_NATION = PageRequest.of(0, DEFAULT_QUERY_SIZE, Sort.Direction.DESC, "id");

@Nested
@DisplayName("단일 미팅 조회 API는")
Expand Down Expand Up @@ -288,7 +288,6 @@ void Return_400_bad_request_if_already_joined_meeting_id_received() {

securityContextSetting.set(me.getId());

loginContext.setUserId(me.getId());
api.joinMeeting(VALID_TOKEN, meeting.getId());
// when
var result = api.joinMeeting(VALID_TOKEN, meeting.getId());
Expand Down Expand Up @@ -472,4 +471,20 @@ void Return_400_bad_request_if_not_bookmarked_meeting_id_received() {
.expectBody(ErrorResponse.class);
}
}

@Nested
@DisplayName("미팅 참가자 조회 API는")
class Get_meeting_participants_api {

@Test
@DisplayName("참여한 meeting id 가 주어지면, 참여한 참가자들의 정보가 주어진다.")
void Get_participants_if_exist_meeting_id_received() {
// given
var meeting = repository.saveAndGetOpenMeeting();
// when
var result = api.getMeetingParticipants(VALID_TOKEN, meeting.getId());
// then
result.expectStatus().isOk();
}
}
}

0 comments on commit 016c3c5

Please sign in to comment.