-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature] 베스트 셀러 Redis 조회 기능 및 스케쥴링 구현 #55
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
81cc3dd
chore: Redis 관련 의존성 추가 (#45)
jwooo ae97085
feat: Redis 관련 설정 추가 (#45)
jwooo 08de615
feat: BestSellerUpdate Event 추가 (#45)
jwooo 0939985
feat: 베스트 셀러 페이징 조회 API 추가 (#45)
jwooo 32e2152
feat: 베스트 셀러 스케쥴링 기능 추가 (#45)
jwooo c13580c
test: 테스트 컨테이너 추가 (#45)
jwooo 17d5e71
test: 베스트 셀러 페이징 조회 API 테스트 추가 (#45)
jwooo ccbc4fd
build: docker-compose redis 컴포넌트 추가 (#45)
jwooo 79a9ead
refactor: 엔티티 @Lob 타입 제거 (#45)
jwooo 5a7f971
refactor: Redis password 추가 (#45)
jwooo 0f436ed
chore: Redis password 설정 추가 (#45)
jwooo 2c6f463
deploy: 배포 파일 REDIS_PASSWORD 추가 (#45)
jwooo 01c859c
refactor: BestSellerRedisRepository 커스텀 Exception 반환 (#45)
jwooo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -114,13 +114,16 @@ jobs: | |
# SSH Key로 서버에 접속하고 docker-compose image를 pull 받고 실행하기 | ||
- name: Access Server with SSH Key, pull and execute docker-compose image | ||
uses: appleboy/[email protected] | ||
env: | ||
REDIS_PASSWORD: ${{ secrets.REDIS_PASSWORD }} | ||
with: | ||
host: ${{ secrets.EC2_HOST }} | ||
username: ${{ secrets.EC2_USERNAME }} | ||
key: ${{ secrets.KEY }} | ||
port: 22 | ||
script: | | ||
cd jisungin | ||
echo "REDIS_PASSWORD=${{ secrets.REDIS_PASSWORD }}" > .env | ||
sudo docker-compose down | ||
sudo docker-compose pull | ||
sudo docker-compose up -d | ||
|
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
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
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
30 changes: 30 additions & 0 deletions
30
src/main/java/com/jisungin/api/book/request/BookPageRequest.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,30 @@ | ||
package com.jisungin.api.book.request; | ||
|
||
import com.jisungin.application.book.request.BookServicePageRequest; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
@NoArgsConstructor | ||
public class BookPageRequest { | ||
|
||
Integer page; | ||
Integer size; | ||
|
||
@Builder | ||
private BookPageRequest(Integer page, Integer size) { | ||
this.page = page != null ? page : 1; | ||
this.size = size != null ? size : 5; | ||
} | ||
|
||
public BookServicePageRequest toServiceRequest() { | ||
return BookServicePageRequest.builder() | ||
.page(page) | ||
.size(size) | ||
.build(); | ||
} | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java/com/jisungin/application/book/BestSellerService.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,35 @@ | ||
package com.jisungin.application.book; | ||
|
||
import com.jisungin.application.PageResponse; | ||
import com.jisungin.application.book.event.BestSellerUpdatedEvent; | ||
import com.jisungin.application.book.request.BookServicePageRequest; | ||
import com.jisungin.application.book.response.BestSellerResponse; | ||
import com.jisungin.domain.book.repository.BestSellerRepository; | ||
import com.jisungin.infra.crawler.Crawler; | ||
import com.jisungin.infra.crawler.CrawlingBook; | ||
import java.util.Map; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.context.ApplicationEventPublisher; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class BestSellerService { | ||
|
||
private final Crawler crawler; | ||
private final BestSellerRepository bestSellerRepository; | ||
private final ApplicationEventPublisher eventPublisher; | ||
|
||
public PageResponse<BestSellerResponse> getBestSellers(BookServicePageRequest page) { | ||
return bestSellerRepository.findBestSellerByPage(page); | ||
} | ||
|
||
|
||
public void updateBestSellers() { | ||
Map<Long, CrawlingBook> crawledBooks = crawler.crawlBestSellerBook(); | ||
|
||
bestSellerRepository.updateAll(crawledBooks); | ||
eventPublisher.publishEvent(new BestSellerUpdatedEvent(crawledBooks)); | ||
} | ||
|
||
} |
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
16 changes: 16 additions & 0 deletions
16
src/main/java/com/jisungin/application/book/event/BestSellerUpdatedEvent.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,16 @@ | ||
package com.jisungin.application.book.event; | ||
|
||
import com.jisungin.infra.crawler.CrawlingBook; | ||
import java.util.Map; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class BestSellerUpdatedEvent { | ||
|
||
private final Map<Long, CrawlingBook> crawledBooks; | ||
|
||
public BestSellerUpdatedEvent(Map<Long, CrawlingBook> crawledBooks) { | ||
this.crawledBooks = crawledBooks; | ||
} | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/com/jisungin/application/book/event/BestSellerUpdatedEventListener.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,29 @@ | ||
package com.jisungin.application.book.event; | ||
|
||
import com.jisungin.application.book.BookService; | ||
import com.jisungin.application.book.request.BookCreateServiceRequest; | ||
import com.jisungin.infra.crawler.CrawlingBook; | ||
import java.util.List; | ||
import java.util.Map; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.context.event.EventListener; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class BestSellerUpdatedEventListener { | ||
|
||
private final BookService bookService; | ||
|
||
@EventListener | ||
public void handleBestSellerUpdatedEvent(BestSellerUpdatedEvent event) { | ||
Map<Long, CrawlingBook> crawledBook = event.getCrawledBooks(); | ||
|
||
List<BookCreateServiceRequest> bookCreateServiceRequests = crawledBook.values().stream() | ||
.map(CrawlingBook::toServiceRequest) | ||
.toList(); | ||
|
||
bookService.addNewBooks(bookCreateServiceRequests); | ||
} | ||
|
||
} |
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
26 changes: 26 additions & 0 deletions
26
src/main/java/com/jisungin/application/book/request/BookServicePageRequest.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,26 @@ | ||
package com.jisungin.application.book.request; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class BookServicePageRequest { | ||
|
||
private Integer page; | ||
private Integer size; | ||
|
||
@Builder | ||
private BookServicePageRequest(Integer page, Integer size) { | ||
this.page = page; | ||
this.size = size; | ||
} | ||
|
||
public Integer extractStartIndex() { | ||
return (page * size) - size + 1; | ||
} | ||
|
||
public Integer extractEndIndex() { | ||
return page * size; | ||
} | ||
|
||
} |
45 changes: 45 additions & 0 deletions
45
src/main/java/com/jisungin/application/book/response/BestSellerResponse.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,45 @@ | ||
package com.jisungin.application.book.response; | ||
|
||
import java.time.LocalDateTime; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
public class BestSellerResponse { | ||
|
||
private Long ranking; | ||
private String isbn; | ||
private String title; | ||
private String publisher; | ||
private String thumbnail; | ||
private String[] authors; | ||
private LocalDateTime dateTime; | ||
|
||
@Builder | ||
private BestSellerResponse(Long ranking, String isbn, String title, String publisher, String thumbnail, | ||
String[] authors, LocalDateTime dateTime) { | ||
this.ranking = ranking; | ||
this.isbn = isbn; | ||
this.title = title; | ||
this.publisher = publisher; | ||
this.thumbnail = thumbnail; | ||
this.authors = authors; | ||
this.dateTime = dateTime; | ||
} | ||
|
||
public static BestSellerResponse of(Long ranking, String isbn, String title, String publisher, String thumbnail, | ||
String[] authors, LocalDateTime dateTime) { | ||
return BestSellerResponse.builder() | ||
.ranking(ranking) | ||
.isbn(isbn) | ||
.title(title) | ||
.publisher(publisher) | ||
.thumbnail(thumbnail) | ||
.authors(authors) | ||
.dateTime(dateTime) | ||
.build(); | ||
} | ||
|
||
} |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
애플리케이션 실행 시 캐싱, 스케줄링, 리트라이가 적용되는 건가요 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
네
@Enablexxx
어노테이션들은 관련된 라이브러리의 기능을 활성화하는 역할 입니다!