Skip to content

Commit

Permalink
remove unecessary specific Router because @observe Router router alre…
Browse files Browse the repository at this point in the history
…ady do the magic

remove @ApplicationScope not need this class as a bean and remove @Inject over a resource(bean) not needed either

convert shoppingList as static field and improve the get method to avoid lazily initialization
  • Loading branch information
jcarranzan committed Nov 15, 2023
1 parent 857fa21 commit 017a5d5
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
@Produces(MediaType.APPLICATION_JSON)
public class ShopResource {

private List<ShoppingList> shoppingList;
private static List<ShoppingList> shoppingList = createSampleProductList();

private List<ShoppingList> createSampleProductList() {
private static List<ShoppingList> createSampleProductList() {
shoppingList = new ArrayList<>();
shoppingList.add(new ShoppingList(UUID.randomUUID(), "ListName1", 25,
new ArrayList<>(Arrays.asList("Carrots", "Water", "Cheese", "Beer"))));
Expand All @@ -27,9 +27,6 @@ private List<ShoppingList> createSampleProductList() {

@GET
public List<ShoppingList> get() {
if (shoppingList == null) {
createSampleProductList();
}
return shoppingList;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import java.util.stream.Collectors;

import jakarta.annotation.PostConstruct;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.event.Observes;
import jakarta.inject.Inject;
import jakarta.ws.rs.core.HttpHeaders;
Expand All @@ -23,7 +22,6 @@
import io.vertx.core.json.Json;
import io.vertx.core.json.JsonArray;
import io.vertx.ext.web.Router;
import io.vertx.ext.web.handler.BodyHandler;
import io.vertx.ext.web.validation.BadRequestException;
import io.vertx.ext.web.validation.BodyProcessorException;
import io.vertx.ext.web.validation.ParameterProcessorException;
Expand All @@ -39,7 +37,6 @@
import io.vertx.json.schema.SchemaRouterOptions;
import io.vertx.json.schema.common.dsl.ObjectSchemaBuilder;

@ApplicationScoped
public class ValidationHandlerOnRoutes {
//TODO when Quarkus use vert.x version 4.4.6 we can use SchemaRepository instead of SchemaParser with SchemaRouter
//private SchemaRepository schemaRepository =SchemaRepository.create(new JsonSchemaOptions().setDraft(Draft.DRAFT7).setBaseUri(BASEURI));
Expand All @@ -49,20 +46,14 @@ public class ValidationHandlerOnRoutes {
@Inject
Vertx vertx;

private Router router;

@Inject
ShopResource shopResource;
private static ShopResource shopResource = new ShopResource();

private static final String ERROR_MESSAGE = "{\"error\": \"%s\"}";
private static final String SHOPPINGLIST_NOT_FOUND = "Shopping list not found in the list or does not exist with that name or price";

@PostConstruct
void initialize() {
router = Router.router(vertx);
router.route().handler(BodyHandler.create());
schemaParser = createSchema();
validateHandlerSoppingList(router);
}

private SchemaParser createSchema() {
Expand Down

0 comments on commit 017a5d5

Please sign in to comment.