Package vaultWeb.services
Class PollService
java.lang.Object
vaultWeb.services.PollService
Service class responsible for managing polls within groups.
Provides functionalities to create, update, delete, retrieve, and vote on polls. It also converts Poll entities to PollResponseDto objects for API responses.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncreatePoll(Group group, User author, PollRequestDto pollDto) Creates a new poll in the specified group by the given author.voiddeletePoll(Long groupId, Long pollId, User user) Deletes a poll authored by a user.getPollsByGroup(Long groupId, User currentUser) Retrieves all polls for a given group.toResponseDto(Poll poll) Converts a Poll entity to a PollResponseDto suitable for API responses.updatePoll(Long groupId, Long pollId, User user, PollRequestDto pollDto) Updates an existing poll authored by a user.voidAllows a user to vote for a specific option in a poll within a group.
-
Constructor Details
-
PollService
public PollService()
-
-
Method Details
-
createPoll
Creates a new poll in the specified group by the given author.- Parameters:
group- the group in which the poll will be createdauthor- the user who creates the pollpollDto- the data transfer object containing poll details- Returns:
- the created Poll entity
- Throws:
NotMemberException- if the author is not a member of the group
-
getPollsByGroup
Retrieves all polls for a given group.- Parameters:
groupId- the ID of the groupcurrentUser- the current user requesting the polls- Returns:
- a list of polls in the group
- Throws:
GroupNotFoundException- if the group does not existNotMemberException- if the user is not a member of the group
-
toResponseDto
Converts a Poll entity to a PollResponseDto suitable for API responses.- Parameters:
poll- the Poll entity to convert- Returns:
- a PollResponseDto representing the poll and its options
-
vote
Allows a user to vote for a specific option in a poll within a group.- Parameters:
groupId- the ID of the group containing the pollpollId- the ID of the polloptionId- the ID of the option to vote foruser- the user casting the vote- Throws:
GroupNotFoundException- if the group does not existNotMemberException- if the user is not a member of the groupPollNotFoundException- if the poll does not existPollDoesNotBelongToGroupException- if the poll doesn't belong to the groupPollOptionNotFoundException- if the poll option invalidAlreadyVotedException- if the user has already voted
-
updatePoll
Updates an existing poll authored by a user.- Parameters:
groupId- the ID of the group containing the pollpollId- the ID of the poll to updateuser- the author of the pollpollDto- the new poll data- Returns:
- the updated Poll entity
- Throws:
PollNotFoundException- if the poll does not existUnauthorizedException- if the user is not the authorPollDoesNotBelongToGroupException- if the poll doesn't belong to the group
-
deletePoll
Deletes a poll authored by a user.- Parameters:
groupId- the ID of the group containing the pollpollId- the ID of the poll to deleteuser- the author of the poll- Throws:
PollNotFoundException- if the poll does not existUnauthorizedException- if the user is not the authorPollDoesNotBelongToGroupException- if the poll doesn't belong to the group
-