Skip to content

Commit

Permalink
merge: 함꼐해요_요청_반환값_변경
Browse files Browse the repository at this point in the history
Refactor/#908 함꼐해요 요청 반환값 변경
  • Loading branch information
hong-sile authored Feb 6, 2024
2 parents e14f942 + 7b2a61b commit 4c7572a
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 18 deletions.
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

0 comments on commit 4c7572a

Please sign in to comment.