본문 바로가기

Project/GameFriendApp

Ggamf : 보낸 겜프 요청 목록 보기

 

 

보낸 겜프 요청 목록 보기

 

 

 

 

 

<작업계획>

DTO 코드 작성

Service 코드 작성

Repository 쿼리 작성

Controller 코드 작성

Postman 확인

 

 

 

 

DTO 코드 작성

<RespDto>

    @Setter
    @Getter
    public static class SendGgamfRespDto {

        List<FollowingDto> followings;

        public SendGgamfRespDto(List<Follow> followings) {
            this.followings = followings.stream().map((follow) -> new FollowingDto(follow))
                    .collect(Collectors.toList());
        }

        @Setter
        @Getter
        public class FollowingDto {
            private Long friendId;
            private String photo;
            private String nickName;
            private String intro;

            public FollowingDto(Follow follow) {
                this.friendId = follow.getFollowing().getId();
                this.photo = follow.getFollowing().getPhoto();
                this.nickName = follow.getFollowing().getNickname();
                this.intro = follow.getFollowing().getIntro();
            }
        }

    }

 

 

 

 

Service 코드 작성

 

    public SendGgamfRespDto 보낸겜프요청목록보기(Long userId) {
        // 내가 보낸 요청 중에서 아직 수락되지 않은 요청 목록
        List<Follow> followListPS = followRepository.findByUserIdFollower(userId);
        return new SendGgamfRespDto(followListPS);
    }

 

 

 

 

Repository 쿼리 작성

 

<FollowRepository>

    // 내가 보낸 겜프 요청 보기
    @Query("select f from Follow f join fetch f.follower e where e.id = :userId and f.accept=false")
    List<Follow> findByUserIdFollower(@Param("userId") Long userId);

 

 

 

 

Controller 코드 작성

 

    // 내가 보낸 겜프 요청 목록 보기
    @GetMapping("/ggamf/user/{userId}/sendggamf")
    public ResponseEntity<?> sendGgamfList(@PathVariable Long userId, @AuthenticationPrincipal LoginUser loginUser) {
        log.debug("디버그 : 보낸 겜프 요청 목록 보기 컨트롤러 호출");
        if (loginUser.getUser().getId() != userId) {
            throw new CustomApiException("로그인 유저와 요청 유저가 일치하지 않습니다.",
                    HttpStatus.BAD_REQUEST);
        }
        SendGgamfRespDto sendGgamfRespDto = ggamfService.보낸겜프요청목록보기(userId);
        return new ResponseEntity<>(new ResponseDto<>("보낸겜프요청목록보기 완료", sendGgamfRespDto),
                HttpStatus.OK);
    }

 

 

 

 

 

Postman 확인