-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: 코드 위치 변경 및 패키지 이동 * chore: 코드 위치 변경 및 패키지 이동 * chore: 코드 위치 변경 및 패키지 이동 * chore: 코드 위치 변경 및 패키지 이동 * feat: Rank API 예외 코드 반영 * feat: 이벤트 수집 API를 하나의 컨트롤러로 정리 * feat: 시큐리티 설정에 Public 경로 추가 (Shared) * feat: Event 타입 정의 * feat: Event Producer (전송자) * feat: Event Consumer (소비자) * feat: 랭킹 집계 모듈 * chore: 코드 위치 변경 및 패키지 이동 * chore: 코드 위치 변경 및 패키지 이동 * chore: 스웨거에 타입 명시 추가 * chore: 스웨거에 시큐리티 스키마 제거 * feat: 랭킹 서비스 리팩토링 * chore: 주석 업데이트 * fix: 204 NoContent로 반환 * fix: 이벤트에 pickId 추가 * fix: 이벤트 리스너 디버깅 추가 * fix: uri 에 언더스코어 제거 * chore: application yaml 에 경로 추가 * chore: SecurityRequirement 어노테이션 제거 * refactor: 이름 변경 및 dto core 모듈로 이동 * refactor: 이름 변경 및 api endpoint 수정 (rank -> ranking) * feat: 랭킹 API 정보 통신을 위한 RestClient 구현 * chore: 이벤트 api 엔드포인트 통일
- Loading branch information
1 parent
921c37a
commit 171ee91
Showing
10 changed files
with
154 additions
and
9 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
52 changes: 52 additions & 0 deletions
52
...k-api/src/main/java/techpick/api/application/ranking/controller/RankingApiController.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,52 @@ | ||
package techpick.api.application.ranking.controller; | ||
|
||
import java.time.LocalDate; | ||
|
||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponses; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import techpick.api.infrastructure.ranking.RankingRepository; | ||
import techpick.api.application.ranking.dto.RankingByViewCount; | ||
|
||
/** | ||
* techpick-ranking 서버로 부터 데이터를 받아와 뿌려준다. | ||
*/ | ||
@Slf4j | ||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/suggestion") | ||
@Tag(name = "추천/소개 API", description = "링크, 픽 등에 대한 소개") | ||
public class RankingApiController { | ||
|
||
private final RankingRepository rankingRepository; | ||
|
||
/** | ||
* 주별, 일별 조회 수를 기반 으로 추천 한다. | ||
* - 조회수 기반 집계 | ||
*/ | ||
@GetMapping("/view") | ||
@Operation(summary = "기간 별 인기 링크 Top 10", description = "기간 별 인기 조회수 글을 10개씩 획득 합니다.") | ||
@ApiResponses(value = { | ||
@ApiResponse(responseCode = "200", description = "조회 성공") | ||
}) | ||
public ResponseEntity<RankingByViewCount> getSuggestionByViewCount( | ||
) { | ||
var LIMIT = 10; | ||
var currentDay = LocalDate.now(); | ||
var before1Day = currentDay.minusDays(1); | ||
var before7Days = currentDay.minusDays(7); | ||
|
||
var dailyRanking = rankingRepository.getLinkRanking(currentDay, currentDay, LIMIT).getBody(); | ||
var weeklyRanking = rankingRepository.getLinkRanking(before7Days, before1Day, LIMIT).getBody(); | ||
var response = new RankingByViewCount(dailyRanking, weeklyRanking); | ||
return ResponseEntity.ok(response); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...d/techpick-api/src/main/java/techpick/api/application/ranking/dto/RankingByViewCount.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,17 @@ | ||
package techpick.api.application.ranking.dto; | ||
|
||
import java.util.List; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import techpick.core.dto.LinkInfoWithViewCount; | ||
|
||
public record RankingByViewCount( | ||
// today's hot pick | ||
@Schema(description = "오늘 하루 동안 인기 있는 링크 Top 10") | ||
List<LinkInfoWithViewCount> daily, | ||
|
||
// weekly hot pick | ||
@Schema(description = "지난 7일동안 인기 있던 링크 Top 10") | ||
List<LinkInfoWithViewCount> weekly | ||
) { | ||
} |
29 changes: 29 additions & 0 deletions
29
backend/techpick-api/src/main/java/techpick/api/config/HttpApiConfiguration.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 techpick.api.config; | ||
|
||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.client.RestClient; | ||
import org.springframework.web.client.support.RestClientAdapter; | ||
import org.springframework.web.service.invoker.HttpServiceProxyFactory; | ||
|
||
import techpick.api.infrastructure.ranking.RankingRepository; | ||
|
||
/** | ||
* 외부 서버와 통신하는 것을 Http Interface 방식으로 사용하기 위한 설정. <br> | ||
* - https://docs.spring.io/spring-framework/reference/integration/rest-clients.html#rest-http-interface | ||
*/ | ||
@Configuration | ||
public class HttpApiConfiguration { | ||
|
||
@Value("${server-url.ranking-server}") | ||
private String rankingServerUrl; | ||
|
||
@Bean | ||
public RankingRepository rankingApi() { | ||
var restClient = RestClient.create(rankingServerUrl); | ||
var adapter = RestClientAdapter.create(restClient); | ||
var proxy = HttpServiceProxyFactory.builderFor(adapter).build(); | ||
return proxy.createClient(RankingRepository.class); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...end/techpick-api/src/main/java/techpick/api/infrastructure/ranking/RankingRepository.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 techpick.api.infrastructure.ranking; | ||
|
||
import java.time.LocalDate; | ||
import java.util.List; | ||
|
||
import org.springframework.format.annotation.DateTimeFormat; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.service.annotation.GetExchange; | ||
|
||
import techpick.core.dto.LinkInfoWithViewCount; | ||
|
||
public interface RankingRepository { | ||
|
||
/** | ||
* @author minkyeu kim | ||
* 랭킹 서버와 통신하기 위한 Http Interface. <br> | ||
* 형식은 techpick-api 모듈의 컨트롤러와 일치합니다. | ||
*/ | ||
@GetExchange("/ranking/link") | ||
ResponseEntity<List<LinkInfoWithViewCount>> getLinkRanking( | ||
@RequestParam("date_begin") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate dateBegin, | ||
@RequestParam("date_end") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate dateEnd, | ||
@RequestParam(required = false, defaultValue = "5") Integer limit | ||
); | ||
} |
11 changes: 11 additions & 0 deletions
11
backend/techpick-core/src/main/java/techpick/core/dto/LinkInfoWithViewCount.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,11 @@ | ||
package techpick.core.dto; | ||
|
||
/** | ||
* api 서버와 ranking 서버가 통신할 때 쓰이는 DTO | ||
* 양쪽 모듈에서 모두 사용되므로 core에 위치. | ||
*/ | ||
public record LinkInfoWithViewCount( | ||
String url, | ||
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
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