Package restapi.services
Class UserService
java.lang.Object
restapi.services.UserService
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate @NonNull org.springframework.security.crypto.password.PasswordEncoder
private @NonNull PhoneNumberService
private final @NonNull UserRepository
private @NonNull UserSessionService
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionchangeAvatar
(String username, int avatar) Updates user's avatar idchangePassword
(String username, String old, String password) Updates user's password if old matches password on DBeditUserInfo
(String username, String phone) Updates user's phone number on the database if validUpdates user's info on the databaseEncodes passwordgetDtoById
(long id) Get UserDTO of user with id == idgetDtoFromEntity
(@NonNull UserEntity u) Translates UserEntity to UserDTOprivate @Nullable UserDTO
getDtoFromOptional
(@NonNull Optional<UserEntity> user) Translates Optional of UserEntity to UserDTOgetDtoFromUserId
(long id) Get UserDTO of user with id == idgetDtoFromUserId
(String username) Get UserDTO of user with username == usernamelong
getIdByUsername
(String username) Returns id of user with username == usernamegetUser
(long id) Retrieves user from DB with id == idRetrieves user from DB with username == usernamegetUserDtoByPhone
(String phone, String country) Get UserDTO of user with phone == phonegetUsernameById
(long id) Returns username of user with id == idboolean
matchesEncrypted
(String literal, String encrypted) Returns true if literal matches encoded encryptedvoid
Create new user
-
Field Details
-
userRepository
-
passwordEncoder
@NonNull private @NonNull org.springframework.security.crypto.password.PasswordEncoder passwordEncoder -
userSessionService
-
phoneNumberService
-
-
Constructor Details
-
UserService
public UserService()
-
-
Method Details
-
signup
Create new user- Parameters:
username
-password
-phone
-email
-country
-
-
getUser
Retrieves user from DB with id == id- Parameters:
id
-- Returns:
- Throws:
CustomNotFoundException
-
getUser
Retrieves user from DB with username == username- Parameters:
username
-- Returns:
- Throws:
CustomNotFoundException
-
getIdByUsername
Returns id of user with username == username- Parameters:
username
-- Returns:
- Throws:
CustomNotFoundException
-
getUsernameById
Returns username of user with id == id- Parameters:
id
-- Returns:
- Throws:
CustomNotFoundException
-
editUserInfo
public UserEntity editUserInfo(String username, String email, String country, String name, String about) throws CustomNotFoundException, CustomConflictException Updates user's info on the database- Parameters:
username
-email
-country
-name
-about
-- Returns:
- Throws:
CustomNotFoundException
CustomConflictException
-
editUserInfo
public UserEntity editUserInfo(String username, String phone) throws CustomNotFoundException, CustomConflictException Updates user's phone number on the database if valid- Parameters:
username
-phone
-- Returns:
- Throws:
CustomNotFoundException
CustomConflictException
-
changePassword
public UserEntity changePassword(String username, String old, String password) throws CustomNotFoundException, CustomConflictException Updates user's password if old matches password on DB- Parameters:
username
-old
-password
-- Returns:
- Throws:
CustomNotFoundException
CustomConflictException
-
changeAvatar
public UserEntity changeAvatar(String username, int avatar) throws CustomNotFoundException, CustomConflictException Updates user's avatar id- Parameters:
username
-avatar
-- Returns:
- Throws:
CustomNotFoundException
CustomConflictException
-
getDtoFromEntity
Translates UserEntity to UserDTO- Parameters:
u
-- Returns:
-
getDtoFromOptional
Translates Optional of UserEntity to UserDTO- Parameters:
user
-- Returns:
-
getDtoById
Get UserDTO of user with id == id- Parameters:
id
-- Returns:
-
getUserDtoByPhone
Get UserDTO of user with phone == phone- Parameters:
phone
-country
-- Returns:
-
getDtoFromUserId
Get UserDTO of user with username == username- Parameters:
username
-- Returns:
-
getDtoFromUserId
Get UserDTO of user with id == id- Parameters:
id
-- Returns:
- Throws:
CustomNotFoundException
-
encrypt
Encodes password- Parameters:
s
-- Returns:
-
matchesEncrypted
Returns true if literal matches encoded encrypted- Parameters:
literal
-encrypted
-- Returns:
-