aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/docker/Dockerfile.jvm94
-rw-r--r--src/main/docker/Dockerfile.legacy-jar90
-rw-r--r--src/main/docker/Dockerfile.native27
-rw-r--r--src/main/docker/Dockerfile.native-micro30
-rw-r--r--src/main/java/dev/submelon/pantry/CustomControllerAdvice.java46
-rw-r--r--src/main/java/dev/submelon/pantry/ErrorResponse.java58
-rw-r--r--src/main/java/dev/submelon/pantry/PantryApplication.java15
-rw-r--r--src/main/java/dev/submelon/pantry/PantryItem.java40
-rw-r--r--src/main/java/dev/submelon/pantry/PantryItemController.java61
-rw-r--r--src/main/java/dev/submelon/pantry/PantryItemRepository.java11
-rw-r--r--src/main/java/dev/submelon/rest/json/PantryItem.java29
-rw-r--r--src/main/java/dev/submelon/rest/json/PantryItemResource.java59
-rw-r--r--src/main/resources/application.properties9
-rw-r--r--src/main/resources/db/changeLog.xml8
-rw-r--r--src/main/resources/db/changelogs/20220804-add-pantryitem.xml30
15 files changed, 369 insertions, 238 deletions
diff --git a/src/main/docker/Dockerfile.jvm b/src/main/docker/Dockerfile.jvm
new file mode 100644
index 0000000..4e3d6fa
--- /dev/null
+++ b/src/main/docker/Dockerfile.jvm
@@ -0,0 +1,94 @@
+####
+# This Dockerfile is used in order to build a container that runs the Quarkus application in JVM mode
+#
+# Before building the container image run:
+#
+# ./mvnw package
+#
+# Then, build the image with:
+#
+# docker build -f src/main/docker/Dockerfile.jvm -t quarkus/pantry-jvm .
+#
+# Then run the container using:
+#
+# docker run -i --rm -p 8080:8080 quarkus/pantry-jvm
+#
+# If you want to include the debug port into your docker image
+# you will have to expose the debug port (default 5005) like this : EXPOSE 8080 5005
+#
+# Then run the container using :
+#
+# docker run -i --rm -p 8080:8080 quarkus/pantry-jvm
+#
+# This image uses the `run-java.sh` script to run the application.
+# This scripts computes the command line to execute your Java application, and
+# includes memory/GC tuning.
+# You can configure the behavior using the following environment properties:
+# - JAVA_OPTS: JVM options passed to the `java` command (example: "-verbose:class")
+# - JAVA_OPTS_APPEND: User specified Java options to be appended to generated options
+# in JAVA_OPTS (example: "-Dsome.property=foo")
+# - JAVA_MAX_MEM_RATIO: Is used when no `-Xmx` option is given in JAVA_OPTS. This is
+# used to calculate a default maximal heap memory based on a containers restriction.
+# If used in a container without any memory constraints for the container then this
+# option has no effect. If there is a memory constraint then `-Xmx` is set to a ratio
+# of the container available memory as set here. The default is `50` which means 50%
+# of the available memory is used as an upper boundary. You can skip this mechanism by
+# setting this value to `0` in which case no `-Xmx` option is added.
+# - JAVA_INITIAL_MEM_RATIO: Is used when no `-Xms` option is given in JAVA_OPTS. This
+# is used to calculate a default initial heap memory based on the maximum heap memory.
+# If used in a container without any memory constraints for the container then this
+# option has no effect. If there is a memory constraint then `-Xms` is set to a ratio
+# of the `-Xmx` memory as set here. The default is `25` which means 25% of the `-Xmx`
+# is used as the initial heap size. You can skip this mechanism by setting this value
+# to `0` in which case no `-Xms` option is added (example: "25")
+# - JAVA_MAX_INITIAL_MEM: Is used when no `-Xms` option is given in JAVA_OPTS.
+# This is used to calculate the maximum value of the initial heap memory. If used in
+# a container without any memory constraints for the container then this option has
+# no effect. If there is a memory constraint then `-Xms` is limited to the value set
+# here. The default is 4096MB which means the calculated value of `-Xms` never will
+# be greater than 4096MB. The value of this variable is expressed in MB (example: "4096")
+# - JAVA_DIAGNOSTICS: Set this to get some diagnostics information to standard output
+# when things are happening. This option, if set to true, will set
+# `-XX:+UnlockDiagnosticVMOptions`. Disabled by default (example: "true").
+# - JAVA_DEBUG: If set remote debugging will be switched on. Disabled by default (example:
+# true").
+# - JAVA_DEBUG_PORT: Port used for remote debugging. Defaults to 5005 (example: "8787").
+# - CONTAINER_CORE_LIMIT: A calculated core limit as described in
+# https://www.kernel.org/doc/Documentation/scheduler/sched-bwc.txt. (example: "2")
+# - CONTAINER_MAX_MEMORY: Memory limit given to the container (example: "1024").
+# - GC_MIN_HEAP_FREE_RATIO: Minimum percentage of heap free after GC to avoid expansion.
+# (example: "20")
+# - GC_MAX_HEAP_FREE_RATIO: Maximum percentage of heap free after GC to avoid shrinking.
+# (example: "40")
+# - GC_TIME_RATIO: Specifies the ratio of the time spent outside the garbage collection.
+# (example: "4")
+# - GC_ADAPTIVE_SIZE_POLICY_WEIGHT: The weighting given to the current GC time versus
+# previous GC times. (example: "90")
+# - GC_METASPACE_SIZE: The initial metaspace size. (example: "20")
+# - GC_MAX_METASPACE_SIZE: The maximum metaspace size. (example: "100")
+# - GC_CONTAINER_OPTIONS: Specify Java GC to use. The value of this variable should
+# contain the necessary JRE command-line options to specify the required GC, which
+# will override the default of `-XX:+UseParallelGC` (example: -XX:+UseG1GC).
+# - HTTPS_PROXY: The location of the https proxy. (example: "myuser@127.0.0.1:8080")
+# - HTTP_PROXY: The location of the http proxy. (example: "myuser@127.0.0.1:8080")
+# - NO_PROXY: A comma separated lists of hosts, IP addresses or domains that can be
+# accessed directly. (example: "foo.example.com,bar.example.com")
+#
+###
+FROM registry.access.redhat.com/ubi8/openjdk-11:1.11
+
+ENV LANG='en_US.UTF-8' LANGUAGE='en_US:en'
+
+
+# We make four distinct layers so if there are application changes the library layers can be re-used
+COPY --chown=185 target/quarkus-app/lib/ /deployments/lib/
+COPY --chown=185 target/quarkus-app/*.jar /deployments/
+COPY --chown=185 target/quarkus-app/app/ /deployments/app/
+COPY --chown=185 target/quarkus-app/quarkus/ /deployments/quarkus/
+
+EXPOSE 8080
+USER 185
+ENV AB_JOLOKIA_OFF=""
+ENV JAVA_OPTS="-Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager"
+ENV JAVA_APP_JAR="/deployments/quarkus-run.jar"
+
diff --git a/src/main/docker/Dockerfile.legacy-jar b/src/main/docker/Dockerfile.legacy-jar
new file mode 100644
index 0000000..79dbab7
--- /dev/null
+++ b/src/main/docker/Dockerfile.legacy-jar
@@ -0,0 +1,90 @@
+####
+# This Dockerfile is used in order to build a container that runs the Quarkus application in JVM mode
+#
+# Before building the container image run:
+#
+# ./mvnw package -Dquarkus.package.type=legacy-jar
+#
+# Then, build the image with:
+#
+# docker build -f src/main/docker/Dockerfile.legacy-jar -t quarkus/pantry-legacy-jar .
+#
+# Then run the container using:
+#
+# docker run -i --rm -p 8080:8080 quarkus/pantry-legacy-jar
+#
+# If you want to include the debug port into your docker image
+# you will have to expose the debug port (default 5005) like this : EXPOSE 8080 5005
+#
+# Then run the container using :
+#
+# docker run -i --rm -p 8080:8080 quarkus/pantry-legacy-jar
+#
+# This image uses the `run-java.sh` script to run the application.
+# This scripts computes the command line to execute your Java application, and
+# includes memory/GC tuning.
+# You can configure the behavior using the following environment properties:
+# - JAVA_OPTS: JVM options passed to the `java` command (example: "-verbose:class")
+# - JAVA_OPTS_APPEND: User specified Java options to be appended to generated options
+# in JAVA_OPTS (example: "-Dsome.property=foo")
+# - JAVA_MAX_MEM_RATIO: Is used when no `-Xmx` option is given in JAVA_OPTS. This is
+# used to calculate a default maximal heap memory based on a containers restriction.
+# If used in a container without any memory constraints for the container then this
+# option has no effect. If there is a memory constraint then `-Xmx` is set to a ratio
+# of the container available memory as set here. The default is `50` which means 50%
+# of the available memory is used as an upper boundary. You can skip this mechanism by
+# setting this value to `0` in which case no `-Xmx` option is added.
+# - JAVA_INITIAL_MEM_RATIO: Is used when no `-Xms` option is given in JAVA_OPTS. This
+# is used to calculate a default initial heap memory based on the maximum heap memory.
+# If used in a container without any memory constraints for the container then this
+# option has no effect. If there is a memory constraint then `-Xms` is set to a ratio
+# of the `-Xmx` memory as set here. The default is `25` which means 25% of the `-Xmx`
+# is used as the initial heap size. You can skip this mechanism by setting this value
+# to `0` in which case no `-Xms` option is added (example: "25")
+# - JAVA_MAX_INITIAL_MEM: Is used when no `-Xms` option is given in JAVA_OPTS.
+# This is used to calculate the maximum value of the initial heap memory. If used in
+# a container without any memory constraints for the container then this option has
+# no effect. If there is a memory constraint then `-Xms` is limited to the value set
+# here. The default is 4096MB which means the calculated value of `-Xms` never will
+# be greater than 4096MB. The value of this variable is expressed in MB (example: "4096")
+# - JAVA_DIAGNOSTICS: Set this to get some diagnostics information to standard output
+# when things are happening. This option, if set to true, will set
+# `-XX:+UnlockDiagnosticVMOptions`. Disabled by default (example: "true").
+# - JAVA_DEBUG: If set remote debugging will be switched on. Disabled by default (example:
+# true").
+# - JAVA_DEBUG_PORT: Port used for remote debugging. Defaults to 5005 (example: "8787").
+# - CONTAINER_CORE_LIMIT: A calculated core limit as described in
+# https://www.kernel.org/doc/Documentation/scheduler/sched-bwc.txt. (example: "2")
+# - CONTAINER_MAX_MEMORY: Memory limit given to the container (example: "1024").
+# - GC_MIN_HEAP_FREE_RATIO: Minimum percentage of heap free after GC to avoid expansion.
+# (example: "20")
+# - GC_MAX_HEAP_FREE_RATIO: Maximum percentage of heap free after GC to avoid shrinking.
+# (example: "40")
+# - GC_TIME_RATIO: Specifies the ratio of the time spent outside the garbage collection.
+# (example: "4")
+# - GC_ADAPTIVE_SIZE_POLICY_WEIGHT: The weighting given to the current GC time versus
+# previous GC times. (example: "90")
+# - GC_METASPACE_SIZE: The initial metaspace size. (example: "20")
+# - GC_MAX_METASPACE_SIZE: The maximum metaspace size. (example: "100")
+# - GC_CONTAINER_OPTIONS: Specify Java GC to use. The value of this variable should
+# contain the necessary JRE command-line options to specify the required GC, which
+# will override the default of `-XX:+UseParallelGC` (example: -XX:+UseG1GC).
+# - HTTPS_PROXY: The location of the https proxy. (example: "myuser@127.0.0.1:8080")
+# - HTTP_PROXY: The location of the http proxy. (example: "myuser@127.0.0.1:8080")
+# - NO_PROXY: A comma separated lists of hosts, IP addresses or domains that can be
+# accessed directly. (example: "foo.example.com,bar.example.com")
+#
+###
+FROM registry.access.redhat.com/ubi8/openjdk-11:1.11
+
+ENV LANG='en_US.UTF-8' LANGUAGE='en_US:en'
+
+
+COPY target/lib/* /deployments/lib/
+COPY target/*-runner.jar /deployments/quarkus-run.jar
+
+EXPOSE 8080
+USER 185
+ENV AB_JOLOKIA_OFF=""
+ENV JAVA_OPTS="-Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager"
+ENV JAVA_APP_JAR="/deployments/quarkus-run.jar"
diff --git a/src/main/docker/Dockerfile.native b/src/main/docker/Dockerfile.native
new file mode 100644
index 0000000..2f2edca
--- /dev/null
+++ b/src/main/docker/Dockerfile.native
@@ -0,0 +1,27 @@
+####
+# This Dockerfile is used in order to build a container that runs the Quarkus application in native (no JVM) mode.
+#
+# Before building the container image run:
+#
+# ./mvnw package -Pnative
+#
+# Then, build the image with:
+#
+# docker build -f src/main/docker/Dockerfile.native -t quarkus/pantry .
+#
+# Then run the container using:
+#
+# docker run -i --rm -p 8080:8080 quarkus/pantry
+#
+###
+FROM registry.access.redhat.com/ubi8/ubi-minimal:8.5
+WORKDIR /work/
+RUN chown 1001 /work \
+ && chmod "g+rwX" /work \
+ && chown 1001:root /work
+COPY --chown=1001:root target/*-runner /work/application
+
+EXPOSE 8080
+USER 1001
+
+CMD ["./application", "-Dquarkus.http.host=0.0.0.0"]
diff --git a/src/main/docker/Dockerfile.native-micro b/src/main/docker/Dockerfile.native-micro
new file mode 100644
index 0000000..ededc88
--- /dev/null
+++ b/src/main/docker/Dockerfile.native-micro
@@ -0,0 +1,30 @@
+####
+# This Dockerfile is used in order to build a container that runs the Quarkus application in native (no JVM) mode.
+# It uses a micro base image, tuned for Quarkus native executables.
+# It reduces the size of the resulting container image.
+# Check https://quarkus.io/guides/quarkus-runtime-base-image for further information about this image.
+#
+# Before building the container image run:
+#
+# ./mvnw package -Pnative
+#
+# Then, build the image with:
+#
+# docker build -f src/main/docker/Dockerfile.native-micro -t quarkus/pantry .
+#
+# Then run the container using:
+#
+# docker run -i --rm -p 8080:8080 quarkus/pantry
+#
+###
+FROM quay.io/quarkus/quarkus-micro-image:1.0
+WORKDIR /work/
+RUN chown 1001 /work \
+ && chmod "g+rwX" /work \
+ && chown 1001:root /work
+COPY --chown=1001:root target/*-runner /work/application
+
+EXPOSE 8080
+USER 1001
+
+CMD ["./application", "-Dquarkus.http.host=0.0.0.0"]
diff --git a/src/main/java/dev/submelon/pantry/CustomControllerAdvice.java b/src/main/java/dev/submelon/pantry/CustomControllerAdvice.java
deleted file mode 100644
index dad961b..0000000
--- a/src/main/java/dev/submelon/pantry/CustomControllerAdvice.java
+++ /dev/null
@@ -1,46 +0,0 @@
-package dev.submelon.pantry;
-
-import org.springframework.http.HttpStatus;
-import org.springframework.http.ResponseEntity;
-import org.springframework.web.bind.annotation.ControllerAdvice;
-import org.springframework.web.bind.annotation.ExceptionHandler;
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.util.NoSuchElementException;
-
-@ControllerAdvice
-class CustomControllerAdvice {
- @ExceptionHandler(NoSuchElementException.class)
- public ResponseEntity<ErrorResponse> handleNullPointerExceptions(
- NoSuchElementException e
- ) {
- HttpStatus status = HttpStatus.NOT_FOUND;
-
- return new ResponseEntity<>(
- new ErrorResponse(status, e.getMessage()),
- status
- );
- }
-
- @ExceptionHandler(Exception.class)
- public ResponseEntity<ErrorResponse> handleExceptions(
- Exception e
- ) {
- HttpStatus status = HttpStatus.INTERNAL_SERVER_ERROR;
-
- // converting the stack trace to String
- StringWriter stringWriter = new StringWriter();
- PrintWriter printWriter = new PrintWriter(stringWriter);
- e.printStackTrace(printWriter);
- String stackTrace = stringWriter.toString();
-
- return new ResponseEntity<>(
- new ErrorResponse(
- status,
- e.getMessage(),
- stackTrace // specifying the stack trace in case of 500s
- ),
- status
- );
- }
-}
diff --git a/src/main/java/dev/submelon/pantry/ErrorResponse.java b/src/main/java/dev/submelon/pantry/ErrorResponse.java
deleted file mode 100644
index c5b1dbe..0000000
--- a/src/main/java/dev/submelon/pantry/ErrorResponse.java
+++ /dev/null
@@ -1,58 +0,0 @@
-package dev.submelon.pantry;
-
-import com.fasterxml.jackson.annotation.JsonFormat;
-import lombok.Getter;
-import lombok.Setter;
-import org.springframework.http.HttpStatus;
-import java.util.Date;
-
-@Getter
-@Setter
-public class ErrorResponse {
- // customizing timestamp serialization format
- @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd-MM-yyyy hh:mm:ss")
- private Date timestamp;
-
- private int code;
-
- private String status;
-
- private String message;
-
- private String stackTrace;
-
- private Object data;
-
- public ErrorResponse() {
- timestamp = new Date();
- }
-
- public ErrorResponse(HttpStatus httpStatus, String message) {
- this();
-
- this.code = httpStatus.value();
- this.status = httpStatus.name();
- this.message = message;
- }
-
- public ErrorResponse(
- HttpStatus httpStatus,
- String message,
- String stackTrace
- ) {
- this(httpStatus, message);
-
- this.stackTrace = stackTrace;
- }
-
- public ErrorResponse(
- HttpStatus httpStatus,
- String message,
- String stackTrace,
- Object data
- ) {
- this(httpStatus, message, stackTrace);
-
- this.data = data;
- }
-}
diff --git a/src/main/java/dev/submelon/pantry/PantryApplication.java b/src/main/java/dev/submelon/pantry/PantryApplication.java
deleted file mode 100644
index 0c2a5b5..0000000
--- a/src/main/java/dev/submelon/pantry/PantryApplication.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package dev.submelon.pantry;
-
-import org.springframework.boot.SpringApplication;
-import org.springframework.boot.autoconfigure.SpringBootApplication;
-import org.springframework.web.bind.annotation.RestController;
-
-@SpringBootApplication
-@RestController
-public class PantryApplication {
-
- public static void main(String[] args) {
- SpringApplication.run(PantryApplication.class, args);
- }
-
-}
diff --git a/src/main/java/dev/submelon/pantry/PantryItem.java b/src/main/java/dev/submelon/pantry/PantryItem.java
deleted file mode 100644
index 97ab62d..0000000
--- a/src/main/java/dev/submelon/pantry/PantryItem.java
+++ /dev/null
@@ -1,40 +0,0 @@
-package dev.submelon.pantry;
-
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.GeneratedValue;
-import javax.persistence.GenerationType;
-import javax.persistence.Id;
-
-import lombok.Getter;
-import lombok.NoArgsConstructor;
-import lombok.Setter;
-
-@Entity
-@Getter
-@Setter
-@NoArgsConstructor
-public class PantryItem {
- @Id
- @GeneratedValue(strategy=GenerationType.AUTO)
- private Long id;
-
- @Column(nullable=false)
- private String name;
-
- private String description;
-
- @Column(nullable=false)
- private double quantity;
-
- @Column(nullable=false)
- private String quantityUnitType;
-
- public PantryItem(String name, String description, double quantity, String quantityUnitType) {
- this.name = name;
- this.description = description;
- this.quantity = quantity;
- this.quantityUnitType = quantityUnitType;
- }
-
-}
diff --git a/src/main/java/dev/submelon/pantry/PantryItemController.java b/src/main/java/dev/submelon/pantry/PantryItemController.java
deleted file mode 100644
index d5586e5..0000000
--- a/src/main/java/dev/submelon/pantry/PantryItemController.java
+++ /dev/null
@@ -1,61 +0,0 @@
-package dev.submelon.pantry;
-
-import java.util.NoSuchElementException;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.DeleteMapping;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.PutMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.ResponseBody;
-
-@Controller
-@RequestMapping(path="/items")
-public class PantryItemController {
- @Autowired
- private PantryItemRepository itemRepository;
-
- @GetMapping(path="")
- @ResponseBody
- Iterable<PantryItem> getAllItems() {
- return itemRepository.findAll();
- }
-
- @PostMapping(path="")
- @ResponseBody
- PantryItem addNewItem(@RequestBody PantryItem item) {
- return itemRepository.save(item);
- }
-
- @PutMapping(path="/{id}")
- @ResponseBody
- PantryItem addNewItem(@RequestBody PantryItem item, @PathVariable Long id) {
- return itemRepository.findById(id)
- .map(existingItem -> {
- existingItem.setName(item.getName());
- existingItem.setDescription(item.getDescription());
- existingItem.setQuantity(item.getQuantity());
- existingItem.setQuantityUnitType(item.getQuantityUnitType());
- return itemRepository.save(existingItem);
- })
- .orElseGet(() -> {
- return itemRepository.save(item);
- });
- }
-
- @DeleteMapping(path="/{id}")
- @ResponseBody
- PantryItem deletePantryItem(@PathVariable Long id) {
- return itemRepository.findById(id)
- .map(item -> {
- itemRepository.delete(item);
- return item;
- })
- .orElseThrow(NoSuchElementException::new);
- }
-
-}
diff --git a/src/main/java/dev/submelon/pantry/PantryItemRepository.java b/src/main/java/dev/submelon/pantry/PantryItemRepository.java
deleted file mode 100644
index 947ad6b..0000000
--- a/src/main/java/dev/submelon/pantry/PantryItemRepository.java
+++ /dev/null
@@ -1,11 +0,0 @@
-package dev.submelon.pantry;
-
-import java.util.Optional;
-
-import org.springframework.data.repository.CrudRepository;
-
-public interface PantryItemRepository extends CrudRepository<PantryItem, Long> {
-
- Optional<PantryItem> findByName(String name);
-
-}
diff --git a/src/main/java/dev/submelon/rest/json/PantryItem.java b/src/main/java/dev/submelon/rest/json/PantryItem.java
new file mode 100644
index 0000000..d476e3c
--- /dev/null
+++ b/src/main/java/dev/submelon/rest/json/PantryItem.java
@@ -0,0 +1,29 @@
+package dev.submelon.rest.json;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Table;
+
+import io.quarkus.hibernate.orm.panache.PanacheEntity;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+@Entity
+@Table(name = "pantryitem")
+@Data
+@EqualsAndHashCode(callSuper = false)
+public class PantryItem extends PanacheEntity {
+
+ @Column(nullable = false)
+ private String name;
+
+ @Column
+ private String description;
+
+ @Column(nullable = false)
+ private double quantity;
+
+ @Column(nullable = false)
+ private String quantityUnitType;
+
+}
diff --git a/src/main/java/dev/submelon/rest/json/PantryItemResource.java b/src/main/java/dev/submelon/rest/json/PantryItemResource.java
new file mode 100644
index 0000000..4bb51c0
--- /dev/null
+++ b/src/main/java/dev/submelon/rest/json/PantryItemResource.java
@@ -0,0 +1,59 @@
+package dev.submelon.rest.json;
+
+import java.util.List;
+
+import javax.transaction.Transactional;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+@Path("/items")
+public class PantryItemResource {
+
+ @GET
+ @Produces(MediaType.APPLICATION_JSON)
+ public List<PantryItem> getItems() {
+ return PantryItem.findAll().list();
+ }
+
+ @Transactional
+ @POST
+ @Produces(MediaType.APPLICATION_JSON)
+ public PantryItem postItem(PantryItem item) {
+ PantryItem.persist(item);
+
+ return item;
+ }
+
+ @Transactional
+ @PUT
+ @Path("/{id}")
+ @Produces(MediaType.APPLICATION_JSON)
+ public PantryItem putItem(@PathParam("id") Long id, PantryItem item) {
+ if (item.id.equals(id)) {
+ PantryItem.persist(item);
+ } else {
+ throw new WebApplicationException(Response.status(400).entity("ID does not match body").build());
+ }
+
+ return item;
+ }
+
+ @Transactional
+ @DELETE
+ @Path("/{id}")
+ public void deleteItem(@PathParam("id") Long id) {
+ boolean result = PantryItem.deleteById(id);
+
+ if (!result) {
+ throw new WebApplicationException(Response.status(404).entity("Could not find item").build());
+ }
+ }
+}
diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties
index dff3088..bd71024 100644
--- a/src/main/resources/application.properties
+++ b/src/main/resources/application.properties
@@ -1,7 +1,2 @@
-spring.jpa.hibernate.ddl-auto=create-drop
-spring.datasource.url=jdbc:mysql://${MARIADB_HOST:localhost}:3306/pantry-db
-spring.datasource.driver-class-name=org.mariadb.jdbc.Driver
-spring.datasource.username=pantry-user
-spring.datasource.password=i2j9ds0g
-spring.jpa.show-sql=true
-spring.jpa.open-in-view=true
+quarkus.liquibase.clean-at-start=true
+quarkus.liquibase.migrate-at-start=true
diff --git a/src/main/resources/db/changeLog.xml b/src/main/resources/db/changeLog.xml
new file mode 100644
index 0000000..f759350
--- /dev/null
+++ b/src/main/resources/db/changeLog.xml
@@ -0,0 +1,8 @@
+<databaseChangeLog
+ xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
+ xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.6.xsd
+ http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
+ <include file="db/changelogs/20220804-add-pantryitem.xml" />
+</databaseChangeLog> \ No newline at end of file
diff --git a/src/main/resources/db/changelogs/20220804-add-pantryitem.xml b/src/main/resources/db/changelogs/20220804-add-pantryitem.xml
new file mode 100644
index 0000000..d118fa8
--- /dev/null
+++ b/src/main/resources/db/changelogs/20220804-add-pantryitem.xml
@@ -0,0 +1,30 @@
+<databaseChangeLog
+ xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
+ xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.6.xsd
+ http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
+ <changeSet id="20220804-add-pantryitem" author="kjhoerr">
+ <validCheckSum>8:350c0b8d4ff8ce36a2453a0fe2373684</validCheckSum>
+ <createSequence
+ sequenceName="hibernate_sequence"
+ incrementBy="1"
+ startValue="1"
+ />
+ <createTable tableName="pantryitem">
+ <column name="id" type="int8">
+ <constraints primaryKey="true" primaryKeyName="pk_pantryitem_id" nullable="false" />
+ </column>
+ <column name="name" type="varchar(80)">
+ <constraints nullable="false" />
+ </column>
+ <column name="description" type="varchar(1000)" />
+ <column name="quantity" type="float8">
+ <constraints nullable="false" />
+ </column>
+ <column name="quantityunittype" type="varchar(40)">
+ <constraints nullable="false" />
+ </column>
+ </createTable>
+ </changeSet>
+</databaseChangeLog> \ No newline at end of file