Skip to content

Commit

Permalink
Feat: 통계 기능 수정
Browse files Browse the repository at this point in the history
- API 응답에 이번달에 받은 좋아요 개수 추가
  • Loading branch information
don9m1n committed Apr 8, 2024
1 parent e60a620 commit 50cbcc7
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.api.readinglog.domain.likesummary.repository;

public interface CustomLikeSummaryRepository {

long getLikeTotalCountInMonth(Long memberId, int month);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.api.readinglog.domain.likesummary.repository;

import static com.api.readinglog.domain.likesummary.entity.QLikeSummary.likeSummary;

import com.querydsl.jpa.impl.JPAQueryFactory;
import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
public class CustomLikeSummaryRepositoryImpl implements CustomLikeSummaryRepository {

private final JPAQueryFactory queryFactory;

@Override
public long getLikeTotalCountInMonth(Long memberId, int month) {
return queryFactory
.select(likeSummary.count())
.from(likeSummary)
.where(likeSummary.member.id.eq(memberId).and(likeSummary.createdAt.month().eq(month)))
.fetchFirst();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
import com.api.readinglog.domain.likesummary.entity.LikeSummary;
import org.springframework.data.jpa.repository.JpaRepository;

public interface LikeSummaryRepository extends JpaRepository<LikeSummary, Long> {
public interface LikeSummaryRepository extends JpaRepository<LikeSummary, Long>, CustomLikeSummaryRepository {
void deleteByMemberIdAndSummaryId(Long userId, Long summaryId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.api.readinglog.domain.book.dto.BookCalendarResponse;
import com.api.readinglog.domain.book.dto.BookCategoryResponse;
import com.api.readinglog.domain.book.repository.BookRepository;
import com.api.readinglog.domain.likesummary.repository.LikeSummaryRepository;
import com.api.readinglog.domain.stat.controller.dto.StatResponse;
import java.util.List;
import lombok.RequiredArgsConstructor;
Expand All @@ -15,15 +16,16 @@
public class StatService {

private final BookRepository bookRepository;
private final LikeSummaryRepository likeSummaryRepository;

public StatResponse getStats(Long memberId, int month) {
Long lastMonthTotalBookCount = bookRepository.getBookTotalCountInMonth(memberId, month - 1);
Long thisMonthTotalBookCount = bookRepository.getBookTotalCountInMonth(memberId, month);
List<BookCategoryResponse> bookCountGroupByCategory = bookRepository.getBookCountGroupByCategory(memberId, month);
List<BookCategoryResponse> bookCountGroupByCategory = bookRepository.getBookCountGroupByCategoryInMonth(memberId, month);
List<BookCalendarResponse> bookCalendarInMonth = bookRepository.getBookCalendarInMonth(memberId, month);
long thisMonthLikeTotalCount = likeSummaryRepository.getLikeTotalCountInMonth(memberId, month);

// TODO: 이번달 받은 좋아요 개수 추가
return StatResponse.of(month, lastMonthTotalBookCount, thisMonthTotalBookCount, null, bookCountGroupByCategory, bookCalendarInMonth);
return StatResponse.of(month, lastMonthTotalBookCount, thisMonthTotalBookCount, thisMonthLikeTotalCount, bookCountGroupByCategory, bookCalendarInMonth);
}

}

0 comments on commit 50cbcc7

Please sign in to comment.