Skip to content

Commit

Permalink
merge: 컨퍼런스 참여자 목록 조회하기 + career -> activity로 수정
Browse files Browse the repository at this point in the history
Feature/#112 컨퍼런스 참여자 목록 조회하기
  • Loading branch information
hong-sile authored Jul 27, 2023
2 parents 23a6023 + a49b820 commit 41994eb
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 12 deletions.
11 changes: 11 additions & 0 deletions backend/emm-sale/src/docs/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,17 @@ include::{snippets}/find-events/http-response.adoc[]
.HTTP response 설명
include::{snippets}/find-events/response-fields.adoc[]

=== `GET` : 행사 참여자 목록 조회

.HTTP request
include::{snippets}/find-participants/http-request.adoc[]

.HTTP response
include::{snippets}/find-participants/http-response.adoc[]

.HTTP response 설명
include::{snippets}/find-participants/response-fields.adoc[]

== Comment

=== `GET` : 댓글 모두 조회
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
import com.emmsale.event.application.EventService;
import com.emmsale.event.application.dto.EventDetailResponse;
import com.emmsale.event.application.dto.EventParticipateRequest;
import com.emmsale.member.domain.Member;
import com.emmsale.event.application.dto.EventResponse;
import com.emmsale.event.application.dto.ParticipantResponse;
import com.emmsale.member.domain.Member;
import java.time.LocalDate;
import java.util.List;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -49,11 +50,16 @@ public ResponseEntity<String> participateEvent(
.build();
}

@GetMapping("/{id}/participants")
public ResponseEntity<List<ParticipantResponse>> findParticipants(@PathVariable final Long id) {
final List<ParticipantResponse> responses = eventService.findParticipants(id);
return ResponseEntity.ok(responses);
}

@GetMapping
public ResponseEntity<List<EventResponse>> findEvents(@RequestParam final int year,
@RequestParam final int month, @RequestParam(required = false) final String tag,
@RequestParam(required = false) final String status) {
return ResponseEntity.ok(eventService.findEvents(LocalDate.now(), year, month, tag, status));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
import static java.util.Comparator.comparing;
import static java.util.stream.Collectors.groupingBy;
import static java.util.stream.Collectors.toList;
import static java.util.stream.Collectors.toUnmodifiableList;

import com.emmsale.event.application.dto.EventDetailResponse;
import com.emmsale.event.application.dto.EventResponse;
import com.emmsale.event.application.dto.ParticipantResponse;
import com.emmsale.event.domain.Event;
import com.emmsale.event.domain.EventStatus;
import com.emmsale.event.domain.EventTag;
Expand Down Expand Up @@ -79,6 +81,16 @@ public List<EventResponse> findEvents(final LocalDate nowDate, final int year, f
return filterEventResponsesByStatus(statusName, sortAndGroupByStatus);
}

@Transactional(readOnly = true)
public List<ParticipantResponse> findParticipants(final Long eventId) {
final Event event = eventRepository.findById(eventId)
.orElseThrow(() -> new EventException(NOT_FOUND_EVENT));
return event.getParticipants().stream()
.sorted(comparing(Participant::getId))
.map(ParticipantResponse::from)
.collect(toUnmodifiableList());
}

private void validateYearAndMonth(final int year, final int month) {
if (year < MIN_YEAR) {
throw new EventException(INVALID_YEAR);
Expand Down Expand Up @@ -145,4 +157,6 @@ private List<EventResponse> filterEventResponsesByStatus(final String statusName
private boolean isExistStatusName(final String statusName) {
return statusName != null;
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.emmsale.event.application.dto;

import com.emmsale.event.domain.Participant;
import com.emmsale.member.domain.Member;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
@Getter
public class ParticipantResponse {

private final Long id;
private final Long memberId;
private final String name;
private final String imageUrl;
private final String description;

public static ParticipantResponse from(final Participant participant) {
final Member member = participant.getMember();
return new ParticipantResponse(participant.getId(), member.getId(), member.getName(),
member.getImageUrl(), member.getDescription());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class Event extends BaseEntity {
private List<EventTag> tags = new ArrayList<>();
@OneToMany(mappedBy = "event")
private List<Comment> comments;
@OneToMany(mappedBy = "event",cascade = CascadeType.ALL)
@OneToMany(mappedBy = "event", cascade = CascadeType.ALL)
private List<Participant> participants = new ArrayList<>();

public Event(
Expand Down Expand Up @@ -74,9 +74,7 @@ public void validateAlreadyParticipate(final Member member) {

private boolean isAlreadyParticipate(final Member member) {
return participants.stream()
.map(participant -> participant.isSameMember(member))
.findAny()
.isPresent();
.anyMatch(participant -> participant.isSameMember(member));
}

public EventStatus calculateEventStatus(LocalDate now) {
Expand Down
14 changes: 8 additions & 6 deletions backend/emm-sale/src/main/resources/data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,24 @@ insert into tag(id, name)
values (5, 'AI');

insert into event(id, name, start_date, end_date, location, information_url, created_at, updated_at)
values (1, '인프콘 2023', '2023-06-01T12:00:00', '2023-09-01T12:00:00', '코엑스', 'https://~~~',
values (1, '인프콘 2023', '2023-06-01T12:00:00', '2023-09-01T12:00:00', '코엑스', 'https://www.naver.com',
CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP());
insert into event(id, name, start_date, end_date, location, information_url, created_at, updated_at)
values (2, 'AI 컨퍼런스', '2023-07-22T12:00:00', '2023-07-30T12:00:00', '코엑스', 'https://~~~',
values (2, 'AI 컨퍼런스', '2023-07-22T12:00:00', '2023-07-30T12:00:00', '코엑스', 'https://www.naver.com',
CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP());
insert into event(id, name, start_date, end_date, location, information_url, created_at, updated_at)
values (3, '모바일 컨퍼런스', '2023-08-03T12:00:00', '2023-09-03T12:00:00', '코엑스', 'https://~~~',
values (3, '모바일 컨퍼런스', '2023-08-03T12:00:00', '2023-09-03T12:00:00', '코엑스', 'https://www.naver.com',
CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP());
insert into event(id, name, start_date, end_date, location, information_url, created_at, updated_at)
values (4, '안드로이드 컨퍼런스', '2023-06-29T12:00:00', '2023-07-16T12:00:00', '코엑스', 'https://~~~',
values (4, '안드로이드 컨퍼런스', '2023-06-29T12:00:00', '2023-07-16T12:00:00', '코엑스',
'https://www.naver.com',
CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP());
insert into event(id, name, start_date, end_date, location, information_url, created_at, updated_at)
values (5, '웹 컨퍼런스', '2023-07-03T12:00:00', '2023-08-03T12:00:00', '코엑스', 'https://~~~',
values (5, '웹 컨퍼런스', '2023-07-03T12:00:00', '2023-08-03T12:00:00', '코엑스', 'https://www.naver.com',
CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP());
insert into event(id, name, start_date, end_date, location, information_url, created_at, updated_at)
values (6, '옛날 웹 컨퍼런스', '2022-07-03T12:00:00', '2022-08-03T12:00:00', '코엑스', 'https://~~~',
values (6, '옛날 웹 컨퍼런스', '2022-07-03T12:00:00', '2022-08-03T12:00:00', '코엑스',
'https://www.naver.com',
CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP());

insert into event_tag(id, event_id, tag_id)
Expand Down
3 changes: 3 additions & 0 deletions backend/emm-sale/src/main/resources/http/event.http
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,6 @@ Authorization: bearer eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxIiwiaWF0IjoxNjkwMTk2OTY5L
{
"memberId": 1
}

### 행사 참여자 목록 조회
GET http://localhost:8080/events/1/participants
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.emmsale.event.application.dto.EventDetailResponse;
import com.emmsale.event.application.dto.EventParticipateRequest;
import com.emmsale.event.application.dto.EventResponse;
import com.emmsale.event.application.dto.ParticipantResponse;
import com.emmsale.helper.MockMvcTestHelper;
import java.time.LocalDate;
import java.time.LocalDateTime;
Expand Down Expand Up @@ -155,4 +156,31 @@ void findEvents() throws Exception {
.andDo(document("find-events", requestParameters, responseFields));
}

@Test
@DisplayName("행사의 참여자를 전체 조회할 수 있다.")
void findParticipants() throws Exception {
//given
final Long eventId = 1L;
final ResponseFieldsSnippet responseFields = responseFields(
fieldWithPath("[].id").type(JsonFieldType.NUMBER).description("참여자 식별자"),
fieldWithPath("[].memberId").type(JsonFieldType.NUMBER).description("member의 식별자"),
fieldWithPath("[].name").type(JsonFieldType.STRING).description("member 이름"),
fieldWithPath("[].imageUrl").type(JsonFieldType.STRING).description("프로필 이미지 url"),
fieldWithPath("[].description").type(JsonFieldType.STRING).description("한줄 자기 소개")
);
final List<ParticipantResponse> responses = List.of(
new ParticipantResponse(1L, 1L, "스캇", "imageUrl",
"토마토 던지는 사람"),
new ParticipantResponse(2L, 2L, "홍실", "imageUrl",
"토마토 맞는 사람")
);

when(eventService.findParticipants(eventId))
.thenReturn(responses);

//when && then
mockMvc.perform(get(format("/events/%s/participants", eventId)))
.andExpect(status().isOk())
.andDo(document("find-participants", responseFields));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import com.emmsale.event.application.dto.EventDetailResponse;
import com.emmsale.event.application.dto.EventResponse;
import com.emmsale.event.application.dto.ParticipantResponse;
import com.emmsale.event.domain.Event;
import com.emmsale.event.domain.EventTag;
import com.emmsale.event.domain.repository.EventRepository;
Expand Down Expand Up @@ -296,4 +297,30 @@ void findEvents_status_filter_fail() {
.hasMessage(EventExceptionType.INVALID_STATUS.errorMessage());
}
}

@Test
@DisplayName("event의 id로 참여자 목록을 조회할 수 있다.")
void findParticipants() {
// given
final Event 인프콘 = eventRepository.save(eventFixture());
final Member 멤버1 = memberRepository.save(new Member(123L, "image1.com", "멤버1"));
final Member 멤버2 = memberRepository.save(new Member(124L, "image2.com", "멤버2"));

final Long 멤버1__ID = eventService.participate(인프콘.getId(), 멤버1.getId(), 멤버1);
final Long 멤버2__ID = eventService.participate(인프콘.getId(), 멤버2.getId(), 멤버2);

//when
final List<ParticipantResponse> actual = eventService.findParticipants(인프콘.getId());

final List<ParticipantResponse> expected = List.of(
new ParticipantResponse(멤버1__ID, 멤버1.getId(), 멤버1.getName(), 멤버1.getImageUrl(),
멤버1.getDescription()),
new ParticipantResponse(멤버2__ID, 멤버2.getId(), 멤버2.getName(), 멤버2.getImageUrl(),
멤버2.getDescription())
);
//then
assertThat(actual)
.usingRecursiveFieldByFieldElementComparator()
.containsExactlyInAnyOrderElementsOf(expected);
}
}

0 comments on commit 41994eb

Please sign in to comment.