Class ProfileService
- java.lang.Object
-
- edu.cnm.deepdive.albuquirky.service.ProfileService
-
- All Implemented Interfaces:
org.springframework.core.convert.converter.Converter<org.springframework.security.oauth2.jwt.Jwt,org.springframework.security.authentication.UsernamePasswordAuthenticationToken>
@Service public class ProfileService extends Object implements org.springframework.core.convert.converter.Converter<org.springframework.security.oauth2.jwt.Jwt,org.springframework.security.authentication.UsernamePasswordAuthenticationToken>
This class handles all of the business logic for getting, putting, posting, and deleting items from theProfileon behalf of theProfileServiceclass, using methods from theProfileRepositoryinterface.
-
-
Constructor Summary
Constructors Constructor Description ProfileService(Random rng, ProfileRepository profileRepository, org.springframework.boot.system.ApplicationHome applicationHome)The constructor initializes a new instance ofRandomand aProfileRepository.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description org.springframework.security.authentication.UsernamePasswordAuthenticationTokenconvert(org.springframework.security.oauth2.jwt.Jwt jwt)Converts the JWT to aUsernamePasswordAuthenticationToken.Optional<Profile>findByAuth(String auth)Retrieves aProfileby their authorization.Optional<Profile>findByUsername(String name)Retrieves aProfileby their username.Optional<Profile>getById(Long id)Retrieves aProfileby their ID.ProfilegetOrCreate(String oauth, String username, String email)Method to get the userProfile, or create it if it does not already exist.org.springframework.core.io.Resourceretrieve(Profile profile)Retrieves the profile picture associated with the given profile.Profilesave(Profile profile)Updates aProfilein the database.ProfileuploadFile(org.springframework.web.multipart.MultipartFile file, Profile profile)Uploads a file to the database.
-
-
-
Constructor Detail
-
ProfileService
@Autowired public ProfileService(Random rng, ProfileRepository profileRepository, org.springframework.boot.system.ApplicationHome applicationHome)
The constructor initializes a new instance ofRandomand aProfileRepository.- Parameters:
rng- A new instance ofRandom.profileRepository- The instance ofProfileRepositoryto be initialized.applicationHome- The AlbuQuirky home directory.
-
-
Method Detail
-
getOrCreate
public Profile getOrCreate(String oauth, String username, String email)
Method to get the userProfile, or create it if it does not already exist.
-
convert
public org.springframework.security.authentication.UsernamePasswordAuthenticationToken convert(org.springframework.security.oauth2.jwt.Jwt jwt)
Converts the JWT to aUsernamePasswordAuthenticationToken.- Specified by:
convertin interfaceorg.springframework.core.convert.converter.Converter<org.springframework.security.oauth2.jwt.Jwt,org.springframework.security.authentication.UsernamePasswordAuthenticationToken>- Parameters:
jwt- The bearer token.- Returns:
- The converted
UsernamePasswordAuthenticationToken.
-
findByUsername
public Optional<Profile> findByUsername(String name)
Retrieves aProfileby their username.
-
findByAuth
public Optional<Profile> findByAuth(String auth)
Retrieves aProfileby their authorization.
-
uploadFile
public Profile uploadFile(org.springframework.web.multipart.MultipartFile file, Profile profile) throws IOException
Uploads a file to the database.- Parameters:
file- The file to be uploaded.profile- TheProfilethe file will be attached to.- Returns:
- The
Profilethat has been updated with the new profile picture. - Throws:
IOException- If the file cannot be accessed from the reference provided.
-
retrieve
public org.springframework.core.io.Resource retrieve(Profile profile) throws IOException
Retrieves the profile picture associated with the given profile.- Parameters:
profile- The userProfile.- Returns:
- A
Resourceof theProfilePicture. - Throws:
IOException- If the file cannot be accessed from the reference provided.
-
-