-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #97 from reading-log/develop
04.08 MAIN MERGE
- Loading branch information
Showing
31 changed files
with
602 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/main/java/com/api/readinglog/common/cache/CacheInitializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.api.readinglog.common.cache; | ||
|
||
import com.api.readinglog.domain.likesummary.service.LikeSummaryService; | ||
import com.api.readinglog.domain.summary.entity.Summary; | ||
import com.api.readinglog.domain.summary.repository.SummaryRepository; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.boot.context.event.ApplicationReadyEvent; | ||
import org.springframework.context.event.EventListener; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class CacheInitializer { | ||
|
||
private final LikeSummaryService likeSummaryService; | ||
private final SummaryRepository summaryRepository; | ||
|
||
// 서버 재시작 시 캐시의 좋아요 개수를 DB에 초기화 | ||
@EventListener(ApplicationReadyEvent.class) | ||
public void initializeCacheWithSummaries(ApplicationReadyEvent event) { | ||
List<Summary> summaries = summaryRepository.findAll(); | ||
|
||
summaries.forEach(summary -> { | ||
Long summaryId = summary.getId(); | ||
int likeCount = likeSummaryService.getSummaryLikeCount(summaryId); | ||
|
||
summary.setLikeCount(likeCount); | ||
summaryRepository.save(summary); | ||
}); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/api/readinglog/common/querydsl/QuerydslConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.api.readinglog.common.querydsl; | ||
|
||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import jakarta.persistence.EntityManager; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
public class QuerydslConfig { | ||
|
||
@Bean | ||
public JPAQueryFactory jpaQueryFactory(EntityManager em) { | ||
return new JPAQueryFactory(em); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/main/java/com/api/readinglog/domain/book/dto/BookCalendarResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.api.readinglog.domain.book.dto; | ||
|
||
import java.time.LocalDateTime; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public class BookCalendarResponse { | ||
|
||
private Long bookId; | ||
private String title; | ||
private LocalDateTime createdAt; | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/api/readinglog/domain/book/dto/BookCategoryResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.api.readinglog.domain.book.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public class BookCategoryResponse { | ||
|
||
private String category; | ||
private long count; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/main/java/com/api/readinglog/domain/book/repository/CustomBookRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.api.readinglog.domain.book.repository; | ||
|
||
import com.api.readinglog.domain.book.dto.BookCalendarResponse; | ||
import com.api.readinglog.domain.book.dto.BookCategoryResponse; | ||
import java.util.List; | ||
|
||
public interface CustomBookRepository { | ||
|
||
Long getBookTotalCountInMonth(long memberId, int month); | ||
|
||
List<BookCategoryResponse> getBookCountGroupByCategoryInMonth(Long memberId, int month); | ||
|
||
List<BookCalendarResponse> getBookCalendarInMonth(Long memberId, int month); | ||
} |
46 changes: 46 additions & 0 deletions
46
src/main/java/com/api/readinglog/domain/book/repository/CustomBookRepositoryImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.api.readinglog.domain.book.repository; | ||
|
||
import static com.api.readinglog.domain.book.entity.QBook.book; | ||
|
||
import com.api.readinglog.domain.book.dto.BookCalendarResponse; | ||
import com.api.readinglog.domain.book.dto.BookCategoryResponse; | ||
import com.querydsl.core.types.Projections; | ||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
public class CustomBookRepositoryImpl implements CustomBookRepository{ | ||
|
||
private final JPAQueryFactory queryFactory; | ||
|
||
@Override | ||
public Long getBookTotalCountInMonth(long memberId, int month) { | ||
return queryFactory | ||
.select(book.count()) | ||
.from(book) | ||
.where(book.member.id.eq(memberId).and(book.createdAt.month().eq(month))) | ||
.fetchFirst(); | ||
} | ||
|
||
@Override | ||
public List<BookCategoryResponse> getBookCountGroupByCategoryInMonth(Long memberId, int month) { | ||
return queryFactory | ||
.select(Projections.constructor(BookCategoryResponse.class, book.category, book.count())) | ||
.from(book) | ||
.where(book.member.id.eq(memberId).and(book.createdAt.month().eq(month))) | ||
.groupBy(book.category) | ||
.orderBy(book.count().desc()) | ||
.fetch(); | ||
} | ||
|
||
@Override | ||
public List<BookCalendarResponse> getBookCalendarInMonth(Long memberId, int month) { | ||
return queryFactory | ||
.select(Projections.constructor(BookCalendarResponse.class, book.id, book.title, book.createdAt)) | ||
.from(book) | ||
.where(book.member.id.eq(memberId).and(book.createdAt.month().eq(month))) | ||
.orderBy(book.createdAt.asc()) | ||
.fetch(); | ||
} | ||
} |
Oops, something went wrong.