Skip to content

Commit

Permalink
Merge branch 'backend-main' of https://github.com/woowacourse-teams/2…
Browse files Browse the repository at this point in the history
…023-emmsale into Feature/#156-관리자_권한_설정
  • Loading branch information
amaran-th committed Nov 27, 2023
2 parents 98c5c3d + 42ab973 commit 42a2a52
Show file tree
Hide file tree
Showing 15 changed files with 293 additions and 202 deletions.
142 changes: 80 additions & 62 deletions backend/emm-sale/src/documentTest/java/com/emmsale/FeedApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,11 @@
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import com.emmsale.feed.application.dto.FeedDetailResponse;
import com.emmsale.feed.application.dto.FeedDetailResponse.WriterProfileResponse;
import com.emmsale.feed.application.dto.FeedListResponse;
import com.emmsale.feed.application.dto.FeedSimpleResponse;
import com.emmsale.feed.application.dto.FeedResponseRefactor;
import com.emmsale.feed.application.dto.FeedUpdateRequest;
import com.emmsale.feed.application.dto.FeedUpdateResponse;
import java.time.LocalDate;
import com.emmsale.member.application.dto.MemberReferenceResponse;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.Collections;
import java.util.List;
import org.junit.jupiter.api.DisplayName;
Expand All @@ -36,34 +32,53 @@

class FeedApiTest extends MockMvcTestHelper {

private static final MemberReferenceResponse MEMBER_REFERENCE_RESPONSE = new MemberReferenceResponse(
2L,
"멤버",
"멤버 설명",
"멤버 이미지url",
"멤버 깃허브 url"
);
private static final ResponseFieldsSnippet FEEDS_RESPONSE_FIELDS = responseFields(
fieldWithPath("[].id").type(JsonFieldType.NUMBER).description("피드 id"),
fieldWithPath("[].eventId").type(JsonFieldType.NUMBER).description("피드가 작성된 부모 이벤트 id"),
fieldWithPath("[].title").type(JsonFieldType.STRING).description("피드 제목"),
fieldWithPath("[].content").type(JsonFieldType.STRING).description("피드 내용"),
fieldWithPath("[].images").type(JsonFieldType.ARRAY).description("피드 이미지 url 리스트"),
fieldWithPath("[].writer.id").type(JsonFieldType.NUMBER).description("writer의 식별자"),
fieldWithPath("[].writer.name").type(JsonFieldType.STRING).description("writer의 이름"),
fieldWithPath("[].writer.description").type(JsonFieldType.STRING)
.description("writer의 한줄 자기소개"),
fieldWithPath("[].writer.imageUrl").type(JsonFieldType.STRING)
.description("writer의 이미지 url"),
fieldWithPath("[].writer.githubUrl").type(JsonFieldType.STRING)
.description("writer의 github Url"),
fieldWithPath("[].commentCount").type(JsonFieldType.NUMBER).description("피드의 댓글 개수"),
fieldWithPath("[].createdAt").type(JsonFieldType.STRING).description("피드 생성 일시"),
fieldWithPath("[].updatedAt").type(JsonFieldType.STRING).description("피드 업데이트 일시")
);

@Test
@DisplayName("이벤트의 피드 목록을 성공적으로 반환하면 200 OK를 반환한다.")
void findAllFeedsTest() throws Exception {
//given
final ResponseFieldsSnippet responseFields = responseFields(
fieldWithPath("eventId").type(JsonFieldType.NUMBER).description("피드가 작성된 부모 이벤트 id"),
fieldWithPath("feeds").type(JsonFieldType.ARRAY).description("피드 리스트"),
fieldWithPath("feeds[].id").type(JsonFieldType.NUMBER).description("피드 id"),
fieldWithPath("feeds[].title").type(JsonFieldType.STRING).description("피드 제목"),
fieldWithPath("feeds[].content").type(JsonFieldType.STRING).description("피드 내용"),
fieldWithPath("feeds[].images").type(JsonFieldType.ARRAY).description("피드 이미지 url 리스트"),
fieldWithPath("feeds[].writerId").type(JsonFieldType.NUMBER).description("피드 작성자 id"),
fieldWithPath("feeds[].commentCount").type(JsonFieldType.NUMBER).description("피드의 댓글 개수"),
fieldWithPath("feeds[].createdAt").type(JsonFieldType.STRING).description("피드 생성 일시"),
fieldWithPath("feeds[].updatedAt").type(JsonFieldType.STRING).description("피드 업데이트 일시")
);

final long eventId = 11L;
final List<FeedSimpleResponse> feeds = List.of(
new FeedSimpleResponse(34L, "피드1 제목", "피드 내용", 23L,
List.of("https://image1.url", "https://image2.url"), 0L,
LocalDateTime.of(LocalDate.of(2023, 7, 13), LocalTime.of(11, 43, 11)),
LocalDateTime.of(LocalDate.of(2023, 7, 13), LocalTime.of(11, 43, 11))),
new FeedSimpleResponse(35L, "피드2 제목", "피드 내용", 43L, Collections.emptyList(), 3L,
LocalDateTime.of(LocalDate.of(2023, 7, 22), LocalTime.of(23, 54, 49)),
LocalDateTime.of(LocalDate.of(2023, 7, 22), LocalTime.of(23, 54, 49)))
final List<FeedResponseRefactor> response = List.of(
new FeedResponseRefactor(
34L, eventId, "피드 1 제목", "피드 1 내용",
MEMBER_REFERENCE_RESPONSE,
Collections.emptyList(),
2L,
LocalDateTime.of(2023, 7, 13, 0, 0), LocalDateTime.of(2023, 7, 13, 0, 0)
),
new FeedResponseRefactor(
35L, eventId, "피드 2 제목", "피드 2 내용",
MEMBER_REFERENCE_RESPONSE,
Collections.emptyList(),
2L,
LocalDateTime.of(2023, 7, 13, 0, 0), LocalDateTime.of(2023, 7, 13, 0, 0)
)
);
final FeedListResponse response = new FeedListResponse(eventId, feeds);

when(feedQueryService.findAllFeeds(any(), any())).thenReturn(response);

Expand All @@ -72,7 +87,7 @@ void findAllFeedsTest() throws Exception {
.param("event-id", String.valueOf(eventId)))
.andExpect(status().isOk())
.andDo(print())
.andDo(document("find-all-feed", responseFields));
.andDo(document("find-all-feed", FEEDS_RESPONSE_FIELDS));
}

@Test
Expand All @@ -81,26 +96,33 @@ void findDetailFeedTest() throws Exception {
//given
final ResponseFieldsSnippet responseFields = responseFields(
fieldWithPath("id").type(JsonFieldType.NUMBER).description("피드 id"),
fieldWithPath("eventId").type(JsonFieldType.NUMBER).description("이벤트 id"),
fieldWithPath("writer").type(JsonFieldType.OBJECT).description("작성자"),
fieldWithPath("writer.memberId").type(JsonFieldType.NUMBER).description("작성자 id"),
fieldWithPath("writer.name").type(JsonFieldType.STRING).description("작성자명"),
fieldWithPath("writer.imageUrl").type(JsonFieldType.STRING).description("작성자 이미지 url"),
fieldWithPath("eventId").type(JsonFieldType.NUMBER).description("피드가 작성된 부모 이벤트 id"),
fieldWithPath("title").type(JsonFieldType.STRING).description("피드 제목"),
fieldWithPath("content").type(JsonFieldType.STRING).description("피드 내용"),
fieldWithPath("images").type(JsonFieldType.ARRAY).description("피드 이미지 url 리스트"),
fieldWithPath("writer.id").type(JsonFieldType.NUMBER).description("writer의 식별자"),
fieldWithPath("writer.name").type(JsonFieldType.STRING).description("writer의 이름"),
fieldWithPath("writer.description").type(JsonFieldType.STRING)
.description("writer의 한줄 자기소개"),
fieldWithPath("writer.imageUrl").type(JsonFieldType.STRING)
.description("writer의 이미지 url"),
fieldWithPath("writer.githubUrl").type(JsonFieldType.STRING)
.description("writer의 github Url"),
fieldWithPath("commentCount").type(JsonFieldType.NUMBER).description("피드의 댓글 개수"),
fieldWithPath("createdAt").type(JsonFieldType.STRING).description("피드 생성 일시"),
fieldWithPath("updatedAt").type(JsonFieldType.STRING).description("피드 업데이트 일시")
);

final long eventId = 11L;
final long feedId = 34L;
final WriterProfileResponse writer = new WriterProfileResponse(8L, "작성자명",
"https://member-image.com");
final FeedDetailResponse response = new FeedDetailResponse(feedId, eventId, writer, "피드 제목",
"피드 상세 내용", List.of("https://image1.url", "https://image2.url"),
LocalDateTime.of(LocalDate.of(2023, 7, 22), LocalTime.of(23, 54, 49)),
LocalDateTime.of(LocalDate.of(2023, 7, 22), LocalTime.of(23, 54, 49)));

final FeedResponseRefactor response =
new FeedResponseRefactor(
34L, eventId, "피드 1 제목", "피드 1 내용",
MEMBER_REFERENCE_RESPONSE,
Collections.emptyList(),
2L,
LocalDateTime.of(2023, 7, 13, 0, 0), LocalDateTime.of(2023, 7, 13, 0, 0)
);

when(feedQueryService.findFeed(any(), any())).thenReturn(response);

Expand All @@ -115,35 +137,31 @@ void findDetailFeedTest() throws Exception {
@DisplayName("자신의 피드 목록을 성공적으로 반환하면 200 OK를 반환한다.")
void findAllMyFeedsTest() throws Exception {
//given
final ResponseFieldsSnippet responseFields = responseFields(
fieldWithPath("[].id").type(JsonFieldType.NUMBER).description("피드 id"),
fieldWithPath("[].title").type(JsonFieldType.STRING).description("피드 제목"),
fieldWithPath("[].content").type(JsonFieldType.STRING).description("피드 내용"),
fieldWithPath("[].images").type(JsonFieldType.ARRAY).description("피드 이미지 url 리스트"),
fieldWithPath("[].writerId").type(JsonFieldType.NUMBER).description("피드 작성자 id"),
fieldWithPath("[].commentCount").type(JsonFieldType.NUMBER).description("피드의 댓글 개수"),
fieldWithPath("[].createdAt").type(JsonFieldType.STRING).description("피드 생성 일시"),
fieldWithPath("[].updatedAt").type(JsonFieldType.STRING).description("피드 업데이트 일시")
);

final List<FeedSimpleResponse> feeds = List.of(
new FeedSimpleResponse(34L, "피드1 제목", "피드 내용", 23L,
List.of("https://image1.url", "https://image2.url"), 0L,
LocalDateTime.of(LocalDate.of(2023, 7, 13), LocalTime.of(11, 43, 11)),
LocalDateTime.of(LocalDate.of(2023, 7, 13), LocalTime.of(11, 43, 11))),
new FeedSimpleResponse(35L, "피드2 제목", "피드 내용", 43L, Collections.emptyList(), 3L,
LocalDateTime.of(LocalDate.of(2023, 7, 22), LocalTime.of(23, 54, 49)),
LocalDateTime.of(LocalDate.of(2023, 7, 22), LocalTime.of(23, 54, 49)))
final List<FeedResponseRefactor> responses = List.of(
new FeedResponseRefactor(
34L, 2L, "피드 1 제목", "피드 1 내용",
MEMBER_REFERENCE_RESPONSE,
Collections.emptyList(),
2L,
LocalDateTime.of(2023, 7, 13, 0, 0), LocalDateTime.of(2023, 7, 13, 0, 0)
),
new FeedResponseRefactor(
35L, 2L, "피드 2 제목", "피드 2 내용",
MEMBER_REFERENCE_RESPONSE,
Collections.emptyList(),
2L,
LocalDateTime.of(2023, 7, 13, 0, 0), LocalDateTime.of(2023, 7, 13, 0, 0)
)
);

when(feedQueryService.findAllMyFeeds(any())).thenReturn(feeds);
when(feedQueryService.findAllMyFeeds(any())).thenReturn(responses);

//when & then
mockMvc.perform(get("/feeds/my")
.header(HttpHeaders.AUTHORIZATION, "Bearer accessToken"))
.andExpect(status().isOk())
.andDo(print())
.andDo(document("find-all-my-feed", responseFields));
.andDo(document("find-all-my-feed", FEEDS_RESPONSE_FIELDS));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import com.emmsale.activity.application.dto.ActivityResponse;
import com.emmsale.member.api.MemberApi;
import com.emmsale.member.application.dto.DescriptionRequest;
import com.emmsale.member.application.dto.MemberActivityAddRequest;
Expand Down Expand Up @@ -95,10 +96,10 @@ void addActivity() throws Exception {
final List<Long> activityIds = List.of(4L, 5L, 6L);
final MemberActivityAddRequest request = new MemberActivityAddRequest(activityIds);

final List<MemberActivityResponse> memberActivityResponses = createMemberActivityResponses();
final List<ActivityResponse> activityResponses = createActivityResponses();

when(memberActivityCommandService.addActivity(any(), any()))
.thenReturn(memberActivityResponses);
.thenReturn(activityResponses);

//when & then
mockMvc.perform(post("/members/activities")
Expand All @@ -111,14 +112,14 @@ void addActivity() throws Exception {
MEMBER_ACTIVITY_RESPONSE_FIELDS));
}

private List<MemberActivityResponse> createMemberActivityResponses() {
private List<ActivityResponse> createActivityResponses() {
return List.of(
new MemberActivityResponse(1L, "YAPP", "동아리"),
new MemberActivityResponse(2L, "DND", "동아리"),
new MemberActivityResponse(3L, "nexters", "동아리"),
new MemberActivityResponse(4L, "인프콘", "컨퍼런스"),
new MemberActivityResponse(5L, "우아한테크코스", "교육"),
new MemberActivityResponse(6L, "Backend", "직무")
new ActivityResponse(1L, "YAPP", "동아리"),
new ActivityResponse(2L, "DND", "동아리"),
new ActivityResponse(3L, "nexters", "동아리"),
new ActivityResponse(4L, "인프콘", "컨퍼런스"),
new ActivityResponse(5L, "우아한테크코스", "교육"),
new ActivityResponse(6L, "Backend", "직무")
);
}

Expand All @@ -128,12 +129,12 @@ void test_deleteActivity() throws Exception {
//given
final String activityIds = "1,2";

final List<MemberActivityResponse> memberActivityResponses = List.of(
new MemberActivityResponse(3L, "nexters", "동아리")
final List<ActivityResponse> activityResponses = List.of(
new ActivityResponse(3L, "nexters", "동아리")
);

when(memberActivityCommandService.deleteActivity(any(), any()))
.thenReturn(memberActivityResponses);
.thenReturn(activityResponses);

//when & then
mockMvc.perform(
Expand All @@ -149,11 +150,10 @@ void test_deleteActivity() throws Exception {
@DisplayName("내 활동들을 조회할 수 있다.")
void test_findActivity() throws Exception {
//given
final List<MemberActivityResponse> memberActivityResponse = createMemberActivityResponses();
final List<ActivityResponse> memberActivityResponse = createActivityResponses();

//when
when(memberActivityQueryService.findActivities(any()))
.thenReturn(memberActivityResponse);
when(memberActivityQueryService.findActivities(any())).thenReturn(memberActivityResponse);

//then
mockMvc.perform(get("/members/1/activities")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package com.emmsale.activity.application.dto;

import com.emmsale.activity.domain.Activity;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.ToString;

@RequiredArgsConstructor
@ToString
@Getter
public class ActivityResponse {

private final Long id;
Expand All @@ -12,21 +16,9 @@ public class ActivityResponse {

public static ActivityResponse from(final Activity activity) {
return new ActivityResponse(
activity.getId(),
activity.getActivityType().getValue(),
activity.getName()
activity.getId(),
activity.getActivityType().getValue(),
activity.getName()
);
}

public Long getId() {
return id;
}

public String getActivityType() {
return activityType;
}

public String getName() {
return name;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import com.emmsale.feed.application.FeedCommandService;
import com.emmsale.feed.application.FeedQueryService;
import com.emmsale.feed.application.dto.FeedDetailResponse;
import com.emmsale.feed.application.dto.FeedListResponse;
import com.emmsale.feed.application.dto.FeedPostRequest;
import com.emmsale.feed.application.dto.FeedResponseRefactor;
import com.emmsale.feed.application.dto.FeedSimpleResponse;
import com.emmsale.feed.application.dto.FeedUpdateRequest;
import com.emmsale.feed.application.dto.FeedUpdateResponse;
Expand Down Expand Up @@ -34,20 +34,20 @@ public class FeedApi {
private final FeedCommandService feedCommandService;

@GetMapping
public FeedListResponse findAllFeeds(
public List<FeedResponseRefactor> findAllFeeds(
final Member member,
@RequestParam("event-id") final Long eventId
) {
return feedQueryService.findAllFeeds(member, eventId);
}

@GetMapping("/{id}")
public FeedDetailResponse findFeed(final Member member, @PathVariable final Long id) {
public FeedResponseRefactor findFeed(final Member member, @PathVariable final Long id) {
return feedQueryService.findFeed(member, id);
}

@GetMapping("/my")
public List<FeedSimpleResponse> findAllMyFeeds(final Member member) {
public List<FeedResponseRefactor> findAllMyFeeds(final Member member) {
return feedQueryService.findAllMyFeeds(member);
}

Expand Down
Loading

0 comments on commit 42a2a52

Please sign in to comment.