Skip to content

Commit

Permalink
Dynamic blog-post filters (tags)
Browse files Browse the repository at this point in the history
  • Loading branch information
gdevxy committed Dec 19, 2024
1 parent b142d47 commit 7c1679f
Show file tree
Hide file tree
Showing 16 changed files with 489 additions and 78 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.gdevxy.blog.client.contentful;

import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;

import com.gdevxy.blog.client.contentful.model.PageBlogModel;
import org.eclipse.microprofile.faulttolerance.Retry;
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;

@RegisterRestClient(configKey = "contentful-cma")
public interface ContentfulCMAClient {

@GET
@Retry(maxRetries = 2)
@Path("/content_types/pageBlogPost")
PageBlogModel findPageBlogModel();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.gdevxy.blog.client.contentful.model;

import java.util.List;
import java.util.Set;

import lombok.Builder;
import lombok.Getter;
import lombok.ToString;
import lombok.extern.jackson.Jacksonized;

@Getter
@Builder
@Jacksonized
@ToString
public class PageBlogModel {

@Builder.Default
private final List<Field> fields = List.of();

@Getter
@Builder
@Jacksonized
@ToString
public static class Field {

private final String id;
private final Items items;

@Getter
@Builder
@Jacksonized
@ToString
public static class Items {

private final List<Validation> validations;

@Getter
@Builder
@Jacksonized
@ToString
public static class Validation {

@Builder.Default
private List<String> in = List.of();

}

}

}

}
6 changes: 5 additions & 1 deletion client/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@ quarkus.rest-client.connect-timeout=1000
quarkus.rest-client.read-timeout=10000

quarkus.rest-client.gravatar.url=https://api.gravatar.com
quarkus.rest-client.gravatar.read-timeout=2000
quarkus.rest-client.gravatar.headers.AUTHORIZATION=Bearer ${GRAVATAR_API_KEY}
quarkus.rest-client.gravatar.read-timeout=2000

quarkus.rest-client.contentful-cma.url=https://api.contentful.com/spaces/r9z7bjp5iedy/environments/master
quarkus.rest-client.contentful-cma.headers.AUTHORIZATION=Bearer ${CONTENTFUL_CMA_TOKEN}
quarkus.rest-client.contentful-cma.read-timeout=2000

# GraphQL
quarkus.smallrye-graphql-client.default.url=https://graphql.contentful.com/content/v1/spaces/r9z7bjp5iedy/environments/master
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.gdevxy.blog.client.contentful;

import static com.github.tomakehurst.wiremock.client.WireMock.*;
import static org.assertj.core.api.Assertions.*;

import java.util.List;

import jakarta.ws.rs.core.HttpHeaders;
import jakarta.ws.rs.core.MediaType;

import com.gdevxy.blog.client.contentful.model.PageBlogModel;
import com.github.tomakehurst.wiremock.client.WireMock;
import io.quarkiverse.wiremock.devservice.ConnectWireMock;
import io.quarkus.test.junit.QuarkusTest;
import org.eclipse.microprofile.rest.client.inject.RestClient;
import org.junit.jupiter.api.Test;

@QuarkusTest
@ConnectWireMock
class ContentfulCMAClientTest {

private WireMock wiremock;

@RestClient
ContentfulCMAClient client;

@Test
void findPageBlogModel() {
// given
wiremock.register(get(urlPathEqualTo("/content_types/pageBlogPost")).withHeader(HttpHeaders.AUTHORIZATION, equalTo("Bearer CMA_TOKEN"))
.willReturn(ok().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).withBodyFile("find-page-blog-model.json")));

// when
var actual = client.findPageBlogModel();

// then
assertThat(actual.getFields()).usingRecursiveFieldByFieldElementComparator()
.contains(PageBlogModel.Field.builder()
.id("tags")
.items(PageBlogModel.Field.Items.builder()
.validations(List.of(PageBlogModel.Field.Items.Validation.builder().in(List.of("About Me", "Agile")).build()))
.build())
.build());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ContentfulClientTest {
private WireMock wiremock;

@Inject
private ContentfulClient client;
ContentfulClient client;

@Test
void findBlogPost() {
Expand Down
Loading

0 comments on commit 7c1679f

Please sign in to comment.