From d84f1bac1c98f08be373f801555ef9f9714aca71 Mon Sep 17 00:00:00 2001 From: harryTheWizzard <hp324245@gmail.com> Date: Tue, 18 Apr 2023 12:43:50 +0200 Subject: [PATCH] added product model and repo --- .../v233/SmartMat/model/product/Product.java | 12 +++++ .../repository/ProductRepository.java | 54 +++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 src/main/java/ntnu/idatt2016/v233/SmartMat/model/product/Product.java create mode 100644 src/main/java/ntnu/idatt2016/v233/SmartMat/repository/ProductRepository.java diff --git a/src/main/java/ntnu/idatt2016/v233/SmartMat/model/product/Product.java b/src/main/java/ntnu/idatt2016/v233/SmartMat/model/product/Product.java new file mode 100644 index 00000000..7de88e53 --- /dev/null +++ b/src/main/java/ntnu/idatt2016/v233/SmartMat/model/product/Product.java @@ -0,0 +1,12 @@ +package ntnu.idatt2016.v233.SmartMat.model.product; + +/** + * Product is a record class representing a product in the system. + * All other info about the product is fetched from api call on fronted. + * this ensures that the product is always up to date. + * @author Birk + * @version 1.0 + * @since 04.04.2023 + */ +public record Product (int ean, String name, String description){ +} diff --git a/src/main/java/ntnu/idatt2016/v233/SmartMat/repository/ProductRepository.java b/src/main/java/ntnu/idatt2016/v233/SmartMat/repository/ProductRepository.java new file mode 100644 index 00000000..0682ee55 --- /dev/null +++ b/src/main/java/ntnu/idatt2016/v233/SmartMat/repository/ProductRepository.java @@ -0,0 +1,54 @@ +package ntnu.idatt2016.v233.SmartMat.repository; + +import ntnu.idatt2016.v233.SmartMat.model.ShoppingList; +import ntnu.idatt2016.v233.SmartMat.model.product.Product; + +import java.util.List; +import java.util.Optional; + +/** + * Repository for Products + * @author Birk + * @version 1.0 + * @since 04.04.2023 + */ +public interface ProductRepository { + /** + * Saves a Product to the database + * + * @param product Product to save + */ + Product save (Product product); + + /** + * Gets a Product by its ID + * + * @param id the ID of the product + * @return an optional containing the product if it exists + */ + Optional<Product> getById(int id); + + /** + * Gets a Product by name + * + * @param id the ID of the group + * @return an optional containing the product if it exists + */ + Optional<Product> getByProductName(int id); + + /** + * Gets all Products + * + * @return an optional containing a list of all products + */ + Optional<List<Product>> getAll(); + + + /** + * Deletes a product by its ID + * + * @param id the ID of the Product + */ + void deleteById(int id); + +} -- GitLab