Class ProfilePictureService
- java.lang.Object
-
- edu.cnm.deepdive.albuquirky.service.ProfilePictureService
-
@Service public class ProfilePictureService extends Object
This class handles all of the business logic for getting, putting, posting, and deleting items from theProfilePictureon behalf of theProfilePictureServiceclass, using methods from theProfilePictureRepositoryinterface.
-
-
Constructor Summary
Constructors Constructor Description ProfilePictureService(ProfilePictureRepository profilePictureRepository)Creates instances of theProfilePictureRepository.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddelete(ProfilePicture image)Deletes a profile picture from the database.Optional<ProfilePicture>get(long id)Retrieves a profile picture by its ID.Optional<ProfilePicture>get(long id, Profile user)Retrieves a profile picture by its ID and the user.org.springframework.core.io.Resourceretrieve(ProfilePicture image)Retrieves a profile picture from the database.ProfilePicturesave(ProfilePicture image)Updates aProfilePicturein the database.ProfilePicturestore(org.springframework.web.multipart.MultipartFile file, Profile user)Stores a profile picture in the database.
-
-
-
Constructor Detail
-
ProfilePictureService
public ProfilePictureService(ProfilePictureRepository profilePictureRepository)
Creates instances of theProfilePictureRepository.- Parameters:
profilePictureRepository- TheProfilePictureRepositoryto be created.
-
-
Method Detail
-
get
public Optional<ProfilePicture> get(@NonNull long id)
Retrieves a profile picture by its ID.- Parameters:
id- The ID of theProfilePicture.- Returns:
- The matching
ProfilePicture, if one exists.
-
get
public Optional<ProfilePicture> get(@NonNull long id, @NonNull Profile user)
Retrieves a profile picture by its ID and the user.- Parameters:
id- The ID of theProfilePicture.user- TheProfileof the user.- Returns:
-
delete
public void delete(@NonNull ProfilePicture image) throws IOExceptionDeletes a profile picture from the database.- Parameters:
image- TheProfilePictureto be deleted.- Throws:
IOException- If the file cannot be accessed from the reference provided.
-
save
public ProfilePicture save(@NonNull ProfilePicture image)
Updates aProfilePicturein the database.- Parameters:
image- TheProfilePictureto be saved.- Returns:
- The
ProfilePictureobject saved.
-
store
public ProfilePicture store(@NonNull org.springframework.web.multipart.MultipartFile file, @NonNull Profile user) throws IOException, org.springframework.web.HttpMediaTypeException
Stores a profile picture in the database.- Parameters:
file- The actual image of theProfilePicture.user- The userProfile.- Returns:
- The
ProfilePicturethat was stored. - Throws:
IOException- If the file cannot be accessed from the reference provided.org.springframework.web.HttpMediaTypeException- If the file is of an extension other than those appearing on the whitelist.
-
retrieve
public org.springframework.core.io.Resource retrieve(@NonNull ProfilePicture image) throws IOExceptionRetrieves a profile picture from the database.- Parameters:
image- TheProfilePictureto retrieve.- Returns:
- The actual image for the
ProfilePicture. - Throws:
IOException- If the file cannot be accessed from the reference provided.
-
-