Skip to content

Commit

Permalink
Merge pull request #118 from woowa-techcamp-2024/refactor/113-서버-분리
Browse files Browse the repository at this point in the history
Refactor/113 서버 분리
  • Loading branch information
huiseung authored Aug 24, 2024
2 parents aeaa806 + f8920df commit d83bfe0
Show file tree
Hide file tree
Showing 103 changed files with 897 additions and 1,437,298 deletions.
3 changes: 3 additions & 0 deletions api-client/cache-client/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dependencies {
implementation project(":api-client:common-client")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package woowa.team4.bff.api.client.cache.caller;

import java.util.List;
import java.util.concurrent.CompletableFuture;
import lombok.RequiredArgsConstructor;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Mono;
import woowa.team4.bff.api.client.cache.config.CacheClientConfiguration;
import woowa.team4.bff.api.client.cache.request.CacheRequest;
import woowa.team4.bff.api.client.cache.response.CacheResponse;
import woowa.tema4.bff.api.client.caller.AsyncClientApiCaller;
import woowa.tema4.bff.api.client.caller.SyncClientApiCaller;
import woowa.tema4.bff.api.client.caller.WebClientCaller;

@Component
@RequiredArgsConstructor
public class CacheApiCaller {

private final CacheClientConfiguration cacheClientConfiguration;
private final SyncClientApiCaller syncClientApiCaller;
private final AsyncClientApiCaller asyncClientApiCaller;
private final WebClientCaller webClientCaller;

public List<CacheResponse> send(CacheRequest cacheRequest) {
return syncClientApiCaller.post(cacheClientConfiguration.getUrl(),
cacheRequest,
new ParameterizedTypeReference<>() {
});
}

public CompletableFuture<List<CacheResponse>> sendAsyncCompletableFuture(
CacheRequest cacheRequest) {
return asyncClientApiCaller.post(cacheClientConfiguration.getUrl(),
cacheRequest,
new ParameterizedTypeReference<>() {
});
}

public Mono<List<CacheResponse>> sendAsyncMono(
CacheRequest cacheRequest) {
return webClientCaller.post(
cacheClientConfiguration.getUrl(),
cacheRequest,
new ParameterizedTypeReference<>() {
}
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package woowa.team4.bff.api.client.cache.config;

import lombok.Getter;
import lombok.Setter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import woowa.tema4.bff.api.client.config.ApiClientConfiguration;

@Getter
@Setter
@Configuration
@Import(ApiClientConfiguration.class)
public class CacheClientConfiguration {

@Value("${external-api.cache-service.endpoints}")
private String endpoints;

public String getUrl() {
return endpoints;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package woowa.team4.bff.api.client.cache.request;

import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;

@ToString
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class CacheRequest {

private List<Long> ids;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package woowa.team4.bff.api.client.cache.response;

import java.util.UUID;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Builder
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class CacheResponse {

private Long restaurantId;
private UUID restaurantUuid;
private String restaurantName;
private String restaurantThumbnailUrl;
private int minimumOrderAmount;
private long reviewCount;
private double rating;
private String menus;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;

Expand All @@ -32,7 +31,7 @@ public <T, R> Mono<R> post(String url, T requestBody,
}

private Mono fallback(Throwable t) {
log.error("error fallback");
log.error("error fallback {}", t.getMessage());
return Mono.empty();
}

Expand Down
3 changes: 3 additions & 0 deletions api-client/search-client/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dependencies {
implementation project(":api-client:common-client")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package woowa.team4.bff.api.client.caller;

import java.util.List;
import java.util.concurrent.CompletableFuture;
import lombok.RequiredArgsConstructor;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Mono;
import woowa.tema4.bff.api.client.caller.AsyncClientApiCaller;
import woowa.tema4.bff.api.client.caller.SyncClientApiCaller;
import woowa.tema4.bff.api.client.caller.WebClientCaller;
import woowa.team4.bff.api.client.config.SearchClientConfiguration;
import woowa.team4.bff.api.client.request.SearchRequest;
import woowa.team4.bff.api.client.response.SearchResponse;

@Component
@RequiredArgsConstructor
public class SearchApiCaller {
private final SearchClientConfiguration searchClientConfiguration;
private final SyncClientApiCaller syncClientApiCaller;
private final AsyncClientApiCaller asyncClientApiCaller;
private final WebClientCaller webClientCaller;

public SearchResponse send(SearchRequest SearchRequest) {
return syncClientApiCaller.post(searchClientConfiguration.getUrl(),
SearchRequest,
new ParameterizedTypeReference<>() {
});
}

public CompletableFuture<List<SearchResponse>> sendAsyncCompletableFuture(
SearchRequest SearchRequest) {
return asyncClientApiCaller.post(searchClientConfiguration.getUrl(),
SearchRequest,
new ParameterizedTypeReference<>() {
});
}

public Mono<List<SearchResponse>> sendAsyncMono(
SearchRequest SearchRequest) {
return webClientCaller.post(
searchClientConfiguration.getUrl(),
SearchRequest,
new ParameterizedTypeReference<>() {
}
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package woowa.team4.bff.api.client.config;

import lombok.Getter;
import lombok.Setter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import woowa.tema4.bff.api.client.config.ApiClientConfiguration;

@Getter
@Setter
@Configuration
@Import(ApiClientConfiguration.class)
public class SearchClientConfiguration {

@Value("${external-api.search-service.endpoints}")
private String endpoints;

public String getUrl() {
return endpoints;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package woowa.team4.bff.api.client.request;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
@AllArgsConstructor
public class SearchRequest {

private String keyword;
private String deliveryLocation;
private Integer pageNumber;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package woowa.team4.bff.api.client.response;

import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@Setter
@NoArgsConstructor
@Builder
@AllArgsConstructor
public class SearchResponse {

List<Long> ids;
}
14 changes: 14 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,30 @@ subprojects {
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'

ext {
set('springCloudVersion', "2023.0.3")
}

dependencies {
// Spring Boot
implementation 'org.springframework.boot:spring-boot-starter'
testImplementation 'org.springframework.boot:spring-boot-starter-test'

// cloud
implementation 'org.springframework.cloud:spring-cloud-starter-circuitbreaker-resilience4j'
implementation 'io.github.resilience4j:resilience4j-reactor'

// Lombok
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
}

dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}

bootJar.enabled = false
jar.enabled = true

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package woowa.team4.bff.cache.redis.service;

import static com.fasterxml.jackson.databind.type.LogicalType.Map;

import com.fasterxml.jackson.core.type.TypeReference;
import lombok.RequiredArgsConstructor;
import org.springframework.data.redis.core.RedisTemplate;
Expand Down Expand Up @@ -34,7 +32,6 @@ public List<Long> findIdsByKeywordAndDeliveryLocation(String keyword, String del
return jsonConverter.convert(json, new TypeReference <List<Long>>() {});
}

// ToDo: Async
@Override
public List<RestaurantSummary> findByRestaurantIds(List<Long> ids) {
return ids.stream()
Expand All @@ -49,6 +46,7 @@ public RestaurantSummary findById(Long id) {
String json = valueOperations.get(restaurantKey);
if (json == null) {
RestaurantSummary restaurantSummary = restaurantReviewStatisticsRepository.findByRestaurantId(id);
// ToDo: Event Publisher
valueOperations.set(restaurantKey, jsonConverter.convert(restaurantSummary));
return restaurantSummary;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;

@ToString
@Getter
@NoArgsConstructor
@Builder
Expand Down
9 changes: 4 additions & 5 deletions domain/exposure-domain/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ dependencies {

// module
implementation project(":core-web")
implementation project(":api-client:cache-client")
implementation project(":api-client:search-client")
implementation project(":api-client:delivery-client")
implementation project(":api-client:coupon-client")
implementation project(":api-client:advertisement-client")
implementation project(":domain:exposure-common-domain")
implementation project(":domain:search-domain-es")
implementation project(":domain:cache-domain-redis")
implementation project(":event:event-publisher")
implementation project(":event:common-event")
implementation project(":event:cache-event")
// implementation project(":domain:search-domain-rdb")
// implementation project(":domain:search-domain-es")
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,35 @@
import woowa.team4.bff.api.client.advertisement.caller.AdvertisementApiCaller;
import woowa.team4.bff.api.client.advertisement.request.AdvertisementRequest;
import woowa.team4.bff.api.client.advertisement.response.AdvertisementResponse;
import woowa.team4.bff.api.client.cache.caller.CacheApiCaller;
import woowa.team4.bff.api.client.cache.request.CacheRequest;
import woowa.team4.bff.api.client.cache.response.CacheResponse;
import woowa.team4.bff.api.client.coupon.caller.CouponApiCaller;
import woowa.team4.bff.api.client.coupon.request.CouponRequest;
import woowa.team4.bff.api.client.coupon.response.CouponResponse;
import woowa.team4.bff.api.client.delivery.caller.DeliveryTimeApiCaller;
import woowa.team4.bff.api.client.delivery.request.DeliveryTimeRequest;
import woowa.team4.bff.api.client.delivery.response.DeliveryTimeResponse;
import woowa.team4.bff.domain.RestaurantSummary;

@Component
@RequiredArgsConstructor
public class AsyncExternalApiCaller {

private final CacheApiCaller cacheApiCaller;
private final DeliveryTimeApiCaller deliveryTimeApiCaller;
private final CouponApiCaller couponApiCaller;
private final AdvertisementApiCaller advertisementApiCaller;

public CompletableFuture<List<CacheResponse>> getCache(List<Long> restaurantIds) {
return cacheApiCaller.sendAsyncCompletableFuture(
new CacheRequest(restaurantIds));
}

public Mono<List<CacheResponse>> getCacheWebFlux(List<Long> restaurantIds) {
return cacheApiCaller.sendAsyncMono(new CacheRequest(restaurantIds));
}

public CompletableFuture<List<DeliveryTimeResponse>> getDeliveryTime(List<Long> restaurantIds) {
return deliveryTimeApiCaller.sendAsyncCompletableFuture(
new DeliveryTimeRequest(restaurantIds));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ public List<CouponResponse> getCoupon(List<Long> restaurantIds) {
public List<AdvertisementResponse> getAdvertisement(List<Long> restaurantIds, String keyword) {
return advertisementApiCaller.send(new AdvertisementRequest(restaurantIds, keyword));
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package woowa.team4.bff.exposure.external.result;

import java.util.UUID;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
Expand All @@ -10,6 +11,15 @@
public class ExternalApiResult {

private long restaurantId;

private UUID restaurantUuid;
private String restaurantName;
private String restaurantThumbnailUrl;
private int minimumOrderAmount;
private long reviewCount;
private double rating;
private String menus;

private int adRank;
private boolean hasAdvertisement;
private boolean hasCoupon;
Expand Down
Loading

0 comments on commit d83bfe0

Please sign in to comment.