Skip to content

Commit

Permalink
Merge pull request #14 from gutanbug/feat/myPetition
Browse files Browse the repository at this point in the history
feat: 내가 쓴 청원 글, 내가 동의한 청원 글 개수 및 목록 조회 기능 추가
  • Loading branch information
gutanbug authored Dec 26, 2023
2 parents f1aa1e4 + 453e20b commit ee59fa0
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,19 @@ public ResponsePage<SummarizedPetitionDto> listMyPosts(AppAuthentication auth,
return new ResponsePage<>(posts);
}

/**
* 내가 동의한 글 조회
*/
@GetMapping("/my/agreed")
@UserAuth
public ResponsePage<SummarizedPetitionDto> listMyAgreedPosts(AppAuthentication auth,
@ParameterObject Pageable pageable,
@RequestParam(defaultValue = "50") int bodySize) {
Page<SummarizedPetitionDto> posts =
petitionService.listMyAgreedPosts(auth.getUserId(), pageable, bodySize);
return new ResponsePage<>(posts);
}

/**
* 게시글 등록
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,8 @@ public interface PetitionRepository extends GenericPostRepository<Petition>{
@Query("select p from Petition p where p.user.id=:userId and p.status='ACTIVE'")
Page<Petition> findAllByUserId(@Param("userId") Long userId, Pageable pageable);

@Query("select p from Petition p " +
"join fetch PetitionStatistic ps on p.id = ps.petition.id " +
"where ps.user.id=:userId and p.status='ACTIVE' ")
Page<Petition> findAllAgreedByUserId (@Param("userId") Long userId, Pageable pageable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,21 @@ public interface PostRepository extends JpaRepository<Post, Long> {
"and p.status='ACTIVE'")
Long countAllByUserId(@Param("userId") Long userId);

/**
* user 가 작성한 청원 게시글의 총 개수를 가져옵니다.
*/
@Query("select count(*) from Post p " +
"where p.user.id=:userId and " +
"TYPE(p) IN (Petition) and " +
"p.status='ACTIVE' ")
Long countAllPetitionByUserId(@Param("userId") Long userId);

/**
* user 가 동의한 청원 게시글의 총 개수를 가져옵니다.
*/
@Query("select count(*) from Post p " +
"join PetitionStatistic as ps on p.id = ps.petition.id " +
"where ps.user.id=:userId and " +
"p.status='ACTIVE' ")
Long countAllAgreedPetitionByUserId(Long userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,13 @@ public Page<SummarizedPetitionDto> listMyPosts(Long userId, Pageable pageable, i
return new SummarizedPetitionDto(dto, post, expiresTime, statisticService.count(post.getId()));
});
}

@Transactional(readOnly = true)
public Page<SummarizedPetitionDto> listMyAgreedPosts(Long userId, Pageable pageable, int bodySize) {
return repository.findAllAgreedByUserId(userId, pageable)
.map(post -> {
SummarizedGenericPostDto dto = postService.makeListDto(bodySize, post);
return new SummarizedPetitionDto(dto, post, expiresTime, statisticService.count(post.getId()));
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,7 @@ public class ResponseUserInfoDto {
private final Long writePostCount;
private final Long commentedPostCount;
private final Long likedPostCount;
private final Long petitionCount;
private final Long agreedPetitionCount;
private final boolean admin;
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,14 @@ public ResponseUserInfoDto getFullUserInfo(Long userId) {
Long writePostCount = postRepository.countAllByUserId(userId);
Long commentedPostCount = commentRepository.countAllCommentedByUserId(userId);
Long likedPostCount = likeService.getCountOfLikedElements(userId, LikeTarget.POST);
Long petitionCount = postRepository.countAllPetitionByUserId(userId);
Long agreedPetitionCount = postRepository.countAllAgreedPetitionByUserId(userId);

return new ResponseUserInfoDto(user.getStudentId(), user.getName(),
user.getNickname(), user.getAge(), user.getGender(), year,
major.getName(), major.getDepartment(), phoneNumber,
writePostCount, commentedPostCount, likedPostCount,
user.getUserRole().isAdmin());
petitionCount, agreedPetitionCount, user.getUserRole().isAdmin());
}

@Transactional(readOnly = true)
Expand Down

0 comments on commit ee59fa0

Please sign in to comment.