Skip to content

Commit

Permalink
Merge pull request #96 from reading-log/feature/#95-stat-like
Browse files Browse the repository at this point in the history
통계 기능 추가
  • Loading branch information
don9m1n authored Apr 8, 2024
2 parents 1ebdc41 + 50cbcc7 commit 1a28ed4
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public interface CustomBookRepository {

Long getBookTotalCountInMonth(long memberId, int month);

List<BookCategoryResponse> getBookCountGroupByCategory(Long memberId, int month);
List<BookCategoryResponse> getBookCountGroupByCategoryInMonth(Long memberId, int month);

List<BookCalendarResponse> getBookCalendarInMonth(Long memberId, int month);
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public Long getBookTotalCountInMonth(long memberId, int month) {
}

@Override
public List<BookCategoryResponse> getBookCountGroupByCategory(Long memberId, int month) {
public List<BookCategoryResponse> getBookCountGroupByCategoryInMonth(Long memberId, int month) {
return queryFactory
.select(Projections.constructor(BookCategoryResponse.class, book.category, book.count()))
.from(book)
Expand Down
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);
}

}
9 changes: 9 additions & 0 deletions src/main/resources/data.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
insert into member(member_id, member_email, member_nickname, member_password, member_profile_img, member_role,
created_at, modified_at, deleted_at)
values (1, '[email protected]', '동민', '{noop}1234', 'default.png', 'member_normal', now(), now(), null);
insert into member(member_id, member_email, member_nickname, member_password, member_profile_img, member_role,
created_at, modified_at, deleted_at)
values (2, '[email protected]', '동민22', '{noop}1234', 'default.png', 'member_normal', now(), now(), null);

insert into book (book_id, member_id, book_item_id, book_title, book_author, book_publisher, book_category, book_cover, created_at, modified_at, deleted_at) values (1, 1, null, 'Report, The (Gozaresh)', 'hmival0', 'Anheuser-Busch Inbev SA', 'Oyondu', 'http://dummyimage.com/159x100.png/ff4444/ffffff', '2024-03-13 07:37:09', '2024-03-05 20:23:56', null);
insert into book (book_id, member_id, book_item_id, book_title, book_author, book_publisher, book_category, book_cover, created_at, modified_at, deleted_at) values (2, 1, null, 'Formula, The', 'tcrookshank1', 'Viad Corp', 'Mydeo', 'http://dummyimage.com/116x100.png/dddddd/000000', '2024-03-12 23:27:43', '2024-03-09 00:25:25', null);
Expand Down Expand Up @@ -63,3 +66,9 @@ insert into summary (summary_id, member_id, book_id, summary_content, created_at
insert into summary (summary_id, member_id, book_id, summary_content, created_at, modified_at, deleted_at) values (28, 1, 28, 'Streamlined mobile capacity', '2024-03-24 12:31:10', '2024-03-11 19:23:06', null);
insert into summary (summary_id, member_id, book_id, summary_content, created_at, modified_at, deleted_at) values (29, 1, 29, 'Cross-group intermediate superstructure', '2024-03-19 07:58:29', '2024-03-17 03:57:50', null);
insert into summary (summary_id, member_id, book_id, summary_content, created_at, modified_at, deleted_at) values (30, 1, 30, 'De-engineered demand-driven open architecture', '2024-03-13 14:06:05', '2024-03-02 14:13:32', null);

insert into like_summary(id, member_id, summary_id, created_at, modified_at, deleted_at) values (1, 1, 1, now(), now(), null);
insert into like_summary(id, member_id, summary_id, created_at, modified_at, deleted_at) values (2, 1, 2, now(), now(), null);
insert into like_summary(id, member_id, summary_id, created_at, modified_at, deleted_at) values (3, 1, 3, now(), now(), null);
insert into like_summary(id, member_id, summary_id, created_at, modified_at, deleted_at) values (4, 1, 4, now(), now(), null);
insert into like_summary(id, member_id, summary_id, created_at, modified_at, deleted_at) values (5, 1, 5, now(), now(), null);

0 comments on commit 1a28ed4

Please sign in to comment.