Skip to content

Commit

Permalink
Merge pull request #127 from oduck-team/feature/117
Browse files Browse the repository at this point in the history
짧은 리뷰 작성, 수정 후 목록에 반영 #117
  • Loading branch information
hanyMK authored Nov 28, 2023
2 parents fd2f2bd + e42ef06 commit 7742a33
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,34 +41,36 @@ 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();

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

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

ShortReview saveShortReview = shortReviewRepository.save(shortReview);
ShortReview shortReview = ShortReview
.builder()
.anime(anime)
.member(member)
.content(shortReviewReq.getContent())
.hasSpoiler(shortReviewReq.isHasSpoiler())
.build();

anime.increaseReviewCount();
shortReviewRepository.save(shortReview);

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

@Override
public SliceResponse<ShortReviewRes> getShortReviews(Long animeId, String cursor, ShortReviewReqDto.Sort sort, OrderDirection order, int size) {
@Transactional
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()
Expand Down Expand Up @@ -135,9 +137,17 @@ public SliceResponse<ShortReviewRes> getShortReviewsByMemberId(Long memberId, St
}

@Override
@Transactional
public void update(Long memberId, Long reviewId, ShortReviewReq req) {
ShortReview findShortReview = getShortReview(reviewId);
Long findMemberId = findShortReview.getMember().getId();

Anime findAnime = animeRepository.findByIdForUpdate(req.getAnimeId())
.orElseThrow(
() -> new NotFoundException("Anime")
);
findAnime.decreaseReviewCount();

//리뷰 작성자 인지 확인
Optional
.ofNullable(findMemberId)
Expand All @@ -150,6 +160,8 @@ public void update(Long memberId, Long reviewId, ShortReviewReq req) {
findShortReview.updateSpoiler(req.isHasSpoiler());
}
);
findAnime.increaseReviewCount();
shortReviewRepository.save(findShortReview);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,6 @@ class PostShortReview{
@DisplayName("리뷰 등록 성공")
void saveShortReview(){
//given
//리뷰 생성
ShortReview shortReview = ShortReview
.builder()
.content("애니리뷰내용")
.hasSpoiler(false)
.build();

//회원 생성
Member member = Member.builder()
.build();
Expand All @@ -89,9 +82,14 @@ void saveShortReview(){

Anime anime = animeRepository.saveAndFlush(createAnime);
Long animeId = anime.getId();

shortReview.relateMember(member);
shortReview.relateAnime(anime);
//리뷰 생성
ShortReview shortReview = ShortReview
.builder()
.member(member)
.anime(anime)
.content("애니리뷰내용")
.hasSpoiler(false)
.build();

//when
ShortReview saveShortReview = shortReviewRepository.save(shortReview);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,10 @@ void patchShortReview(){
Long reviewId = 1L;
Long memberId = 1L;
ShortReviewReq patchShortReviewReq = createPatchShortReview();
Anime anime = createAnime();

given(shortReviewRepository.findById(reviewId)).willReturn(Optional.ofNullable(shortReview));
given(animeRepository.findByIdForUpdate(reviewId)).willReturn(Optional.of(anime));

//when
shortReviewService.update(memberId, reviewId, patchShortReviewReq);
Expand Down

0 comments on commit 7742a33

Please sign in to comment.