Package idatt2106.group3.backend.Service
Class ActivityService
- java.lang.Object
-
- idatt2106.group3.backend.Service.ActivityService
-
@Service public class ActivityService extends java.lang.Object
-
-
Constructor Summary
Constructors Constructor Description ActivityService()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
addUserToActivity(long activityId, long userId)
Adds a user to an activity, user becomes a participant Checks if both are stored in databaseboolean
checkIfOrganizerOfActivity(long activityId, long userId)
Checks if a user is the organizer of the activityboolean
checkIfParticipant(long activityId, long userId)
Checks if the user is a participant of an existing activity based on activityIdActivityDTO
createActivity(ActivityRegistrationDTO activity)
Finds the user who created the activity, and sets it as the organizer Saves the Activity object in the databaseboolean
deleteActivity(long activityId)
Finds activity based on id, removes it, sends cancellation emails to all participants, and deletes the activity from the databaseActivityDTO
editActivity(long activityId, ActivityRegistrationDTO activityRegDTO)
Finds the activity based on id and changes all given fields based on given activityRegistrationDTOjava.util.List<ActivityDTO>
getActivities()
Returns all activities stored in the databasejava.util.List<ActivityDTO>
getActivitiesWithFilterAndSorting(SortFilterQueryDTO filter)
Returns a sorted or filtered list based on filters defined by the userActivityDTO
getActivity(long activityId)
Returns activity based on activityId stored in the databaseChat
getChat(long activityId)
Returns activity's Chat objectjava.util.Set<UserNameDTO>
getUsers(long activityId)
Returns names of all participants of an existing activity based on activityIdjava.util.Set<java.lang.Long>
markAbsent(long activityId, AbsenceDTO absenceDTO)
Method that increases "absence" counter for users that were absent in an activity.
-
-
-
Method Detail
-
getActivity
public ActivityDTO getActivity(long activityId)
Returns activity based on activityId stored in the database- Parameters:
activityId
-- Returns:
- ActivityDTO object
-
getActivities
public java.util.List<ActivityDTO> getActivities()
Returns all activities stored in the database- Returns:
- List of activities
-
getActivitiesWithFilterAndSorting
public java.util.List<ActivityDTO> getActivitiesWithFilterAndSorting(SortFilterQueryDTO filter)
Returns a sorted or filtered list based on filters defined by the user- Parameters:
filter
-- Returns:
- List of ActivityDTO objects
-
createActivity
public ActivityDTO createActivity(ActivityRegistrationDTO activity)
Finds the user who created the activity, and sets it as the organizer Saves the Activity object in the database- Parameters:
activity
-- Returns:
- ActivityDTO object
-
editActivity
public ActivityDTO editActivity(long activityId, ActivityRegistrationDTO activityRegDTO)
Finds the activity based on id and changes all given fields based on given activityRegistrationDTO- Parameters:
activityId
-activityRegDTO
- input DTO object- Returns:
- ActivityDTO
-
deleteActivity
public boolean deleteActivity(long activityId)
Finds activity based on id, removes it, sends cancellation emails to all participants, and deletes the activity from the database- Parameters:
activityId
-- Returns:
- true if deletion was successful, false otherwise
-
addUserToActivity
public boolean addUserToActivity(long activityId, long userId)
Adds a user to an activity, user becomes a participant Checks if both are stored in database- Parameters:
activityId
-userId
-- Returns:
- true if user was added successfully
-
getChat
public Chat getChat(long activityId)
Returns activity's Chat object- Parameters:
activityId
-- Returns:
- Chat entity object
-
checkIfOrganizerOfActivity
public boolean checkIfOrganizerOfActivity(long activityId, long userId)
Checks if a user is the organizer of the activity- Parameters:
activityId
-userId
-- Returns:
- true if user is the orhanizer, false otherwise
-
checkIfParticipant
public boolean checkIfParticipant(long activityId, long userId)
Checks if the user is a participant of an existing activity based on activityId- Parameters:
activityId
-userId
-- Returns:
- true if participant, false otherwise
-
markAbsent
public java.util.Set<java.lang.Long> markAbsent(long activityId, AbsenceDTO absenceDTO)
Method that increases "absence" counter for users that were absent in an activity. Also sets activity's markedAbsence boolean to true, so that we know that the activity already has marked user absences.- Parameters:
activityId
-absenceDTO
-- Returns:
- a set of UserIds of users that were absent. If it fails, returns an empty HashSet.
-
getUsers
public java.util.Set<UserNameDTO> getUsers(long activityId)
Returns names of all participants of an existing activity based on activityId- Parameters:
activityId
-- Returns:
- Set of UserNameDTO objects
-
-