Skip to content

Commit

Permalink
Merge pull request #14 from CJSCommonPlatform/dev/TP-1102-update-cake…
Browse files Browse the repository at this point in the history
…shop-to-utilise-pojo-compatible-requester-and-sender-methods

Update cakeshop query api and view  with pojo examples
  • Loading branch information
BenNzewi committed Mar 4, 2019
2 parents ef54f22 + 847751f commit 9960c6b
Show file tree
Hide file tree
Showing 18 changed files with 300 additions and 32 deletions.
8 changes: 1 addition & 7 deletions example-context/example-persistence/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
</dependency>
<dependency>
<groupId>uk.gov.justice.services</groupId>
<artifactId>test-utils-core</artifactId>
<artifactId>test-utils-common</artifactId>
<version>${framework.version}</version>
<scope>test</scope>
</dependency>
Expand All @@ -77,12 +77,6 @@
<version>${json-schema-catalog.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>uk.gov.justice.services</groupId>
<artifactId>core</artifactId>
<version>${framework.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@
<type>pom</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>uk.gov.justice.services.example</groupId>
<artifactId>example-persistence</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import uk.gov.justice.services.core.annotation.Handles;
import uk.gov.justice.services.core.annotation.ServiceComponent;
import uk.gov.justice.services.core.requester.Requester;
import uk.gov.justice.services.messaging.JsonEnvelope;
import uk.gov.justice.services.example.cakeshop.query.api.request.SearchCakeOrder;
import uk.gov.justice.services.example.cakeshop.query.api.response.CakeOrderView;
import uk.gov.justice.services.messaging.Envelope;

import javax.inject.Inject;

Expand All @@ -17,7 +19,7 @@ public class CakeOrdersQueryApi {
Requester requester;

@Handles("example.get-order")
public JsonEnvelope getOrder(final JsonEnvelope query) {
return requester.request(query);
public Envelope<CakeOrderView> getOrder(final Envelope<SearchCakeOrder> query) {
return requester.request(query, CakeOrderView.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import uk.gov.justice.services.core.annotation.Handles;
import uk.gov.justice.services.core.annotation.ServiceComponent;
import uk.gov.justice.services.core.requester.Requester;
import uk.gov.justice.services.messaging.JsonEnvelope;
import uk.gov.justice.services.example.cakeshop.query.api.response.CakesView;
import uk.gov.justice.services.example.cakeshop.query.api.request.SearchCake;
import uk.gov.justice.services.messaging.Envelope;

import javax.inject.Inject;

Expand All @@ -16,8 +18,8 @@ public class CakesQueryApi {
Requester requester;

@Handles("example.search-cakes")
public JsonEnvelope cakes(final JsonEnvelope query) {
return requester.request(query);
public Envelope<CakesView> cakes(final Envelope<SearchCake> query) {
return requester.request(query, CakesView.class);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import uk.gov.justice.services.core.annotation.Handles;
import uk.gov.justice.services.core.annotation.ServiceComponent;
import uk.gov.justice.services.core.requester.Requester;
import uk.gov.justice.services.example.cakeshop.query.api.request.SearchRecipes;
import uk.gov.justice.services.example.cakeshop.query.api.response.RecipesView;
import uk.gov.justice.services.messaging.Envelope;
import uk.gov.justice.services.messaging.JsonEnvelope;

import javax.inject.Inject;
Expand All @@ -26,8 +29,8 @@ public JsonEnvelope getRecipe(final JsonEnvelope query) {
}

@Handles("example.query-recipes")
public JsonEnvelope queryRecipes(final JsonEnvelope query) {
return requester.request(query);
public Envelope<RecipesView> queryRecipes(final Envelope<SearchRecipes> query) {
return requester.request(query, RecipesView.class);
}

@Handles("example.get-recipe-photograph")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package uk.gov.justice.services.example.cakeshop.query.api.request;

import java.util.UUID;

public class SearchCake {

private final UUID id;
private final String name;

public SearchCake(final UUID id, final String name) {
this.id = id;
this.name = name;
}

public UUID getId() {
return id;
}

public String getName() {
return name;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package uk.gov.justice.services.example.cakeshop.query.api.request;

import java.time.ZonedDateTime;
import java.util.UUID;

public class SearchCakeOrder {
private UUID orderId;

private UUID recipeId;

private ZonedDateTime deliveryDate;


public SearchCakeOrder(final UUID orderId, final UUID recipeId, final ZonedDateTime deliveryDate) {
this.orderId = orderId;
this.recipeId = recipeId;
this.deliveryDate = deliveryDate;
}

public UUID getOrderId() {
return orderId;
}

public UUID getRecipeId() {
return recipeId;
}

public ZonedDateTime getDeliveryDate() {
return deliveryDate;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package uk.gov.justice.services.example.cakeshop.query.api.request;

public class SearchRecipes {

private int pagesize;
private String name;
private boolean glutenFree;

public SearchRecipes(final int pagesize) {
this.pagesize = pagesize;
}

public int getPagesize() {
return pagesize;
}

public void setPagesize(final int pagesize) {
this.pagesize = pagesize;
}

public String getName() {
return name;
}

public void setName(final String name) {
this.name = name;
}

public boolean isGlutenFree() {
return glutenFree;
}

public void setGlutenFree(final boolean glutenFree) {
this.glutenFree = glutenFree;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package uk.gov.justice.services.example.cakeshop.query.api.response;

import java.time.ZonedDateTime;
import java.util.UUID;

public class CakeOrderView {
private UUID orderId;

private UUID recipeId;

private ZonedDateTime deliveryDate;


public CakeOrderView(final UUID orderId, final UUID recipeId, final ZonedDateTime deliveryDate) {
this.orderId = orderId;
this.recipeId = recipeId;
this.deliveryDate = deliveryDate;
}

public UUID getOrderId() {
return orderId;
}

public UUID getRecipeId() {
return recipeId;
}

public ZonedDateTime getDeliveryDate() {
return deliveryDate;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package uk.gov.justice.services.example.cakeshop.query.api.response;

import uk.gov.justice.services.example.cakeshop.query.api.request.SearchCake;

import java.util.List;

public class CakesView {

private final List<SearchCake> cakes;

public CakesView(final List<SearchCake> cakes) {
this.cakes = cakes;
}

public List<SearchCake> getCakes() {
return cakes;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package uk.gov.justice.services.example.cakeshop.query.api.response;

import uk.gov.justice.services.example.cakeshop.persistence.entity.Recipe;

import java.util.Objects;
import java.util.UUID;

/**
* View representation of an {@link Recipe}.
*/
public class RecipeView {

private final UUID id;
private final String name;
private final boolean glutenFree;

public RecipeView(final UUID id, final String name, final boolean glutenFree) {
this.id = id;
this.name = name;
this.glutenFree = glutenFree;
}

public RecipeView(final Recipe recipe) {
this.id = recipe.getId();
this.name = recipe.getName();
this.glutenFree = recipe.isGlutenFree();
}

public UUID getId() {
return id;
}

public String getName() {
return name;
}

public boolean isGlutenFree() {
return glutenFree;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
RecipeView that = (RecipeView) o;
return Objects.equals(getId(), that.getId()) &&
Objects.equals(getName(), that.getName()) &&
isGlutenFree() == that.isGlutenFree();
}

@Override
public int hashCode() {
return Objects.hash(getId(), getName());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package uk.gov.justice.services.example.cakeshop.query.api.response;

import uk.gov.justice.services.example.cakeshop.persistence.entity.Recipe;

import java.util.List;
import java.util.Objects;

/**
* View representation of a list of {@link Recipe}'s.
*/
public class RecipesView {

private final List<RecipeView> recipes;

public RecipesView(final List<RecipeView> recipes) {
this.recipes = recipes;
}

public List<RecipeView> getRecipes() {
return recipes;
}

@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
final RecipesView that = (RecipesView) o;
return Objects.equals(recipes, that.getRecipes());
}

@Override
public int hashCode() {
return Objects.hash(recipes);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
import uk.gov.justice.services.core.annotation.Component;
import uk.gov.justice.services.core.annotation.Handles;
import uk.gov.justice.services.core.annotation.ServiceComponent;
import uk.gov.justice.services.example.cakeshop.query.view.request.SearchCakeOrder;
import uk.gov.justice.services.example.cakeshop.query.view.response.CakeOrderView;
import uk.gov.justice.services.example.cakeshop.query.view.service.CakeOrderService;
import uk.gov.justice.services.messaging.Envelope;
import uk.gov.justice.services.messaging.JsonEnvelope;

import javax.inject.Inject;

Expand All @@ -19,8 +19,8 @@ public class CakeOrdersQueryView {
CakeOrderService service;

@Handles("example.get-order")
public Envelope<CakeOrderView> findOrder(final JsonEnvelope query) {
final String orderId = query.payloadAsJsonObject().getString("orderId");
public Envelope<CakeOrderView> findOrder(final Envelope<SearchCakeOrder> query) {
final String orderId = query.payload().getOrderId().toString();

return envelop(service.findOrder(orderId))
.withName("example.get-order")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package uk.gov.justice.services.example.cakeshop.query.view.request;

import java.time.ZonedDateTime;
import java.util.UUID;

public class SearchCakeOrder {
private UUID orderId;

private UUID recipeId;

private ZonedDateTime deliveryDate;


public SearchCakeOrder(final UUID orderId, final UUID recipeId, final ZonedDateTime deliveryDate) {
this.orderId = orderId;
this.recipeId = recipeId;
this.deliveryDate = deliveryDate;
}

public UUID getOrderId() {
return orderId;
}

public UUID getRecipeId() {
return recipeId;
}

public ZonedDateTime getDeliveryDate() {
return deliveryDate;
}
}
Loading

0 comments on commit 9960c6b

Please sign in to comment.