Package idatt2106.group3.backend.Service
Class UserService
- java.lang.Object
-
- idatt2106.group3.backend.Service.UserService
-
@Service public class UserService extends java.lang.Object
-
-
Constructor Summary
Constructors Constructor Description UserService()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Activity
addUserToActivity(long userId, long activityId)
Adds a user to an activity.UserRegistrationCallbackDTO
createUser(UserWithPasswordDTO user)
Creates User object from an UserWithPasswordDTO and stores it in databaseboolean
deleteUser(long userId)
Deletes a user from the database, and checks if it exists afterboolean
doesEmailAlreadyExist(java.lang.String email)
Checks if the email already exists in the databaseUserDTO
editUser(long userId, UserEditDTO userDTO)
Edits a stored User object with userDTO fieldsjava.util.List<Activity>
findFutureActivities(long userId)
Finds future activities that the user has signed up tojava.util.List<Activity>
findOrganizedActivities(long userId)
Finds all acitivites that a user is an organizer ofUserDTO
getUser(long userId)
Finds user in Database, and creates a DTO object from itjava.util.Set<Activity>
getUserActivities(long userId)
Gets all activities where the user has signed upboolean
isOldPasswordCorrect(java.lang.String oldPassword, long userId)
Finds user from id and and compares user's hashed password with input password(oldPassword)boolean
removeUserFromActivity(long userId, long activityId)
Removes a user from an activity.
-
-
-
Method Detail
-
getUser
public UserDTO getUser(long userId)
Finds user in Database, and creates a DTO object from it- Parameters:
userId
-- Returns:
- DTO object from User
-
createUser
public UserRegistrationCallbackDTO createUser(UserWithPasswordDTO user)
Creates User object from an UserWithPasswordDTO and stores it in database- Parameters:
user
-- Returns:
- UserDTO object with a JWT token
-
editUser
public UserDTO editUser(long userId, UserEditDTO userDTO)
Edits a stored User object with userDTO fields- Parameters:
userId
-userDTO
- input object- Returns:
- UserDTO object
-
deleteUser
public boolean deleteUser(long userId)
Deletes a user from the database, and checks if it exists after- Parameters:
userId
-- Returns:
- if it exists or not
-
getUserActivities
public java.util.Set<Activity> getUserActivities(long userId)
Gets all activities where the user has signed up- Parameters:
userId
-- Returns:
- List of activities
-
removeUserFromActivity
public boolean removeUserFromActivity(long userId, long activityId)
Removes a user from an activity. Returns true if successful, else false- Parameters:
userId
-activityId
-- Returns:
-
addUserToActivity
public Activity addUserToActivity(long userId, long activityId)
Adds a user to an activity. Returns true if successful, else false- Parameters:
userId
-activityId
-- Returns:
-
doesEmailAlreadyExist
public boolean doesEmailAlreadyExist(java.lang.String email)
Checks if the email already exists in the database- Parameters:
email
-- Returns:
-
isOldPasswordCorrect
public boolean isOldPasswordCorrect(java.lang.String oldPassword, long userId)
Finds user from id and and compares user's hashed password with input password(oldPassword)- Parameters:
oldPassword
-userId
-- Returns:
- if passwords are equal
-
findFutureActivities
public java.util.List<Activity> findFutureActivities(long userId)
Finds future activities that the user has signed up to- Parameters:
userId
-- Returns:
- List of activities
-
findOrganizedActivities
public java.util.List<Activity> findOrganizedActivities(long userId)
Finds all acitivites that a user is an organizer of- Parameters:
userId
-- Returns:
- List of activities
-
-