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

Refactor/#908 함꼐해요 요청 반환값 변경 #909

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ class RecruitmentPostApiTest extends MockMvcTestHelper {
.description("member의 이미지 url"),
fieldWithPath("[].member.githubUrl").type(JsonFieldType.STRING)
.description("member의 github Url"),
fieldWithPath("[].eventId").type(JsonFieldType.NUMBER).description("행사의 식별자")
fieldWithPath("[].eventId").type(JsonFieldType.NUMBER).description("행사의 식별자"),
fieldWithPath("[].eventName").type(JsonFieldType.STRING).description("행사의 이름")
);

private static final ResponseFieldsSnippet RECRUITMENT_POST_RESPONSE_FIELDS = responseFields(
Expand All @@ -62,7 +63,8 @@ class RecruitmentPostApiTest extends MockMvcTestHelper {
.description("member의 이미지 url"),
fieldWithPath("member.githubUrl").type(JsonFieldType.STRING)
.description("member의 github Url"),
fieldWithPath("eventId").type(JsonFieldType.NUMBER).description("행사의 식별자")
fieldWithPath("eventId").type(JsonFieldType.NUMBER).description("행사의 식별자"),
fieldWithPath("eventName").type(JsonFieldType.STRING).description("행사의 이름")
);

@Test
Expand Down Expand Up @@ -125,9 +127,9 @@ void findRecruitmentPosts() throws Exception {
final LocalDate postedAt = LocalDate.of(2023, 7, 15);
final List<RecruitmentPostQueryResponse> response = List.of(
new RecruitmentPostQueryResponse(1L, "함께해요~", postedAt,
MemberReferenceResponse.from(member1), 21L),
MemberReferenceResponse.from(member1), 21L, "21번 행사"),
new RecruitmentPostQueryResponse(2L, "같이 가요~", postedAt,
MemberReferenceResponse.from(member2), 43L)
MemberReferenceResponse.from(member2), 43L, "43번 행사")
);

when(postQueryService.findRecruitmentPosts(eventId)).thenReturn(response);
Expand All @@ -150,7 +152,7 @@ void findRecruitmentPost() throws Exception {

final RecruitmentPostQueryResponse response = new RecruitmentPostQueryResponse(1L, "함께해요~",
postedAt,
MemberReferenceResponse.from(member), 21L);
MemberReferenceResponse.from(member), 21L, "21번 행사");
when(postQueryService.findRecruitmentPost(eventId, postId)).thenReturn(response);

//when && then
Expand Down Expand Up @@ -212,18 +214,17 @@ void findRecruitmentPostsByMemberIdTest() throws Exception {
final LocalDate postedAt = LocalDate.of(2023, 7, 15);
final List<RecruitmentPostQueryResponse> response = List.of(
new RecruitmentPostQueryResponse(1L, "함께해요~", postedAt,
MemberReferenceResponse.from(member), 21L),
MemberReferenceResponse.from(member), 21L,"21번 행사"),
new RecruitmentPostQueryResponse(2L, "같이 가요~", postedAt,
MemberReferenceResponse.from(member), 43L)
MemberReferenceResponse.from(member), 43L, "43번 행사")
);

//when
given(postQueryService.findRecruitmentPostsByMemberId(any(), any())).willReturn(response);

//then
mockMvc.perform(
get("/events/recruitment-posts?member-id={memberId}",
memberId)
get("/events/recruitment-posts?member-id={memberId}", memberId)
.header(HttpHeaders.AUTHORIZATION, "Bearer AccessToken"))
.andExpect(status().isOk())
.andDo(document("find-all-by-member-id-recruitment-post",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import java.util.List;
import javax.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
Expand All @@ -22,7 +21,6 @@
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;

@RestController
Expand Down Expand Up @@ -95,11 +93,12 @@ public ResponseEntity<Boolean> isAlreadyRecruit(
}

@GetMapping("/recruitment-posts")
@ResponseStatus(HttpStatus.OK)
public List<RecruitmentPostQueryResponse> findRecruitmentPostsByMemberId(
public ResponseEntity<List<RecruitmentPostQueryResponse>> findRecruitmentPostsByMemberId(
final Member member,
@RequestParam("member-id") final Long memberId
) {
return postQueryService.findRecruitmentPostsByMemberId(member, memberId);
final List<RecruitmentPostQueryResponse> responses
= postQueryService.findRecruitmentPostsByMemberId(member, memberId);
return ResponseEntity.ok(responses);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class RecruitmentPostQueryResponse {
private final LocalDate updatedAt;
private final MemberReferenceResponse member;
private final Long eventId;
private final String eventName;

public static RecruitmentPostQueryResponse from(final RecruitmentPost recruitmentPost) {
final Member member = recruitmentPost.getMember();
Expand All @@ -28,7 +29,8 @@ public static RecruitmentPostQueryResponse from(final RecruitmentPost recruitmen
recruitmentPost.getContent(),
recruitmentPost.getUpdatedAt().toLocalDate(),
MemberReferenceResponse.from(member),
recruitmentPost.getEvent().getId()
recruitmentPost.getEvent().getId(),
recruitmentPost.getEvent().getName()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.List;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

@Repository
Expand All @@ -14,5 +15,8 @@ public interface RecruitmentPostRepository extends JpaRepository<RecruitmentPost

Boolean existsByEventIdAndMemberId(final Long eventId, final Long memberId);

@Query("select r from RecruitmentPost r "
+ "join fetch r.event "
+ "where r.member = :member")
List<RecruitmentPost> findAllByMember(Member member);
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ void findRecruitmentPosts() {

final List<RecruitmentPostQueryResponse> expected = List.of(
new RecruitmentPostQueryResponse(멤버1_참가글_ID, requestMember1.getContent(), LocalDate.now(),
MemberReferenceResponse.from(사용자1), 인프콘.getId()),
MemberReferenceResponse.from(사용자1), 인프콘.getId(), 인프콘.getName()),
new RecruitmentPostQueryResponse(멤버2_참가글_ID, requestMember2.getContent(), LocalDate.now(),
MemberReferenceResponse.from(사용자2), 인프콘.getId())
MemberReferenceResponse.from(사용자2), 인프콘.getId(), 인프콘.getName())
);

//when
Expand All @@ -93,7 +93,7 @@ void findRecruitmentPost() {

final RecruitmentPostQueryResponse expected = new RecruitmentPostQueryResponse(멤버1_참가글_ID,
requestMember1.getContent(), LocalDate.now(), MemberReferenceResponse.from(사용자1),
인프콘.getId());
인프콘.getId(), 인프콘.getName());

//when
final RecruitmentPostQueryResponse actual = postQueryService.findRecruitmentPost(
Expand Down
Loading