Skip to content

Commit

Permalink
fix: 친구요청 중복 처리 로직 수정, 선호도 컨텐츠 요청 path Variable 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
GitJIHO committed Nov 27, 2024
1 parent 3015b73 commit d573bcb
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.software.ott.friend.FriendStatus;
import com.software.ott.friend.entity.Friend;
import com.software.ott.member.entity.Member;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

Expand All @@ -10,6 +11,5 @@
@Repository
public interface FriendRepository extends JpaRepository<Friend, Long> {
List<Friend> findAllByAccepterIdAndStatusOrRequesterIdAndStatus(Long accepterId, FriendStatus status1, Long requesterId, FriendStatus status2);

boolean existsByRequesterIdOrAccepterId(Long requesterId, Long accepterId);
boolean existsByRequesterAndAccepter(Member requester, Member accepter);
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ public void sendContentRecommend(Long memberId, Long friendRequestId, RecommendC
Content content = contentRepository.findById(recommendContentRequest.contentId())
.orElseThrow(() -> new NotFoundException("contentId에 해당하는 컨텐츠가 없습니다."));

if (!friendRepository.existsByRequesterIdOrAccepterId(memberId, friend.getAccepter().getId()) && !friendRepository.existsByRequesterIdOrAccepterId(friend.getRequester().getId(), memberId)) {
throw new BadRequestException("서로 친구 관계가 아닙니다.");
}

Member friendMember = null;

if (friend.getAccepter().equals(member)) {
Expand All @@ -63,6 +59,10 @@ public void sendContentRecommend(Long memberId, Long friendRequestId, RecommendC
throw new BadRequestException("이미 해당 컨텐츠를 상대방에게 추천했습니다.");
}

if (!friendRepository.existsByRequesterAndAccepter(member, friendMember) && !friendRepository.existsByRequesterAndAccepter(friendMember, member)) {
throw new BadRequestException("서로 친구 관계가 아닙니다.");
}

friendRecommendRepository.save(
FriendRecommend.builder()
.sender(member)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,14 @@ public void makeFriendRequest(Long memberId, FriendEmailRequest friendEmailReque
Member accepterMember = memberRepository.findByEmail(friendEmailRequest.email())
.orElseThrow(() -> new NotFoundException("email에 해당하는 멤버가 없습니다."));

if (friendRepository.existsByRequesterIdOrAccepterId(memberId, memberId)) {
if (friendRepository.existsByRequesterAndAccepter(requesterMember, accepterMember) || friendRepository.existsByRequesterAndAccepter(accepterMember, requesterMember)) {
throw new BadRequestException("이미 친구이거나, 친구요청이 존재합니다.");
}

if (requesterMember.equals(accepterMember)) {
throw new BadRequestException("본인에게는 친구 요청을 할 수 없습니다");
}

friendRepository.save(Friend.builder()
.requester(requesterMember)
.accepter(accepterMember)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ public ResponseEntity<List<TopContentLikeResponse>> getTop10MostLikedContents()
}

@Operation(summary = "선호도 표시 삭제", description = "사용자의 선호도 표시를 삭제합니다.")
@DeleteMapping("{contentLikeId}")
public ResponseEntity<StringTypeMessageResponse> deleteContentLike(@RequestAttribute("memberId") Long memberId, @PathVariable Long contentLikeId) {
contentLikeService.deleteContentLike(memberId, contentLikeId);
@DeleteMapping("/{contentId}")
public ResponseEntity<StringTypeMessageResponse> deleteContentLike(@RequestAttribute("memberId") Long memberId, @PathVariable Long contentId) {
contentLikeService.deleteContentLike(memberId, contentId);
return ResponseEntity.ok().body(new StringTypeMessageResponse("삭제되었습니다."));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,9 @@ public List<TopContentLikeResponse> getTop10MostLikedContents() {
}

@Transactional
public void deleteContentLike(Long memberId, Long contentLikeId) {
Member member = memberRepository.findById(memberId)
.orElseThrow(() -> new NotFoundException("id에 해당하는 컨텐츠를 찾을 수 없습니다."));

ContentLike contentLike = contentLikeRepository.findById(contentLikeId)
.orElseThrow(() -> new NotFoundException("contentId에 해당하는 컨텐츠 선호도 표시가 없습니다."));

if (contentLike.memberIsNotCorrect(member)) {
throw new BadRequestException("삭제할 권한이 없습니다.");
}
public void deleteContentLike(Long memberId, Long contentId) {
ContentLike contentLike = contentLikeRepository.findByMemberIdAndContentId(memberId, contentId)
.orElseThrow(() -> new BadRequestException("선호도를 삭제할 권한이 없습니다."));

contentLikeRepository.delete(contentLike);
}
Expand Down

0 comments on commit d573bcb

Please sign in to comment.