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

[Feature/389] 친구 삭제 API 구현 완료 #390

Merged
merged 2 commits into from
Oct 27, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import static com.namo.spring.core.common.code.status.ErrorStatus.*;

import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
Expand Down Expand Up @@ -115,4 +115,18 @@ public ResponseDto<String> toggleFavorite(@AuthenticationPrincipal SecurityUserD
String message = isFavorite ? "친구를 즐겨찾기에 등록했습니다." : "친구를 즐겨찾기에서 해제했습니다.";
return ResponseDto.onSuccess(message);
}

@Operation(summary = "친구 삭제", description = "특정 친구를 삭제합니다.")
@ApiErrorCodes(value = {
NOT_FOUND_FRIENDSHIP_FAILURE,
})
@DeleteMapping("/{friendId}")
public ResponseDto<String> deleteFriend(
@AuthenticationPrincipal SecurityUserDetails member,
@Parameter(description = "삭제할 친구의 memberId를 입력해주세요", example = "1")
@PathVariable Long friendId
){
friendUseCase.deleteFriend(member.getUserId(), friendId);
return ResponseDto.onSuccess("친구 삭제 완료");
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.namo.spring.application.external.api.user.service;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import com.namo.spring.db.mysql.domains.schedule.exception.ScheduleException;
Expand Down Expand Up @@ -123,4 +125,13 @@ public Friendship getAcceptedFriendship(Long memberId, Long friendId){
return friendshipService.readFriendshipByStatus(memberId, friendId, FriendshipStatus.ACCEPTED)
.orElseThrow(() -> new MemberException(ErrorStatus.NOT_FOUND_FRIENDSHIP_FAILURE));
}

/**
* 친구 관계는 양방향으로 생성되기 때문에 양방향 입력을 받아 삭제처리 합니다.
* @param target
* @param reversedTarget
*/
public void deleteFriendShip(Friendship target, Friendship reversedTarget) {
friendshipService.deleteAll(Arrays.asList(target, reversedTarget));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,11 @@ public boolean toggleFavorite(Long memberId, Long friendId) {
friendship.toggleFavorite();
return friendship.isFavorite();
}

@Transactional
public void deleteFriend(Long memberId, Long friendId) {
Friendship target = friendManageService.getAcceptedFriendship(memberId, friendId);
Friendship reversedTarget = friendManageService.getAcceptedFriendship(friendId, memberId);
friendManageService.deleteFriendShip(target, reversedTarget);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ public void delete(Friendship friendship) {
friendshipRepository.delete(friendship);
}

public void deleteAll(List<Friendship> friendships){
friendshipRepository.deleteAll(friendships);
}

/**
* startDate부터 endDate까지의 날짜가 생일인
* 친구의 정보와 생일을 조회합니다.
Expand Down
Loading