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

회원 입덕 애니 및 작성 리뷰 갯수 #98 #100

Merged
merged 14 commits into from
Nov 13, 2023
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
40 changes: 40 additions & 0 deletions src/docs/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,46 @@ include::{snippets}/getBookmarks/successWithCursor/response-body.adoc[]
.response-fields
include::{snippets}/getBookmarks/successWithCursor/response-fields.adoc[]sho

=== GET api/v1/members/:id/bookmarks/count

.curl-request
include::{snippets}/getBookmarkCount/success/curl-request.adoc[]

.http-request
include::{snippets}/getBookmarkCount/success/http-request.adoc[]

.request-param
include::{snippets}/getBookmarkCount/success/path-parameters.adoc[]

.http-response
include::{snippets}/getBookmarkCount/success/http-response.adoc[]

.response-body
include::{snippets}/getBookmarkCount/success/response-body.adoc[]

.response-fields
include::{snippets}/getBookmarkCount/success/response-fields.adoc[]

=== GET api/v1/members/:id/short-reviews/count

.curl-request
include::{snippets}/getReviewCount/success/curl-request.adoc[]

.http-request
include::{snippets}/getReviewCount/success/http-request.adoc[]

.request-param
include::{snippets}/getReviewCount/success/path-parameters.adoc[]

.http-response
include::{snippets}/getReviewCount/success/http-response.adoc[]

.response-body
include::{snippets}/getReviewCount/success/response-body.adoc[]

.response-fields
include::{snippets}/getReviewCount/success/response-fields.adoc[]

== animes
=== GET api/v1/animes
.curl-request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@
import lombok.NoArgsConstructor;

public class BookmarkResDto {
@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public static class BookmarkCountRes {
private Long count;
}
@Getter
@Builder
@NoArgsConstructor(access = AccessLevel.PROTECTED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

@Repository
public interface BookmarkRepository extends JpaRepository<Bookmark,Long>, BookmarkRepositoryCustom {
Long countByMemberId(Long memberId);
Optional<Bookmark> findByMemberIdAndAnimeId(Long memberId, Long animeId);

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.oduck.api.domain.bookmark.service;

import io.oduck.api.domain.bookmark.dto.BookmarkResDto.BookmarkCountRes;
import io.oduck.api.domain.bookmark.dto.BookmarkResDto.BookmarkRes;
import io.oduck.api.domain.bookmark.dto.BookmarkReqDto.Sort;
import io.oduck.api.domain.bookmark.dto.BookmarkResDto.BookmarkedDateTimeRes;
Expand All @@ -9,6 +10,7 @@
public interface BookmarkService {
boolean toggleBookmark(Long memberId, Long animeId);
BookmarkedDateTimeRes checkBookmarked(Long memberId, Long animeId);
BookmarkCountRes getBookmarksCountByMemberId(Long memberId);
SliceResponse<BookmarkRes> getBookmarksByMemberId(Long memberId, String cursor, Sort sort, OrderDirection order, int size);

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import io.oduck.api.domain.anime.repository.AnimeRepository;
import io.oduck.api.domain.bookmark.dto.BookmarkDslDto.BookmarkDsl;
import io.oduck.api.domain.bookmark.dto.BookmarkReqDto;
import io.oduck.api.domain.bookmark.dto.BookmarkResDto.BookmarkCountRes;
import io.oduck.api.domain.bookmark.dto.BookmarkResDto.BookmarkRes;
import io.oduck.api.domain.bookmark.dto.BookmarkResDto.BookmarkedDateTimeRes;
import io.oduck.api.domain.bookmark.entity.Bookmark;
Expand Down Expand Up @@ -74,6 +75,14 @@ public BookmarkedDateTimeRes checkBookmarked(Long memberId, Long animeId) {
throw new NotFoundException("bookmark");
}

@Override
public BookmarkCountRes getBookmarksCountByMemberId(Long memberId) {
Long count = bookmarkRepository.countByMemberId(memberId);
return BookmarkCountRes.builder()
.count(count)
.build();
}

@Override
public SliceResponse<BookmarkRes> getBookmarksByMemberId(Long memberId, String cursor, BookmarkReqDto.Sort sort, OrderDirection order, int size) {
Sort sortList = Sort.by(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
import io.oduck.api.domain.bookmark.dto.BookmarkReqDto.Sort;
import io.oduck.api.domain.member.dto.MemberResDto.MemberProfileRes;
import io.oduck.api.domain.member.service.MemberService;
import io.oduck.api.domain.review.service.ShortReviewService;
import io.oduck.api.global.common.OrderDirection;
import io.oduck.api.global.common.SliceResponse;
import io.oduck.api.global.security.auth.dto.AuthUser;
import io.oduck.api.global.security.auth.dto.LoginUser;
import jakarta.validation.Valid;
import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.Positive;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
Expand All @@ -33,6 +35,7 @@
public class MemberController {
private final MemberService memberService;
private final BookmarkService bookmarkService;
private final ShortReviewService shortReviewService;

// 로컬 회원 가입
@PostMapping
Expand Down Expand Up @@ -70,7 +73,7 @@ public ResponseEntity<?> patchProfile(

@GetMapping("/{id}/bookmarks")
public ResponseEntity<?> getBookmaks(
@PathVariable("id") Long id,
@PathVariable("id") @Positive Long id,
@RequestParam(required = false) String cursor,
@RequestParam(required = false, defaultValue = "created_at") Sort sort,
@RequestParam(required = false, defaultValue = "DESC") OrderDirection order,
Expand All @@ -80,11 +83,25 @@ public ResponseEntity<?> getBookmaks(
SliceResponse<BookmarkRes> res = bookmarkService.getBookmarksByMemberId(id, cursor, sort, order, size);
return ResponseEntity.ok(res);
}

@GetMapping("/{id}/bookmarks/count")
public ResponseEntity<?> getBookmarksCount(
@PathVariable("id") @Positive Long id
) {
return ResponseEntity.ok(bookmarkService.getBookmarksCountByMemberId(id));
}
//
// @GetMapping("/{name}/short-reviews")
// public ResponseEntity<?> getShortReviews(
// @LoginUser AuthUser user
// ) {
// return ResponseEntity.ok(SliceResponse.of());
// }

@GetMapping("/{id}/short-reviews/count")
public ResponseEntity<?> getShoertReviewsCount(
@PathVariable("id") @Positive Long id
) {
return ResponseEntity.ok(shortReviewService.getShortReviewCountByMemberId(id));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,12 @@ public String bringCursor(String property) {
};
}
}

@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public static class ShortReviewCountRes {
private Long count;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@

@Repository
public interface ShortReviewRepository extends JpaRepository<ShortReview,Long>, ShortReviewRepositoryCustom {


Long countByMemberId(Long memberId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import io.oduck.api.domain.review.dto.ShortReviewReqDto.PatchShortReviewReq;
import io.oduck.api.domain.review.dto.ShortReviewReqDto.PostShortReviewReq;
import io.oduck.api.domain.review.dto.ShortReviewReqDto.Sort;
import io.oduck.api.domain.review.dto.ShortReviewResDto.ShortReviewCountRes;
import io.oduck.api.domain.review.dto.ShortReviewResDto.ShortReviewRes;
import io.oduck.api.global.common.OrderDirection;
import io.oduck.api.global.common.SliceResponse;
Expand All @@ -14,6 +15,7 @@ public interface ShortReviewService {

//애니 짧은 리뷰 조회
SliceResponse<ShortReviewRes> getShortReviews(Long animeId, String cursor, Sort sort, OrderDirection order, int size);
ShortReviewCountRes getShortReviewCountByMemberId(Long memberId);

//애니 리뷰 수정
void update(Long memberId, Long reviewId, PatchShortReviewReq req);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import io.oduck.api.domain.review.dto.ShortReviewReqDto;
import io.oduck.api.domain.review.dto.ShortReviewReqDto.PatchShortReviewReq;
import io.oduck.api.domain.review.dto.ShortReviewReqDto.PostShortReviewReq;
import io.oduck.api.domain.review.dto.ShortReviewResDto.ShortReviewCountRes;
import io.oduck.api.domain.review.dto.ShortReviewResDto.ShortReviewRes;
import io.oduck.api.domain.review.entity.ShortReview;
import io.oduck.api.domain.review.repository.ShortReviewRepository;
Expand Down Expand Up @@ -99,6 +100,14 @@ public SliceResponse<ShortReviewRes> getShortReviews(Long animeId, String cursor
return SliceResponse.of(shortReviews, res, sort.getSort());
}

@Override
public ShortReviewCountRes getShortReviewCountByMemberId(Long memberId) {
Long count = shortReviewRepository.countByMemberId(memberId);
return ShortReviewCountRes.builder()
.count(count)
.build();
}

@Override
public void update(Long memberId, Long reviewId, PatchShortReviewReq req) {
ShortReview findShortReview = getShortReview(reviewId);
Expand Down
76 changes: 76 additions & 0 deletions src/test/java/io/oduck/api/e2e/member/MemberControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -633,5 +633,81 @@ void getBookmarksSuccessWithCursor() throws Exception {
}
}

@DisplayName("회원의 북마크 애니 갯수 조회")
@Nested
class GetBookmarkCount {
@DisplayName("회원의 북마크 애니 갯수 조회 성공시 200 OK 응답")
@Test
void getBookmarkCountSuccess() throws Exception {
// given
// 회원의 북마크 애니 갯수 조회에 필요한 데이터
Long memberId = 1L;

// when
ResultActions actions = mockMvc.perform(
get(BASE_URL + "/{memberId}/bookmarks/count", memberId)
.contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON)
);

// then
actions
.andExpect(status().isOk())
.andExpect(jsonPath("$.count").exists())
.andDo(
document("getBookmarkCount/success",
preprocessRequest(prettyPrint()),
preprocessResponse(prettyPrint()),
pathParameters(
parameterWithName("memberId")
.description("회원 id")),
responseFields(
fieldWithPath("count")
.type(JsonFieldType.NUMBER)
.description("회원의 북마크 애니 갯수")
)
)
);
}
}

// TODO: 회원 리뷰 목록 조회

@DisplayName("회원의 리뷰 갯수 조회")
@Nested
class GetReviewCount {
@DisplayName("회원의 리뷰 갯수 조회 성공시 200 OK 응답")
@Test
void getReviewCountSuccess() throws Exception {
// given
// 회원의 리뷰 갯수 조회에 필요한 데이터
Long memberId = 1L;

// when
ResultActions actions = mockMvc.perform(
get(BASE_URL + "/{memberId}/short-reviews/count", memberId)
.contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON)
);

// then
actions
.andExpect(status().isOk())
.andExpect(jsonPath("$.count").exists())
.andDo(
document("getReviewCount/success",
preprocessRequest(prettyPrint()),
preprocessResponse(prettyPrint()),
pathParameters(
parameterWithName("memberId")
.description("회원 id")),
responseFields(
fieldWithPath("count")
.type(JsonFieldType.NUMBER)
.description("회원의 리뷰 갯수")
)
)
);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.oduck.api.unit.bookmark.repository;

import static io.oduck.api.global.utils.PagingUtils.applyPageableForNonOffset;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

import io.oduck.api.domain.bookmark.dto.BookmarkDslDto.BookmarkDsl;
Expand All @@ -22,7 +23,7 @@
@ActiveProfiles("test")
public class BookmarkRepositoryTest {
@Autowired
BookmarkRepository memberRepository;
BookmarkRepository bookmarkRepository;

@DisplayName("회원 북마크 애니 목록 조회")
@Nested
Expand All @@ -36,7 +37,7 @@ void selectBookmarksSuccess() {
Pageable pageable = applyPageableForNonOffset(10, "createdAt", "desc");

// when
Slice<BookmarkDsl> bookmarks = memberRepository.selectBookmarks(memberId, null, pageable);
Slice<BookmarkDsl> bookmarks = bookmarkRepository.selectBookmarks(memberId, null, pageable);

assertNotNull(bookmarks);
assertNotNull(bookmarks.getContent().get(0).getAnimeId());
Expand All @@ -45,4 +46,21 @@ void selectBookmarksSuccess() {
}
}

@DisplayName("회원 북마크 애니 갯수 조회")
@Nested
class selectBookmarkCount {
@DisplayName("회원 ID로 회원이 북마크한 애니 갯수 조회 성공")
@Test
void selectBookmarkCountSuccess() {
// given
Long memberId = 1L;

// when
Long bookmarkCount = bookmarkRepository.countByMemberId(memberId);

// then
assertNotNull(bookmarkCount);
assertEquals(3L, bookmarkCount);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import io.oduck.api.domain.anime.repository.AnimeRepository;
import io.oduck.api.domain.bookmark.dto.BookmarkDslDto.BookmarkDsl;
import io.oduck.api.domain.bookmark.dto.BookmarkReqDto.Sort;
import io.oduck.api.domain.bookmark.dto.BookmarkResDto.BookmarkCountRes;
import io.oduck.api.domain.bookmark.dto.BookmarkResDto.BookmarkRes;
import io.oduck.api.domain.bookmark.dto.BookmarkResDto.BookmarkedDateTimeRes;
import io.oduck.api.domain.bookmark.entity.Bookmark;
Expand Down Expand Up @@ -134,6 +135,24 @@ void getBookmarksByMemberIdSuccess() {
}
}

@DisplayName("회원의 북마크 갯수 조회")
@Nested
class GetBookmarkCountByMemberId {
@DisplayName("회원의 북마크 갯수 조회 성공")
@Test
void getBookmarkCountByMemberIdSuccess() {
Long memberId = 1L;
Long count = 3L;

when(bookmarkRepository.countByMemberId(memberId)).thenReturn(count);

BookmarkCountRes result = bookmarkService.getBookmarksCountByMemberId(memberId);

assertNotNull(result);
assertEquals(count, result.getCount());
}
}

@DisplayName("북마크 체크")
@Nested
class checkBookmarked {
Expand Down
Loading