Skip to content

Commit

Permalink
Mate-135 : [FEAT] 마이페이지 작성글 페이징 조회 기능 구현 (#119)
Browse files Browse the repository at this point in the history
* MATE-135 : [FEAT] 마이페이지 작성한 굿즈 거래글 페이징 조회 기능 구현

* MATE-135 : [TEST] 마이페이지 작성한 굿즈 거래글 페이징 조회 기능 테스트

* MATE-135 : [FEAT] 마이페이지 작성한 메이트 구인글 페이징 조회 기능 구현

* MATE-135 : [TEST] 마이페이지 작성한 메이트 구인글 페이징 조회 기능 테스트
  • Loading branch information
jooinjoo authored Jan 2, 2025
1 parent 28066a2 commit cbd19a1
Show file tree
Hide file tree
Showing 7 changed files with 386 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,12 @@ Page<GoodsPost> findGoodsPostsBySellerId(@Param("memberId") Long memberId, @Para
""")
Page<GoodsPost> findGoodsPostsByBuyerId(@Param("memberId") Long memberId, @Param("status") Status status,
Pageable pageable);

@Query("""
SELECT gp
FROM GoodsPost gp
WHERE gp.seller.id = :memberId
ORDER BY gp.createdAt DESC
""")
Page<GoodsPost> findMyGoodsPosts(@Param("memberId") Long memberId, Pageable pageable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.example.mate.domain.mate.entity.MatePost;
import com.example.mate.domain.mate.entity.Status;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
Expand All @@ -21,4 +22,12 @@ public interface MateRepository extends JpaRepository<MatePost, Long>, MateRepos
""")
List<MatePost> findMainPagePosts(@Param("teamId") Long teamId, @Param("now") LocalDateTime now,
@Param("statuses") List<Status> statuses, Pageable pageable);

@Query("""
SELECT mp
FROM MatePost mp
WHERE mp.author.id = :memberId
ORDER BY mp.createdAt DESC
""")
Page<MatePost> findMyMatePosts(@Param("memberId") Long memberId, Pageable pageable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import com.example.mate.common.response.PageResponse;
import com.example.mate.common.security.auth.AuthMember;
import com.example.mate.common.validator.ValidPageable;
import com.example.mate.domain.goodsPost.dto.response.GoodsPostSummaryResponse;
import com.example.mate.domain.mate.dto.response.MatePostSummaryResponse;
import com.example.mate.domain.member.dto.response.MyGoodsRecordResponse;
import com.example.mate.domain.member.dto.response.MyReviewResponse;
import com.example.mate.domain.member.dto.response.MyVisitResponse;
Expand Down Expand Up @@ -83,4 +85,24 @@ public ResponseEntity<ApiResponse<PageResponse<MyGoodsRecordResponse>>> getBough
PageResponse<MyGoodsRecordResponse> response = profileService.getBoughtGoodsPage(memberId, pageable);
return ResponseEntity.ok(ApiResponse.success(response));
}

@Operation(summary = "작성한 굿즈 거래글 모아보기 페이징 조회")
@GetMapping("/posts/goods")
public ResponseEntity<ApiResponse<PageResponse<GoodsPostSummaryResponse>>> getGoodsPosts(
@Parameter(description = "회원 로그인 정보") @AuthenticationPrincipal AuthMember authMember,
@Parameter(description = "페이지 요청 정보") @ValidPageable Pageable pageable
) {
PageResponse<GoodsPostSummaryResponse> response = profileService.getGoodsPostsPage(authMember.getMemberId(), pageable);
return ResponseEntity.ok(ApiResponse.success(response));
}

@Operation(summary = "작성한 메이트 구인글 모아보기 페이징 조회")
@GetMapping("/posts/mate")
public ResponseEntity<ApiResponse<PageResponse<MatePostSummaryResponse>>> getMatePosts(
@Parameter(description = "회원 로그인 정보") @AuthenticationPrincipal AuthMember authMember,
@Parameter(description = "페이지 요청 정보") @ValidPageable Pageable pageable
) {
PageResponse<MatePostSummaryResponse> response = profileService.getMatePostsPage(authMember.getMemberId(), pageable);
return ResponseEntity.ok(ApiResponse.success(response));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
import com.example.mate.domain.goodsPost.entity.Status;
import com.example.mate.domain.goodsPost.repository.GoodsPostRepository;
import com.example.mate.domain.goodsReview.repository.GoodsReviewRepositoryCustom;
import com.example.mate.domain.goodsPost.dto.response.GoodsPostSummaryResponse;
import com.example.mate.domain.match.entity.Match;
import com.example.mate.domain.mate.dto.response.MatePostSummaryResponse;
import com.example.mate.domain.mate.entity.MatePost;
import com.example.mate.domain.mate.entity.MateReview;
import com.example.mate.domain.mate.repository.MateReviewRepository;
import com.example.mate.domain.mate.repository.MateReviewRepositoryCustom;
import com.example.mate.domain.mate.repository.VisitPartRepository;
import com.example.mate.domain.mate.repository.VisitRepository;
import com.example.mate.domain.mate.repository.*;
import com.example.mate.domain.member.dto.response.MyGoodsRecordResponse;
import com.example.mate.domain.member.dto.response.MyReviewResponse;
import com.example.mate.domain.member.dto.response.MyTimelineResponse;
Expand All @@ -38,6 +38,7 @@ public class ProfileService {

private final MemberRepository memberRepository;
private final GoodsPostRepository goodsPostRepository;
private final MateRepository mateRepository;
private final MateReviewRepositoryCustom mateReviewRepositoryCustom;
private final GoodsReviewRepositoryCustom goodsReviewRepositoryCustom;
private final VisitPartRepository visitPartRepository;
Expand Down Expand Up @@ -174,4 +175,31 @@ private PageResponse<MyVisitResponse> createPageResponse(Page<MyTimelineResponse
.pageSize(pageSize)
.build();
}

// 작성한 굿즈 거래글 페이징 조회
@Transactional(readOnly = true)
public PageResponse<GoodsPostSummaryResponse> getGoodsPostsPage(Long memberId, Pageable pageable) {
Page<GoodsPost> goodsPostsPage = goodsPostRepository.findMyGoodsPosts(memberId, pageable);
List<GoodsPostSummaryResponse> content = goodsPostsPage.getContent().stream()
.map(this::convertToGoodsPostResponse)
.toList();

return PageResponse.from(goodsPostsPage, content);
}

private GoodsPostSummaryResponse convertToGoodsPostResponse(GoodsPost goodsPost) {
String mainImageUrl = goodsPost.getMainImageUrl();
return GoodsPostSummaryResponse.of(goodsPost, mainImageUrl);
}

// 작성한 메이트 구인글 페이징 조회
@Transactional(readOnly = true)
public PageResponse<MatePostSummaryResponse> getMatePostsPage(Long memberId, Pageable pageable) {
Page<MatePost> matePostsPage = mateRepository.findMyMatePosts(memberId, pageable);
List<MatePostSummaryResponse> content = matePostsPage.getContent().stream()
.map(MatePostSummaryResponse::from)
.toList();

return PageResponse.from(matePostsPage, content);
}
}
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
package com.example.mate.domain.member.controller;

import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.willThrow;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import com.example.mate.common.error.CustomException;
import com.example.mate.common.error.ErrorCode;
import com.example.mate.common.response.PageResponse;
import com.example.mate.common.security.filter.JwtCheckFilter;
import com.example.mate.config.WithAuthMember;
import com.example.mate.domain.constant.Gender;
import com.example.mate.domain.goodsPost.dto.response.GoodsPostSummaryResponse;
import com.example.mate.domain.mate.dto.response.MatePostSummaryResponse;
import com.example.mate.domain.mate.entity.Age;
import com.example.mate.domain.mate.entity.Status;
import com.example.mate.domain.mate.entity.TransportType;
import com.example.mate.domain.member.dto.response.MyGoodsRecordResponse;
import com.example.mate.domain.member.dto.response.MyReviewResponse;
import com.example.mate.domain.member.dto.response.MyVisitResponse;
import com.example.mate.domain.member.dto.response.MyVisitResponse.MateReviewResponse;
import com.example.mate.domain.member.service.ProfileService;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.time.LocalDateTime;
import java.util.List;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
Expand All @@ -35,6 +30,18 @@
import org.springframework.data.jpa.mapping.JpaMetamodelMappingContext;
import org.springframework.test.web.servlet.MockMvc;

import java.time.LocalDateTime;
import java.util.List;

import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.willThrow;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

@WebMvcTest(ProfileController.class)
@MockBean(JpaMetamodelMappingContext.class)
@AutoConfigureMockMvc(addFilters = false)
Expand Down Expand Up @@ -404,4 +411,113 @@ void get_my_visit_page_fail_invalid_member_id() throws Exception {
verify(profileService, times(1)).getMyVisitPage(memberId, pageable);
}
}

@Nested
@DisplayName("작성한 굿즈 거래글 페이징 조회")
class ProfileGoodsPostsPage {

@Test
@DisplayName("작성한 굿즈 거래글 페이징 조회 성공")
void get_my_goods_posts_page_success() throws Exception {
// given
Long memberId = 1L;
Pageable pageable = PageRequest.of(0, 10);

GoodsPostSummaryResponse responseDTO = GoodsPostSummaryResponse.builder()
.id(1L)
.teamName("KIA")
.title("test title")
.category("유니폼")
.price(10000)
.imageUrl("test.png")
.build();
List<GoodsPostSummaryResponse> content = List.of(responseDTO);
PageImpl<GoodsPostSummaryResponse> goodsPostPage = new PageImpl<>(content);

PageResponse<GoodsPostSummaryResponse> response = PageResponse.<GoodsPostSummaryResponse>builder()
.content(content)
.totalPages(goodsPostPage.getTotalPages())
.totalElements(goodsPostPage.getTotalElements())
.hasNext(goodsPostPage.hasNext())
.pageNumber(goodsPostPage.getNumber())
.pageSize(goodsPostPage.getSize())
.build();

given(profileService.getGoodsPostsPage(memberId, pageable)).willReturn(response);

// when & then
mockMvc.perform(get("/api/profile/posts/goods")
.param("page", String.valueOf(pageable.getPageNumber()))
.param("size", String.valueOf(pageable.getPageSize())))
.andDo(print())
.andExpect(status().isOk())
.andExpect(jsonPath("$.status").value("SUCCESS"))
.andExpect(jsonPath("$.data.content.size()").value(content.size()))
.andExpect(jsonPath("$.data.content[0].title").value(responseDTO.getTitle()))
.andExpect(jsonPath("$.data.content[0].price").value(responseDTO.getPrice()))
.andExpect(jsonPath("$.data.totalPages").value(response.getTotalPages()))
.andExpect(jsonPath("$.data.totalElements").value(response.getTotalElements()))
.andExpect(jsonPath("$.data.pageNumber").value(response.getPageNumber()))
.andExpect(jsonPath("$.data.pageSize").value(response.getPageSize()))
.andExpect(jsonPath("$.code").value(200));
}
}

@Nested
@DisplayName("작성한 메이트 구인글 페이징 조회")
class ProfileMatePostsPage {

@Test
@DisplayName("작성한 메이트 구인글 페이징 조회 성공")
void get_my_mate_posts_page_success() throws Exception {
// given
Long memberId = 1L;
Pageable pageable = PageRequest.of(0, 10);

MatePostSummaryResponse responseDTO = MatePostSummaryResponse.builder()
.imageUrl("test.png")
.title("test title")
.status(Status.CLOSED)
.myTeamName("KIA")
.rivalTeamName("LG")
.matchTime(LocalDateTime.now().minusDays(7))
.location("광주-기아 챔피언스 필드")
.maxParticipants(10)
.age(Age.ALL)
.gender(Gender.ANY)
.transportType(TransportType.ANY)
.postId(1L)
.build();

List<MatePostSummaryResponse> content = List.of(responseDTO);
PageImpl<MatePostSummaryResponse> matePostPage = new PageImpl<>(content);

PageResponse<MatePostSummaryResponse> response = PageResponse.<MatePostSummaryResponse>builder()
.content(content)
.totalPages(matePostPage.getTotalPages())
.totalElements(matePostPage.getTotalElements())
.hasNext(matePostPage.hasNext())
.pageNumber(matePostPage.getNumber())
.pageSize(matePostPage.getSize())
.build();

given(profileService.getMatePostsPage(memberId, pageable)).willReturn(response);

// when & then
mockMvc.perform(get("/api/profile/posts/mate")
.param("page", String.valueOf(pageable.getPageNumber()))
.param("size", String.valueOf(pageable.getPageSize())))
.andDo(print())
.andExpect(status().isOk())
.andExpect(jsonPath("$.status").value("SUCCESS"))
.andExpect(jsonPath("$.data.content.size()").value(content.size()))
.andExpect(jsonPath("$.data.content[0].title").value(responseDTO.getTitle()))
.andExpect(jsonPath("$.data.content[0].location").value(responseDTO.getLocation()))
.andExpect(jsonPath("$.data.totalPages").value(response.getTotalPages()))
.andExpect(jsonPath("$.data.totalElements").value(response.getTotalElements()))
.andExpect(jsonPath("$.data.pageNumber").value(response.getPageNumber()))
.andExpect(jsonPath("$.data.pageSize").value(response.getPageSize()))
.andExpect(jsonPath("$.code").value(200));
}
}
}
Loading

0 comments on commit cbd19a1

Please sign in to comment.