From fdf36c0af83db4fa015794e9827ccce0aa8b5a5e Mon Sep 17 00:00:00 2001 From: Kevin J Hoerr Date: Thu, 29 Dec 2022 18:03:41 -0500 Subject: Update; Switch to MongoDB --- .../java/dev/submelon/rest/json/PantryItem.java | 24 +++--- .../dev/submelon/rest/json/PantryItemResource.java | 20 +++-- src/main/resources/application.properties | 5 +- src/main/resources/db/changeLog.xml | 9 --- .../db/changelogs/20220804-add-pantryitem.xml | 30 ------- .../resources/db/changelogs/20220814-test-data.xml | 93 ---------------------- 6 files changed, 26 insertions(+), 155 deletions(-) delete mode 100644 src/main/resources/db/changeLog.xml delete mode 100644 src/main/resources/db/changelogs/20220804-add-pantryitem.xml delete mode 100644 src/main/resources/db/changelogs/20220814-test-data.xml (limited to 'src') diff --git a/src/main/java/dev/submelon/rest/json/PantryItem.java b/src/main/java/dev/submelon/rest/json/PantryItem.java index d476e3c..6a30031 100644 --- a/src/main/java/dev/submelon/rest/json/PantryItem.java +++ b/src/main/java/dev/submelon/rest/json/PantryItem.java @@ -1,29 +1,29 @@ package dev.submelon.rest.json; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.Table; +import java.util.UUID; -import io.quarkus.hibernate.orm.panache.PanacheEntity; +import org.bson.codecs.pojo.annotations.BsonId; + +import io.quarkus.mongodb.panache.PanacheMongoEntityBase; +import io.quarkus.mongodb.panache.common.MongoEntity; import lombok.Data; import lombok.EqualsAndHashCode; -@Entity -@Table(name = "pantryitem") @Data -@EqualsAndHashCode(callSuper = false) -public class PantryItem extends PanacheEntity { +@EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true) +@MongoEntity(collection = "item") +public class PantryItem extends PanacheMongoEntityBase { - @Column(nullable = false) + @BsonId + @EqualsAndHashCode.Include + private UUID id; + 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 index 4bb51c0..75a986d 100644 --- a/src/main/java/dev/submelon/rest/json/PantryItemResource.java +++ b/src/main/java/dev/submelon/rest/json/PantryItemResource.java @@ -1,6 +1,7 @@ package dev.submelon.rest.json; import java.util.List; +import java.util.UUID; import javax.transaction.Transactional; import javax.ws.rs.DELETE; @@ -16,7 +17,7 @@ import javax.ws.rs.core.Response; @Path("/items") public class PantryItemResource { - + @GET @Produces(MediaType.APPLICATION_JSON) public List getItems() { @@ -36,8 +37,9 @@ public class PantryItemResource { @PUT @Path("/{id}") @Produces(MediaType.APPLICATION_JSON) - public PantryItem putItem(@PathParam("id") Long id, PantryItem item) { - if (item.id.equals(id)) { + public PantryItem putItem(@PathParam("id") String id, PantryItem item) { + UUID _id = UUID.fromString(id); + if (item.getId().equals(_id)) { PantryItem.persist(item); } else { throw new WebApplicationException(Response.status(400).entity("ID does not match body").build()); @@ -49,11 +51,13 @@ public class PantryItemResource { @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()); + public Response deleteItem(@PathParam("id") String id) { + UUID _id = UUID.fromString(id); + boolean result = PantryItem.deleteById(_id); + if (result) { + return Response.ok().build(); + } else { + return Response.status(404).entity("Could not find item").build(); } } } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index f36fb33..81f5248 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,3 +1,2 @@ -quarkus.liquibase.clean-at-start=true -quarkus.liquibase.migrate-at-start=true -quarkus.liquibase.contexts=migrate,test +#quarkus.mongodb.connection-string=mongodb://localhost:27017 +quarkus.mongodb.database = pantry diff --git a/src/main/resources/db/changeLog.xml b/src/main/resources/db/changeLog.xml deleted file mode 100644 index 870baf4..0000000 --- a/src/main/resources/db/changeLog.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - \ 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 deleted file mode 100644 index f6ab0ee..0000000 --- a/src/main/resources/db/changelogs/20220804-add-pantryitem.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - 8:350c0b8d4ff8ce36a2453a0fe2373684 - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/main/resources/db/changelogs/20220814-test-data.xml b/src/main/resources/db/changelogs/20220814-test-data.xml deleted file mode 100644 index b8b9ad3..0000000 --- a/src/main/resources/db/changelogs/20220814-test-data.xml +++ /dev/null @@ -1,93 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file -- cgit