Skip to content

Commit

Permalink
Merge pull request #84 from Clubber2024/refactor/#83-refactor-존재하지-않는…
Browse files Browse the repository at this point in the history
…-동아리-예외-적용

refactor : 존재 하지 않는 동아리 예외 적용
  • Loading branch information
mjKim1229 authored May 19, 2024
2 parents 0719832 + fb1cad5 commit 1fea63f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


import com.clubber.ClubberServer.domain.club.domain.Club;
import com.clubber.ClubberServer.domain.club.exception.ClubNotFoundException;
import com.clubber.ClubberServer.domain.club.repository.ClubRepository;
import com.clubber.ClubberServer.domain.favorite.domain.Favorite;
import com.clubber.ClubberServer.domain.favorite.dto.FavoriteResponse;
Expand Down Expand Up @@ -31,7 +32,8 @@ public FavoriteResponse createFavorite(Long clubId){
Long currentUserId = SecurityUtils.getCurrentUserId();
User user = userRepository.findById(currentUserId)
.orElseThrow(() -> UserNotFoundException.EXCEPTION);
Club club = clubRepository.findById(clubId).get();
Club club = clubRepository.findById(clubId)
.orElseThrow(() -> ClubNotFoundException.EXCEPTION);

favoriteRepository.findByUserAndClub(user,club)
.ifPresent(favorite -> { throw ClubAlreadyRegisterdFavoriteException.EXCEPTION; });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.clubber.ClubberServer.domain.review.service;

import com.clubber.ClubberServer.domain.club.domain.Club;
import com.clubber.ClubberServer.domain.club.exception.ClubNotFoundException;
import com.clubber.ClubberServer.domain.club.repository.ClubRepository;
import com.clubber.ClubberServer.domain.review.domain.Keyword;
import com.clubber.ClubberServer.domain.review.domain.Review;
Expand Down Expand Up @@ -41,7 +42,8 @@ public ReviewCreateResponse createReview(Long clubId, ReviewRequest reviewReques
User user = userRepository.findById(currentUserId)
.orElseThrow(() -> UserNotFoundException.EXCEPTION);

Club club = clubRepository.findById(clubId).get();
Club club = clubRepository.findById(clubId)
.orElseThrow(() -> ClubNotFoundException.EXCEPTION);
Review review = Review.of(user, club);

return createReviewKeyword(reviewRequest, reviewRepository.save(review));
Expand All @@ -59,14 +61,16 @@ private ReviewCreateResponse createReviewKeyword(ReviewRequest reviewRequest, Re

@Transactional(readOnly = true)
public ClubReviewResponse getClubReviews(Long clubId){
Club club = clubRepository.findById(clubId).get();
Club club = clubRepository.findById(clubId)
.orElseThrow(() -> ClubNotFoundException.EXCEPTION);
List<ReviewKeyword> reviewKeywords = reviewKeywordRepository.queryReviewKeywordByClubId(club.getId());
return ClubReviewResponse.of(club, reviewKeywords);
}

@Transactional(readOnly = true)
public ClubReviewKeywordStatsResponse getClubReviewKeywordStats(Long clubId){
Club club = clubRepository.findById(clubId).get();
Club club = clubRepository.findById(clubId)
.orElseThrow(() -> ClubNotFoundException.EXCEPTION);
List<KeywordStats> keywordStats = reviewKeywordRepository.queryReviewKeywordStatsByClubId(
club.getId());

Expand Down

0 comments on commit 1fea63f

Please sign in to comment.