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(PollContext pollContext, User author, PollRequestDto pollDto) Creates a new poll in the specified group by the given author.voiddeletePoll(Long pollId, User user) Deletes a poll authored by a user.voiddeletePollInGroup(Long groupId, Long pollId, User user) voiddeletePollInPrivateChat(Long privateChatId, Long pollId, User user) getPollsByGroup(Long groupId, User currentUser) Retrieves all polls for a given group.getPollsByPrivateChat(Long privateChatId, User currentUser) toResponseDto(Poll poll) Converts a Poll entity to a PollResponseDto suitable for API responses.updatePoll(Long pollId, User user, PollRequestDto pollDto) Updates an existing poll authored by a user.updatePollInGroup(Long groupId, Long pollId, User user, PollRequestDto pollDto) updatePollInPrivateChat(Long privateChatId, Long pollId, User user, PollRequestDto pollDto) voidAllows a user to vote for a specific option in a poll within a group.voidvoteInGroup(Long groupId, Long pollId, Long optionId, User user) voidvoteInPrivateChat(Long privateChatId, Long pollId, Long optionId, User user)
-
Constructor Details
-
PollService
public PollService()
-
-
Method Details
-
createPoll
Creates a new poll in the specified group by the given author.- Parameters:
pollContext- the group or private chat 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
-
getPollsByPrivateChat
-
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:
pollId- 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
-
voteInGroup
-
voteInPrivateChat
-
updatePoll
Updates an existing poll authored by a user.- Parameters:
pollId- 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
-
updatePollInGroup
-
updatePollInPrivateChat
public Poll updatePollInPrivateChat(Long privateChatId, Long pollId, User user, PollRequestDto pollDto) -
deletePoll
Deletes a poll authored by a user.- Parameters:
pollId- 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
-
deletePollInGroup
-
deletePollInPrivateChat
-