Skip to content

Commit

Permalink
Merge branch 'develop' into feature/103
Browse files Browse the repository at this point in the history
  • Loading branch information
FaberJoo committed Nov 13, 2023
2 parents c516e56 + b51cc16 commit 5ed36ef
Show file tree
Hide file tree
Showing 15 changed files with 281 additions and 59 deletions.
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 @@ -56,4 +56,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 @@ -2,6 +2,7 @@

import io.oduck.api.domain.review.dto.ShortReviewReqDto.ShortReviewReq;
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 @@ -13,6 +14,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, ShortReviewReq req);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
import io.oduck.api.domain.member.repository.MemberRepository;
import io.oduck.api.domain.review.dto.ShortReviewDslDto.ShortReviewDsl;
import io.oduck.api.domain.review.dto.ShortReviewReqDto;
import io.oduck.api.domain.review.dto.ShortReviewReqDto.ShortReviewReq;

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 All @@ -31,7 +32,7 @@
@Slf4j
@Service
@RequiredArgsConstructor
public class ShortReviewServiceImpl implements ShortReviewService{
public class ShortReviewServiceImpl implements ShortReviewService {

private final ShortReviewRepository shortReviewRepository;
private final MemberRepository memberRepository;
Expand All @@ -41,85 +42,68 @@ public class ShortReviewServiceImpl implements ShortReviewService{
@Override
@Transactional
public void save(Long memberId, ShortReviewReq shortReviewReq) {
ShortReview shortReview = ShortReview
.builder()
.content(shortReviewReq.getContent())
.hasSpoiler(shortReviewReq.isHasSpoiler())
.build();
ShortReview shortReview = ShortReview.builder().content(shortReviewReq.getContent())
.hasSpoiler(shortReviewReq.isHasSpoiler()).build();

//애니 입력
// 애니 입력
Anime anime = animeRepository.findByIdForUpdate(shortReviewReq.getAnimeId())
.orElseThrow(
() -> new NotFoundException("Anime")
);
.orElseThrow(() -> new NotFoundException("Anime"));
shortReview.relateAnime(anime);

//회원 입력
// 회원 입력
Member member = memberRepository.findById(memberId)
.orElseThrow(
() -> new NotFoundException("Member")
);
.orElseThrow(() -> new NotFoundException("Member"));
shortReview.relateMember(member);

ShortReview saveShortReview = shortReviewRepository.save(shortReview);
anime.increaseReviewCount();

//log.info("ShortReview Crated! {}", saveShortReview.getId());
// log.info("ShortReview Crated! {}", saveShortReview.getId());
}

@Override
public SliceResponse<ShortReviewRes> getShortReviews(Long animeId, String cursor,ShortReviewReqDto.Sort sort, OrderDirection order, int size) {
Sort sortList = Sort.by(
Direction.fromString(order.getOrder()),
sort.getSort()
);
public SliceResponse<ShortReviewRes> getShortReviews(Long animeId, String cursor,
ShortReviewReqDto.Sort sort, OrderDirection order, int size) {
Sort sortList = Sort.by(Direction.fromString(order.getOrder()), sort.getSort());

if(sort == ShortReviewReqDto.Sort.LIKE_COUNT){
if (sort == ShortReviewReqDto.Sort.LIKE_COUNT) {
sortList = sortList.and(Sort.by(Direction.DESC, "createdAt"));
}else if(sort == ShortReviewReqDto.Sort.SCORE){
} else if (sort == ShortReviewReqDto.Sort.SCORE) {
sortList = sortList.and(Sort.by(Direction.DESC, "createdAt"));
}

Slice<ShortReviewDsl> shortReviews = shortReviewRepository.selectShortReviews(
animeId,
cursor,
applyPageableForNonOffset(
size,
sortList
)
);
Slice<ShortReviewDsl> shortReviews = shortReviewRepository.selectShortReviews(animeId,
cursor, applyPageableForNonOffset(size, sortList));

List<ShortReviewRes> res = shortReviews.getContent()
.stream()
.map(ShortReviewRes::of)
.toList();
List<ShortReviewRes> res =
shortReviews.getContent().stream().map(ShortReviewRes::of).toList();

return SliceResponse.of(shortReviews, res, sort.getSort());
}

@Override
public void update(Long memberId, Long reviewId, ShortReviewReq req) {
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);
Long findMemberId = findShortReview.getMember().getId();
//리뷰 작성자 인지 확인
Optional
.ofNullable(findMemberId)
.ifPresent(
id -> {
if(!findMemberId.equals(memberId)) {
throw new BadRequestException("Not the author of the review.");
}
findShortReview.updateContent(req.getContent());
findShortReview.updateSpoiler(req.isHasSpoiler());
}
);
// 리뷰 작성자 인지 확인
Optional.ofNullable(findMemberId).ifPresent(id -> {
if (!findMemberId.equals(memberId)) {
throw new BadRequestException("Not the author of the review.");
}
findShortReview.updateContent(req.getContent());
findShortReview.updateSpoiler(req.isHasSpoiler());
});
}


private ShortReview getShortReview(Long reviewId){
private ShortReview getShortReview(Long reviewId) {
return shortReviewRepository.findById(reviewId)
.orElseThrow(
() -> new NotFoundException("shortReview")
);
.orElseThrow(() -> new NotFoundException("shortReview"));
}
}
}
Loading

0 comments on commit 5ed36ef

Please sign in to comment.