Skip to content

Commit

Permalink
Merge pull request #73 from Nawabali-project/feature/34/cicdNotification
Browse files Browse the repository at this point in the history
동네별 점수 조회
  • Loading branch information
minnieming authored Apr 12, 2024
2 parents b43f0c9 + 08473d8 commit 78b6851
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 3 deletions.
20 changes: 20 additions & 0 deletions .idea/dataSources.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,12 @@ public ResponseEntity<List<PostSearch>> searchPost(@RequestParam("query") String
List<PostSearch> postDslDto = postService.searchByContents(contents);
return ResponseEntity.ok(postDslDto);
}

@Operation(summary = "동네별 점수 조회", description = "동네(구)를 넣으면 총 게시물 수 / 좋아요 수 / 동네인증 수 조회 가능합니다")
@GetMapping("/district/{district}")
public ResponseEntity<PostDto.DistrictDto> districtMap(@PathVariable String district, @AuthenticationPrincipal UserDetailsImpl userDetails) {
PostDto.DistrictDto districtDto = postService.districtMap(district, userDetails.getUser());
return ResponseEntity.ok(districtDto);
}
}

12 changes: 12 additions & 0 deletions src/main/java/com/nawabali/nawabali/dto/PostDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,16 @@ public static class getMyPostsResponseDto {

private Long id;
}

@Getter
@AllArgsConstructor
@NoArgsConstructor
@Builder
public static class DistrictDto {

private Long totalPost;
private Long totalLike;
private Long totalLocalLike;

}
}
3 changes: 3 additions & 0 deletions src/main/java/com/nawabali/nawabali/exception/ErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ public enum ErrorCode {
INCHATROOM_NOT_FOUND(NOT_FOUND, "속해있는 채팅방이 없습니다."),
CHAT_MESSAGE_NOT_FOUND(NOT_FOUND, "해당 메세지를 찾을 수 없습니다."),
NOTIFICATION_NOT_FOUND(NOT_FOUND, "해당 알림을 찾을 수 없습니다."),
DISTRICTPOST_NOT_FOUND(NOT_FOUND, "해당 구의 총 게시물 수를 찾을 수 없습니다."),
DISTRICTLIKE_NOT_FOUND(NOT_FOUND, "해당 구의 총 좋아요 수를 찾을 수 없습니다."),
DISTRICTLOCALLIKE_NOT_FOUND(NOT_FOUND, "해당 구의 총 동네인증 수를 찾을 수 없습니다."),

// 409 CONFLICT: 중복된 리소스 (요청이 현재 서버 상태와 충돌될 때)
DUPLICATE_EMAIL(CONFLICT, "이미 존재하는 이메일입니다."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ public interface LikeRepository extends JpaRepository <Like, Long> {
Like findByUserIdAndPostIdAndLikeCategoryEnum(Long userId, Long postId, LikeCategoryEnum likeCategoryEnum);
Optional<Object> findFirstByPostIdAndUserIdAndLikeCategoryEnum(Long postId, Long userId, LikeCategoryEnum likeCategoryEnum);

Optional<Long> countByPostTownDistrictAndLikeCategoryEnum(String district, LikeCategoryEnum likeCategoryEnum);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public interface PostRepository extends JpaRepository<Post, Long> , PostDslRepositoryCustom {
List<PostDto.getMyPostsResponseDto> findByUserId(Long userId);

Optional<Long> countByTownDistrict(String district);
}
33 changes: 30 additions & 3 deletions src/main/java/com/nawabali/nawabali/service/PostService.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
import java.util.List;
import java.util.stream.Collectors;

import static com.nawabali.nawabali.constant.LikeCategoryEnum.LIKE;
import static com.nawabali.nawabali.constant.LikeCategoryEnum.LOCAL_LIKE;

@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
Expand Down Expand Up @@ -87,7 +90,7 @@ public Slice<PostDto.ResponseDto> getPostsByLatest(Pageable pageable) {
Slice<PostDslDto.ResponseDto> postSlice = postRepository.findPostsByLatest(pageable);
List<PostDto.ResponseDto> content = postSlice.getContent().stream()
.map(post -> {
Long likesCount = getLikesCount(post.getPostId(), LikeCategoryEnum.LIKE);
Long likesCount = getLikesCount(post.getPostId(), LIKE);
Long localLikesCount = getLikesCount(post.getPostId(), LikeCategoryEnum.LOCAL_LIKE);

return new PostDto.ResponseDto(
Expand Down Expand Up @@ -116,7 +119,7 @@ public Slice<PostDto.ResponseDto> getPostsByLatest(Pageable pageable) {
// 상세 게시물 조회
public PostDto.ResponseDetailDto getPost(Long postId) {
Post post = getPostId(postId);
Long likesCount = getLikesCount(postId, LikeCategoryEnum.LIKE);
Long likesCount = getLikesCount(postId, LIKE);
Long localLikesCount = getLikesCount(postId, LikeCategoryEnum.LOCAL_LIKE);
String profileImageUrl = getProfileImage(postId).getImgUrl();

Expand All @@ -128,7 +131,7 @@ public Slice<PostDto.ResponseDto> getPostByCategory(String category, String dist
Slice<PostDslDto.ResponseDto> postCategory = postRepository.findCategoryByPost(category,district, pageable);
List<PostDto.ResponseDto> content = postCategory.getContent().stream()
.map(post -> {
Long likesCount = getLikesCount(post.getPostId(), LikeCategoryEnum.LIKE);
Long likesCount = getLikesCount(post.getPostId(), LIKE);
Long localLikesCount = getLikesCount(post.getPostId(), LikeCategoryEnum.LOCAL_LIKE);

return new PostDto.ResponseDto(
Expand Down Expand Up @@ -210,4 +213,28 @@ public ProfileImage getProfileImage(Long postId) {
.orElseThrow(() -> new CustomException(ErrorCode.PROFILEIMAGE_NOT_FOUND));
}

// 동네별 점수 조회
public PostDto.DistrictDto districtMap(String district, User user) {

// 유저 인증
userService.getUserId(user.getId());

Long post = postRepository.countByTownDistrict(district)
.orElseThrow(()-> new CustomException(ErrorCode.DISTRICTPOST_NOT_FOUND));

Long like = likeRepository.countByPostTownDistrictAndLikeCategoryEnum(district, LIKE)
.orElseThrow(()-> new CustomException(ErrorCode.DISTRICTLIKE_NOT_FOUND));

Long localLike = likeRepository.countByPostTownDistrictAndLikeCategoryEnum(district, LOCAL_LIKE)
.orElseThrow(()-> new CustomException(ErrorCode.DISTRICTLOCALLIKE_NOT_FOUND));

PostDto.DistrictDto districtDto = PostDto.DistrictDto.builder()
.totalPost(post)
.totalLike(like)
.totalLocalLike(localLike)
.build();

return districtDto;
}

}

0 comments on commit 78b6851

Please sign in to comment.