diff --git a/database/product-store-api_create.sql b/database/product-store-api_create.sql
deleted file mode 100644
index 1321ad8..0000000
--- a/database/product-store-api_create.sql
+++ /dev/null
@@ -1,38 +0,0 @@
-CREATE TABLE lot (
- id SERIAL NOT NULL,
- "date" timestamp NOT NULL,
- cost float8 NOT NULL,
- amount float8 NOT NULL,
- product_id int4 NOT NULL,
- PRIMARY KEY (id));
-CREATE TABLE pack (
- id SERIAL NOT NULL,
- "date" timestamp NOT NULL,
- amount float8 NOT NULL,
- lot_id int4 NOT NULL,
- shop_id int4 NOT NULL,
- PRIMARY KEY (id));
-CREATE TABLE product (
- id SERIAL NOT NULL,
- code varchar(255) NOT NULL UNIQUE,
- name varchar(255) NOT NULL,
- measure varchar(10) NOT NULL,
- description varchar(255),
- PRIMARY KEY (id));
-CREATE TABLE sale (
- id SERIAL NOT NULL,
- amount float8 NOT NULL,
- price float8 NOT NULL,
- packid int4 NOT NULL,
- PRIMARY KEY (id));
-CREATE TABLE shop (
- id SERIAL NOT NULL,
- name varchar(255) NOT NULL UNIQUE,
- address varchar(255) NOT NULL,
- descripcion varchar(255),
- PRIMARY KEY (id));
-ALTER TABLE lot ADD CONSTRAINT FKlot646825 FOREIGN KEY (product_id) REFERENCES product (id);
-ALTER TABLE pack ADD CONSTRAINT FKpack415159 FOREIGN KEY (lot_id) REFERENCES lot (id);
-ALTER TABLE sale ADD CONSTRAINT FKsale907373 FOREIGN KEY (packid) REFERENCES pack (id);
-ALTER TABLE pack ADD CONSTRAINT FKpack49864 FOREIGN KEY (shop_id) REFERENCES shop (id);
-
diff --git a/database/product-store-api_drop.sql b/database/product-store-api_drop.sql
deleted file mode 100644
index ed2a4e1..0000000
--- a/database/product-store-api_drop.sql
+++ /dev/null
@@ -1,10 +0,0 @@
-ALTER TABLE lot DROP CONSTRAINT FKlot646825;
-ALTER TABLE pack DROP CONSTRAINT FKpack415159;
-ALTER TABLE sale DROP CONSTRAINT FKsale907373;
-ALTER TABLE pack DROP CONSTRAINT FKpack49864;
-DROP TABLE IF EXISTS lot CASCADE;
-DROP TABLE IF EXISTS pack CASCADE;
-DROP TABLE IF EXISTS product CASCADE;
-DROP TABLE IF EXISTS sale CASCADE;
-DROP TABLE IF EXISTS shop CASCADE;
-
diff --git a/src/main/java/com/i8ai/training/store/api/BalanceController.java b/src/main/java/com/i8ai/training/store/rest/BalanceController.java
similarity index 98%
rename from src/main/java/com/i8ai/training/store/api/BalanceController.java
rename to src/main/java/com/i8ai/training/store/rest/BalanceController.java
index e210e24..7af575f 100644
--- a/src/main/java/com/i8ai/training/store/api/BalanceController.java
+++ b/src/main/java/com/i8ai/training/store/rest/BalanceController.java
@@ -1,4 +1,4 @@
-package com.i8ai.training.store.api;
+package com.i8ai.training.store.rest;
import com.i8ai.training.store.service.BalanceService;
import com.i8ai.training.store.service.data.Balance;
diff --git a/src/main/java/com/i8ai/training/store/api/ExistenceController.java b/src/main/java/com/i8ai/training/store/rest/ExistenceController.java
similarity index 97%
rename from src/main/java/com/i8ai/training/store/api/ExistenceController.java
rename to src/main/java/com/i8ai/training/store/rest/ExistenceController.java
index 67c68a3..feea707 100644
--- a/src/main/java/com/i8ai/training/store/api/ExistenceController.java
+++ b/src/main/java/com/i8ai/training/store/rest/ExistenceController.java
@@ -1,4 +1,4 @@
-package com.i8ai.training.store.api;
+package com.i8ai.training.store.rest;
import com.i8ai.training.store.service.ExistenceService;
import com.i8ai.training.store.service.data.Existence;
diff --git a/src/main/java/com/i8ai/training/store/api/LotController.java b/src/main/java/com/i8ai/training/store/rest/LotController.java
similarity index 96%
rename from src/main/java/com/i8ai/training/store/api/LotController.java
rename to src/main/java/com/i8ai/training/store/rest/LotController.java
index d56ccc0..7b280e3 100644
--- a/src/main/java/com/i8ai/training/store/api/LotController.java
+++ b/src/main/java/com/i8ai/training/store/rest/LotController.java
@@ -1,4 +1,4 @@
-package com.i8ai.training.store.api;
+package com.i8ai.training.store.rest;
import com.i8ai.training.store.model.Lot;
import com.i8ai.training.store.service.LotService;
diff --git a/src/main/java/com/i8ai/training/store/api/PackController.java b/src/main/java/com/i8ai/training/store/rest/PackController.java
similarity index 97%
rename from src/main/java/com/i8ai/training/store/api/PackController.java
rename to src/main/java/com/i8ai/training/store/rest/PackController.java
index d9942e3..97166ee 100644
--- a/src/main/java/com/i8ai/training/store/api/PackController.java
+++ b/src/main/java/com/i8ai/training/store/rest/PackController.java
@@ -1,4 +1,4 @@
-package com.i8ai.training.store.api;
+package com.i8ai.training.store.rest;
import com.i8ai.training.store.model.Pack;
import com.i8ai.training.store.service.PackService;
diff --git a/src/main/java/com/i8ai/training/store/api/ProductController.java b/src/main/java/com/i8ai/training/store/rest/ProductController.java
similarity index 97%
rename from src/main/java/com/i8ai/training/store/api/ProductController.java
rename to src/main/java/com/i8ai/training/store/rest/ProductController.java
index 9d7f101..8b2b701 100644
--- a/src/main/java/com/i8ai/training/store/api/ProductController.java
+++ b/src/main/java/com/i8ai/training/store/rest/ProductController.java
@@ -1,4 +1,4 @@
-package com.i8ai.training.store.api;
+package com.i8ai.training.store.rest;
import com.i8ai.training.store.model.Product;
import com.i8ai.training.store.service.ProductService;
diff --git a/src/main/java/com/i8ai/training/store/api/SaleController.java b/src/main/java/com/i8ai/training/store/rest/SaleController.java
similarity index 96%
rename from src/main/java/com/i8ai/training/store/api/SaleController.java
rename to src/main/java/com/i8ai/training/store/rest/SaleController.java
index ed2f0d7..1e42082 100644
--- a/src/main/java/com/i8ai/training/store/api/SaleController.java
+++ b/src/main/java/com/i8ai/training/store/rest/SaleController.java
@@ -1,4 +1,4 @@
-package com.i8ai.training.store.api;
+package com.i8ai.training.store.rest;
import com.i8ai.training.store.model.Sale;
import com.i8ai.training.store.service.SaleService;
diff --git a/src/main/java/com/i8ai/training/store/api/ShopController.java b/src/main/java/com/i8ai/training/store/rest/ShopController.java
similarity index 97%
rename from src/main/java/com/i8ai/training/store/api/ShopController.java
rename to src/main/java/com/i8ai/training/store/rest/ShopController.java
index 66f8a5b..0a84bc4 100644
--- a/src/main/java/com/i8ai/training/store/api/ShopController.java
+++ b/src/main/java/com/i8ai/training/store/rest/ShopController.java
@@ -1,4 +1,4 @@
-package com.i8ai.training.store.api;
+package com.i8ai.training.store.rest;
import com.i8ai.training.store.model.Shop;
diff --git a/src/main/java/com/i8ai/training/store/util/DateTimeUtils.java b/src/main/java/com/i8ai/training/store/util/DateTimeUtils.java
index 7ac240c..bc93ee5 100644
--- a/src/main/java/com/i8ai/training/store/util/DateTimeUtils.java
+++ b/src/main/java/com/i8ai/training/store/util/DateTimeUtils.java
@@ -1,17 +1,17 @@
package com.i8ai.training.store.util;
+import lombok.experimental.UtilityClass;
+
import java.util.Date;
+@UtilityClass
public class DateTimeUtils {
- private DateTimeUtils() {
- }
-
- public static Date dateOrMin(Date start) {
+ public Date dateOrMin(Date start) {
return start != null ? start : new Date(0);
}
- public static Date dateOrMax(Date end) {
+ public Date dateOrMax(Date end) {
return end != null ? end : new Date();
}
}
diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml
index 39d57c7..ce8aa75 100644
--- a/src/main/resources/application-dev.yml
+++ b/src/main/resources/application-dev.yml
@@ -1,6 +1,6 @@
spring:
datasource:
- url: jdbc:h2:mem:dev;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;AUTO_RECONNECT=TRUE;MODE=PostgreSQL;
+ url: jdbc:h2:./${spring.application.name};MODE=PostgreSQL;
username: sa
password:
diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml
index 2a96540..26422d9 100644
--- a/src/main/resources/application.yml
+++ b/src/main/resources/application.yml
@@ -1,6 +1,11 @@
spring:
- profiles:
- active: prod
+ application:
+ name: product-store-api
liquibase:
- change-log: classpath:/db/changelog/db.changelog-master.yml
+ change-log: classpath:/db/changelog-master.xml
+ user: ${spring.datasource.username}
+ password: ${spring.datasource.password}
+
+ profiles:
+ active: prod
diff --git a/src/main/resources/db/changelog-master.xml b/src/main/resources/db/changelog-master.xml
new file mode 100644
index 0000000..8cda74f
--- /dev/null
+++ b/src/main/resources/db/changelog-master.xml
@@ -0,0 +1,10 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/resources/db/changelog/db.changelog-master.yml b/src/main/resources/db/changelog/db.changelog-master.yml
deleted file mode 100644
index b8f2a94..0000000
--- a/src/main/resources/db/changelog/db.changelog-master.yml
+++ /dev/null
@@ -1,3 +0,0 @@
-databaseChangeLog:
- - include:
- file: db/changelog/init-changelog.sql
\ No newline at end of file
diff --git a/src/main/resources/db/changelog/init-changelog.sql b/src/main/resources/db/changelog/init-changelog.sql
deleted file mode 100644
index 2d70336..0000000
--- a/src/main/resources/db/changelog/init-changelog.sql
+++ /dev/null
@@ -1,58 +0,0 @@
--- liquibase formatted sql
-
--- changeset Isbel:1724434913481-1
-CREATE TABLE product
-(
- id BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL,
- code VARCHAR(255) NOT NULL,
- name VARCHAR(255) NOT NULL,
- measure VARCHAR(255) NOT NULL,
- description VARCHAR(255),
- CONSTRAINT pk_product PRIMARY KEY (id)
-);
-CREATE TABLE shop
-(
- id BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL,
- name VARCHAR(255) NOT NULL,
- address VARCHAR(255) NOT NULL,
- description VARCHAR(255),
- CONSTRAINT pk_shop PRIMARY KEY (id)
-);
-CREATE TABLE lot
-(
- id BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL,
- received TIMESTAMP WITHOUT TIME ZONE NOT NULL,
- amount DOUBLE PRECISION NOT NULL,
- cost DOUBLE PRECISION NOT NULL,
- product_id BIGINT NOT NULL,
- CONSTRAINT pk_lot PRIMARY KEY (id)
-);
-CREATE TABLE pack
-(
- id BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL,
- delivered TIMESTAMP WITHOUT TIME ZONE NOT NULL,
- amount DOUBLE PRECISION NOT NULL,
- lot_id BIGINT NOT NULL,
- shop_id BIGINT NOT NULL,
- CONSTRAINT pk_pack PRIMARY KEY (id)
-);
-CREATE TABLE sale
-(
- id BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL,
- registered TIMESTAMP WITHOUT TIME ZONE NOT NULL,
- amount DOUBLE PRECISION NOT NULL,
- price DOUBLE PRECISION NOT NULL,
- pack_id BIGINT NOT NULL,
- CONSTRAINT pk_sale PRIMARY KEY (id)
-);
-ALTER TABLE product
- ADD CONSTRAINT uc_product_code UNIQUE (code);
-ALTER TABLE lot
- ADD CONSTRAINT FK_LOT_ON_PRODUCT FOREIGN KEY (product_id) REFERENCES product (id);
-ALTER TABLE pack
- ADD CONSTRAINT FK_PACK_ON_LOT FOREIGN KEY (lot_id) REFERENCES lot (id);
-ALTER TABLE pack
- ADD CONSTRAINT FK_PACK_ON_SHOP FOREIGN KEY (shop_id) REFERENCES shop (id);
-ALTER TABLE sale
- ADD CONSTRAINT FK_SALE_ON_PACK FOREIGN KEY (pack_id) REFERENCES pack (id);
-
diff --git a/src/main/resources/db/init-changelog.xml b/src/main/resources/db/init-changelog.xml
new file mode 100644
index 0000000..caeb996
--- /dev/null
+++ b/src/main/resources/db/init-changelog.xml
@@ -0,0 +1,107 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/test/java/com/i8ai/training/store/ApplicationTest.java b/src/test/java/com/i8ai/training/store/ApplicationTest.java
index c94b729..0be829c 100644
--- a/src/test/java/com/i8ai/training/store/ApplicationTest.java
+++ b/src/test/java/com/i8ai/training/store/ApplicationTest.java
@@ -2,10 +2,12 @@
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.ContextConfiguration;
import static org.junit.jupiter.api.Assertions.assertTrue;
@SpringBootTest
+@ContextConfiguration(classes = Application.class)
class ApplicationTest {
@Test
void contextLoads() {
diff --git a/src/test/java/com/i8ai/training/store/api/BalanceControllerTest.java b/src/test/java/com/i8ai/training/store/rest/BalanceControllerTest.java
similarity index 99%
rename from src/test/java/com/i8ai/training/store/api/BalanceControllerTest.java
rename to src/test/java/com/i8ai/training/store/rest/BalanceControllerTest.java
index 55a6c18..2cf77b1 100644
--- a/src/test/java/com/i8ai/training/store/api/BalanceControllerTest.java
+++ b/src/test/java/com/i8ai/training/store/rest/BalanceControllerTest.java
@@ -1,4 +1,4 @@
-package com.i8ai.training.store.api;
+package com.i8ai.training.store.rest;
import com.i8ai.training.store.service.BalanceService;
import com.i8ai.training.store.service.data.Balance;
diff --git a/src/test/java/com/i8ai/training/store/api/ExistenceControllerTest.java b/src/test/java/com/i8ai/training/store/rest/ExistenceControllerTest.java
similarity index 98%
rename from src/test/java/com/i8ai/training/store/api/ExistenceControllerTest.java
rename to src/test/java/com/i8ai/training/store/rest/ExistenceControllerTest.java
index 1391a33..8471fd5 100644
--- a/src/test/java/com/i8ai/training/store/api/ExistenceControllerTest.java
+++ b/src/test/java/com/i8ai/training/store/rest/ExistenceControllerTest.java
@@ -1,4 +1,4 @@
-package com.i8ai.training.store.api;
+package com.i8ai.training.store.rest;
import com.i8ai.training.store.service.ExistenceService;
import com.i8ai.training.store.service.data.Existence;
diff --git a/src/test/java/com/i8ai/training/store/api/LotControllerTest.java b/src/test/java/com/i8ai/training/store/rest/LotControllerTest.java
similarity index 98%
rename from src/test/java/com/i8ai/training/store/api/LotControllerTest.java
rename to src/test/java/com/i8ai/training/store/rest/LotControllerTest.java
index 74248a7..99b6d3b 100644
--- a/src/test/java/com/i8ai/training/store/api/LotControllerTest.java
+++ b/src/test/java/com/i8ai/training/store/rest/LotControllerTest.java
@@ -1,4 +1,4 @@
-package com.i8ai.training.store.api;
+package com.i8ai.training.store.rest;
import com.i8ai.training.store.model.Lot;
import com.i8ai.training.store.service.LotService;
diff --git a/src/test/java/com/i8ai/training/store/api/PackControllerTest.java b/src/test/java/com/i8ai/training/store/rest/PackControllerTest.java
similarity index 98%
rename from src/test/java/com/i8ai/training/store/api/PackControllerTest.java
rename to src/test/java/com/i8ai/training/store/rest/PackControllerTest.java
index eeef19e..f2a0329 100644
--- a/src/test/java/com/i8ai/training/store/api/PackControllerTest.java
+++ b/src/test/java/com/i8ai/training/store/rest/PackControllerTest.java
@@ -1,4 +1,4 @@
-package com.i8ai.training.store.api;
+package com.i8ai.training.store.rest;
import com.i8ai.training.store.model.Pack;
import com.i8ai.training.store.service.PackService;
diff --git a/src/test/java/com/i8ai/training/store/api/ProductControllerTest.java b/src/test/java/com/i8ai/training/store/rest/ProductControllerTest.java
similarity index 98%
rename from src/test/java/com/i8ai/training/store/api/ProductControllerTest.java
rename to src/test/java/com/i8ai/training/store/rest/ProductControllerTest.java
index ad9d899..4ff5ddd 100644
--- a/src/test/java/com/i8ai/training/store/api/ProductControllerTest.java
+++ b/src/test/java/com/i8ai/training/store/rest/ProductControllerTest.java
@@ -1,4 +1,4 @@
-package com.i8ai.training.store.api;
+package com.i8ai.training.store.rest;
import com.i8ai.training.store.model.Product;
import com.i8ai.training.store.service.ProductService;
diff --git a/src/test/java/com/i8ai/training/store/api/SaleControllerTest.java b/src/test/java/com/i8ai/training/store/rest/SaleControllerTest.java
similarity index 98%
rename from src/test/java/com/i8ai/training/store/api/SaleControllerTest.java
rename to src/test/java/com/i8ai/training/store/rest/SaleControllerTest.java
index f3cd149..6f31579 100644
--- a/src/test/java/com/i8ai/training/store/api/SaleControllerTest.java
+++ b/src/test/java/com/i8ai/training/store/rest/SaleControllerTest.java
@@ -1,4 +1,4 @@
-package com.i8ai.training.store.api;
+package com.i8ai.training.store.rest;
import com.i8ai.training.store.model.Sale;
import com.i8ai.training.store.service.SaleService;
diff --git a/src/test/java/com/i8ai/training/store/api/ShopControllerTest.java b/src/test/java/com/i8ai/training/store/rest/ShopControllerTest.java
similarity index 98%
rename from src/test/java/com/i8ai/training/store/api/ShopControllerTest.java
rename to src/test/java/com/i8ai/training/store/rest/ShopControllerTest.java
index ee2ebac..c1ce3a5 100644
--- a/src/test/java/com/i8ai/training/store/api/ShopControllerTest.java
+++ b/src/test/java/com/i8ai/training/store/rest/ShopControllerTest.java
@@ -1,4 +1,4 @@
-package com.i8ai.training.store.api;
+package com.i8ai.training.store.rest;
import com.i8ai.training.store.model.Shop;
import com.i8ai.training.store.service.ShopService;
diff --git a/src/test/resources/application.yml b/src/test/resources/application.yml
index f010e79..3cc1dcd 100644
--- a/src/test/resources/application.yml
+++ b/src/test/resources/application.yml
@@ -1,6 +1,9 @@
spring:
datasource:
- url: jdbc:h2:mem:dev;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;AUTO_RECONNECT=TRUE;MODE=PostgreSQL;
+ url: jdbc:h2:mem:test;MODE=PostgreSQL;
liquibase:
- enabled: false
\ No newline at end of file
+ enabled: false
+
+ profiles:
+ active: test
\ No newline at end of file