Class ImageService


  • @Service
    public class ImageService
    extends Object
    This class handles all of the business logic for getting, putting, posting, and deleting items from the Image on behalf of the ImageService class, using methods from the ImageRepository interface.
    • Constructor Detail

      • ImageService

        @Autowired
        public ImageService​(ImageRepository imageRepository)
        Creates instances of the ImageRepository.
        Parameters:
        imageRepository - The ImageRepository to be created.
    • Method Detail

      • save

        public Image save​(Image image)
        Method to save images pertaining to the user profile or product listing.
        Parameters:
        image - The Image to be saved.
        Returns:
        The Image that was saved.
      • remove

        public Image remove​(Image image,
                            Profile profile)
        This will remove an image if needed by the user it pertains to. It will also throw an exception if someone without access attempts to remove the photo.
        Parameters:
        image - The Image object to be deleted.
        profile - The Profile connected to the Image.
        Returns:
        The Image object that was deleted.
      • get

        public Optional<Image> get​(long id)
        Method to get a specific image.
        Parameters:
        id - The ID of the Image being requested.
        Returns:
        The matching Image.
      • getAllByProduct

        public List<Image> getAllByProduct​(Product product)
        Method to get images tied to a specific product.
        Parameters:
        product - The Product linked to the images requested.
        Returns:
        A List of Image objects associated with the Product.