Class ProductService

java.lang.Object
ntnu.idatt2016.v233.SmartMat.service.product.ProductService

@Service public class ProductService extends Object
Service for Products uses both the ProductRepository and the ProductUtil
Version:
1.1
Author:
Birk
  • Constructor Details

    • ProductService

      public ProductService(ProductRepository productRepository)
      Creates a new ProductService
      Parameters:
      productRepository - The repository to use
  • Method Details

    • getProductById

      public Optional<Product> getProductById(Long id)
      Gets a product by its ID
      Parameters:
      id - The ID of the product to get
      Returns:
      The product with the given ID, if it exists
    • getAllProducts

      public List<Product> getAllProducts()
      Gets all products in the database
      Returns:
      All products in the database
    • saveProduct

      public Product saveProduct(Product product)
      Saves a product to the database
      Parameters:
      product - The product to save
      Returns:
      The saved product
    • deleteProductById

      public void deleteProductById(long id)
      Deletes a product by its ID
      Parameters:
      id - The ID of the product to delete
    • getProductByName

      public Optional<Product> getProductByName(String name)
      Parameters:
      name - The name of the product to get
      Returns:
      The product with the given name, if it exists
    • getProductVolume

      public Optional<List<String>> getProductVolume(long id)
      Gets the volume of a product
      Parameters:
      id - The id of the product to get the volume from
      Returns:
      The volume of the product, if it exists
    • updateProduct

      public void updateProduct(Product product)
      Updates a product
      Parameters:
      product - The product to update