본문 바로가기

Project/GameFriendApp

Ggamf : 겜프요청취소

 

 

겜프요청취소

 

 

 

<작업계획>

DTO 코드 작성

Service 코드 작성

Controller 코드 작성

Postman 확인

 

 

겜프 요청 취소는 Follow 테이블에서 해당 Follow 데이터를

삭제하는 작업으로 처리한다.

 

 

DTO 코드 작성

 

<RespDto>

    @Setter
    @Getter
    public static class CancelGgamfRespDto {
        private Long followId;
        // 나중에 내가보낸겜프요청 목록 보여주기

        public CancelGgamfRespDto(Long followId) {
            this.followId = followId;
        }
    }

 

 

 

Service 코드 작성

    @Transactional
    public CancelGgamfRespDto 겜프요청취소(Long userId, Long followId) {
        log.debug("디버그 : 겜프요청취소 서비스 호출");
        Follow followPS = followRepository.findById(followId)
                .orElseThrow(() -> new CustomApiException("취소 할 겜프 요청이 없습니다", HttpStatus.FORBIDDEN));
        if (followPS.getAccept() == true) {
            throw new CustomApiException("이미 겜프입니다. 삭제를 원하면 겜프 프로필에서 삭제하세요", HttpStatus.BAD_REQUEST);
        }
        if (followPS.getFollower().getId() != userId) {
            throw new CustomApiException("당신은 취소 권한이 없습니다.", HttpStatus.BAD_REQUEST);
        }
        followRepository.delete(followPS);
        return new CancelGgamfRespDto(followId);
    }

 

 

 

 

Controller 코드 작성

 

    // 겜프 요청 취소
    @DeleteMapping("ggamf/user/{userId}/cancel/{followId}")
    public ResponseEntity<?> cancelGgamf(@PathVariable Long userId, @PathVariable Long followId,
            @AuthenticationPrincipal LoginUser loginUser) {
        log.debug("디버그 : 겜프 요청 취소 컨트롤러 호출");
        if (loginUser.getUser().getId() != userId) {
            throw new CustomApiException("당신은 취소 권한이 없습니다.", HttpStatus.BAD_REQUEST);
        }
        CancelGgamfRespDto cancelGgamfRespDto = ggamfService.겜프요청취소(userId, followId);
        return new ResponseEntity<>(new ResponseDto<>("겜프요청취소 완료", cancelGgamfRespDto), HttpStatus.OK);
    }

 

 

 

 

Postman 확인

 

 

cos(userId=1)는 본인이 보낸 요청만 취소할 수 있으므로

followId=1, followId=2 인 것만 취소에 성공해야한다.

 

 

<이미 친구인 경우>

followId=5를 입력해본다.

겜프취소요청 실패 !

 

 

 

<내가 받은 요청인 경우>

followId=3을 입력해본다.

겜프요청취소 실패!

 

 

<내가 보낸 요청인 경우>

followId=1을 입력해본다.

겜프취소요청 정상:)

 

 

 

 

다시 같은 요청을 해보면

겜프취소요청이 정상처리되어

followId=1이 삭제된 것을 확인할 수 있다.

 

 

'Project > GameFriendApp' 카테고리의 다른 글

Ggamf : 겜프 신고  (0) 2022.12.08
Ggamf : 겜프요청취소 Junit Test  (0) 2022.12.08
Ggamf : 겜프 거절 Junit Test  (0) 2022.12.08
Ggamf : 겜프 거절  (0) 2022.12.08
Ggamf : 겜프 삭제 Junit Test  (0) 2022.12.08