From e06ab0f9e796e914529bdd55dbeb6f04846aed02 Mon Sep 17 00:00:00 2001 From: mrfoxygmfr Date: Sun, 23 Mar 2025 14:52:40 +0300 Subject: feat(db/dao): create specifications for JPA --- .../db/dao/specs/OperationSpecs.java | 21 +++++++++++ .../db/dao/specs/PartnerSpecs.java | 21 +++++++++++ .../db/dao/specs/ProductSpecs.java | 41 ++++++++++++++++++++++ .../db/dao/specs/StorageSlotSpecs.java | 37 +++++++++++++++++++ 4 files changed, 120 insertions(+) create mode 100644 src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/dao/specs/OperationSpecs.java create mode 100644 src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/dao/specs/PartnerSpecs.java create mode 100644 src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/dao/specs/ProductSpecs.java create mode 100644 src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/dao/specs/StorageSlotSpecs.java diff --git a/src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/dao/specs/OperationSpecs.java b/src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/dao/specs/OperationSpecs.java new file mode 100644 index 0000000..34b9ac5 --- /dev/null +++ b/src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/dao/specs/OperationSpecs.java @@ -0,0 +1,21 @@ +package ru.mrfoxygmfr.warehouse_accounting.db.dao.specs; + +import org.springframework.data.jpa.domain.Specification; +import ru.mrfoxygmfr.warehouse_accounting.db.models.*; + +public class OperationSpecs { + public static Specification operationTypeEqual(OperationType operationType) { + return (root, _, builder) + -> builder.equal(root.get(Operation_.type), operationType); + } + + public static Specification operationStatusEqual(OperationStatus operationStatus) { + return (root, _, builder) + -> builder.equal(root.get(Operation_.status), operationStatus); + } + + public static Specification operationPartnerNameLike(String partnerName) { + return (root, _, builder) + -> builder.equal(root.get(Operation_.partner).get(Partner_.name), partnerName); + } +} diff --git a/src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/dao/specs/PartnerSpecs.java b/src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/dao/specs/PartnerSpecs.java new file mode 100644 index 0000000..c8d4c09 --- /dev/null +++ b/src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/dao/specs/PartnerSpecs.java @@ -0,0 +1,21 @@ +package ru.mrfoxygmfr.warehouse_accounting.db.dao.specs; + +import org.springframework.data.jpa.domain.Specification; +import ru.mrfoxygmfr.warehouse_accounting.db.models.*; + +public class PartnerSpecs { + public static Specification partnerNameLike(String nameFilter) { + return (root, _, builder) + -> builder.like(root.get(Partner_.name), "%" +nameFilter + "%"); + } + + public static Specification partnerTaxNumberLike(String taxNumberFilter) { + return (root, _, builder) + -> builder.like(root.get(Partner_.taxNumber), "%" + taxNumberFilter + "%"); + } + + public static Specification partnerTypeEqual(PartnerType typeFilter) { + return (root, _, builder) + -> builder.equal(root.get(Partner_.type), typeFilter); + } +} diff --git a/src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/dao/specs/ProductSpecs.java b/src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/dao/specs/ProductSpecs.java new file mode 100644 index 0000000..ba37f6a --- /dev/null +++ b/src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/dao/specs/ProductSpecs.java @@ -0,0 +1,41 @@ +package ru.mrfoxygmfr.warehouse_accounting.db.dao.specs; + +import org.springframework.data.jpa.domain.Specification; +import ru.mrfoxygmfr.warehouse_accounting.db.models.*; + +public class ProductSpecs { + public static Specification productNameLike(String nameFilter) { + return (root, _, builder) + -> builder.like(root.get(Product_.name), "%" + nameFilter + "%"); + } + + public static Specification productHeightLess(long maxHeight) { + return (root, _, builder) + -> builder.lessThanOrEqualTo(root.get(Product_.height), maxHeight); + } + + public static Specification productHeightGreater(long minHeight) { + return (root, _, builder) + -> builder.greaterThanOrEqualTo(root.get(Product_.height), minHeight); + } + + public static Specification productWidthLess(long maxWidth) { + return (root, _, builder) + -> builder.lessThanOrEqualTo(root.get(Product_.width), maxWidth); + } + + public static Specification productWidthGreater(long minWidth) { + return (root, _, builder) + -> builder.greaterThanOrEqualTo(root.get(Product_.width), minWidth); + } + + public static Specification productDepthLess(long maxDepth) { + return (root, _, builder) + -> builder.lessThanOrEqualTo(root.get(Product_.depth), maxDepth); + } + + public static Specification productDepthGreater(long minDepth) { + return (root, _, builder) + -> builder.greaterThanOrEqualTo(root.get(Product_.depth), minDepth); + } +} \ No newline at end of file diff --git a/src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/dao/specs/StorageSlotSpecs.java b/src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/dao/specs/StorageSlotSpecs.java new file mode 100644 index 0000000..2dbd2cf --- /dev/null +++ b/src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/dao/specs/StorageSlotSpecs.java @@ -0,0 +1,37 @@ +package ru.mrfoxygmfr.warehouse_accounting.db.dao.specs; + +import org.springframework.data.jpa.domain.Specification; +import ru.mrfoxygmfr.warehouse_accounting.db.models.*; + +public class StorageSlotSpecs { + + public static Specification storageSlotHeightLess(long maxHeight) { + return (root, _, builder) + -> builder.lessThanOrEqualTo(root.get(StorageSlot_.height), maxHeight); + } + + public static Specification storageSlotHeightGreater(long minHeight) { + return (root, _, builder) + -> builder.greaterThanOrEqualTo(root.get(StorageSlot_.height), minHeight); + } + + public static Specification storageSlotWidthLess(long maxWidth) { + return (root, _, builder) + -> builder.lessThanOrEqualTo(root.get(StorageSlot_.width), maxWidth); + } + + public static Specification storageSlotWidthGreater(long minWidth) { + return (root, _, builder) + -> builder.greaterThanOrEqualTo(root.get(StorageSlot_.width), minWidth); + } + + public static Specification storageSlotDepthLess(long maxDepth) { + return (root, _, builder) + -> builder.lessThanOrEqualTo(root.get(StorageSlot_.depth), maxDepth); + } + + public static Specification storageSlotDepthGreater(long minDepth) { + return (root, _, builder) + -> builder.greaterThanOrEqualTo(root.get(StorageSlot_.depth), minDepth); + } +} -- cgit mrf-deployment