Skip to content

Commit 83e611a

Browse files
GwFreak01GwFreak01
authored andcommitted
feat(poll): add delete poll option endpoint
- Add DeletePollOptionRequest class with userId support - Add deleteOption() static factory method - Add DELETE /polls/{poll_id}/options/{option_id} service method - Add unit test for poll option deletion
1 parent b8d2c9b commit 83e611a

File tree

3 files changed

+80
-0
lines changed

3 files changed

+80
-0
lines changed

src/main/java/io/getstream/chat/java/models/Poll.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,31 @@ protected Call<UpdatePollOptionResponse> generateCall(Client client) throws Stre
531531
}
532532
}
533533

534+
/** Request for deleting a poll option. */
535+
@Getter
536+
@EqualsAndHashCode
537+
public static class DeletePollOptionRequest extends StreamRequest<StreamResponseObject> {
538+
@NotNull private final String pollId;
539+
@NotNull private final String optionId;
540+
@Nullable private String userId;
541+
542+
public DeletePollOptionRequest(@NotNull String pollId, @NotNull String optionId) {
543+
this.pollId = pollId;
544+
this.optionId = optionId;
545+
}
546+
547+
@NotNull
548+
public DeletePollOptionRequest userId(@NotNull String userId) {
549+
this.userId = userId;
550+
return this;
551+
}
552+
553+
@Override
554+
protected Call<StreamResponseObject> generateCall(Client client) throws StreamException {
555+
return client.create(PollService.class).deleteOption(this.pollId, this.optionId, this.userId);
556+
}
557+
}
558+
534559
/** Request data for creating a poll. */
535560
@Builder(
536561
builderClassName = "CreatePollRequest",
@@ -671,4 +696,17 @@ public static UpdatePollOptionRequestData.UpdatePollOptionRequest updateOption(
671696
@NotNull String pollId) {
672697
return new UpdatePollOptionRequestData.UpdatePollOptionRequest(pollId);
673698
}
699+
700+
/**
701+
* Deletes a poll option.
702+
*
703+
* @param pollId the poll ID
704+
* @param optionId the option ID
705+
* @return the created request
706+
*/
707+
@NotNull
708+
public static DeletePollOptionRequest deleteOption(
709+
@NotNull String pollId, @NotNull String optionId) {
710+
return new DeletePollOptionRequest(pollId, optionId);
711+
}
674712
}

src/main/java/io/getstream/chat/java/services/PollService.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,18 @@ Call<CreatePollOptionResponse> createOption(
9898
@PUT("polls/{poll_id}/options")
9999
Call<UpdatePollOptionResponse> updateOption(
100100
@NotNull @Path("poll_id") String pollId, @NotNull @Body UpdatePollOptionRequestData request);
101+
102+
/**
103+
* Deletes a poll option.
104+
*
105+
* @param pollId The poll ID
106+
* @param optionId The option ID
107+
* @param userId Optional user ID
108+
* @return A response indicating success
109+
*/
110+
@DELETE("polls/{poll_id}/options/{option_id}")
111+
Call<StreamResponseObject> deleteOption(
112+
@NotNull @Path("poll_id") String pollId,
113+
@NotNull @Path("option_id") String optionId,
114+
@Nullable @Query("user_id") String userId);
101115
}

src/test/java/io/getstream/chat/java/PollTest.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,4 +350,32 @@ void whenUpdatingPollOption_thenNoException() {
350350
Assertions.assertNotNull(updateResponse.getPollOption());
351351
Assertions.assertEquals(newText, updateResponse.getPollOption().getText());
352352
}
353+
354+
@DisplayName("Can delete a poll option")
355+
@Test
356+
void whenDeletingPollOption_thenNoException() {
357+
// Create a poll with multiple options
358+
CreatePollResponse createResponse =
359+
Assertions.assertDoesNotThrow(
360+
() ->
361+
Poll.create()
362+
.name("Poll for option delete " + UUID.randomUUID())
363+
.userId(testUserRequestObject.getId())
364+
.option(PollOptionRequestObject.builder().text("Option 1").build())
365+
.option(PollOptionRequestObject.builder().text("Option 2").build())
366+
.request());
367+
368+
String pollId = createResponse.getPoll().getId();
369+
String optionId = createResponse.getPoll().getOptions().get(0).getId();
370+
371+
// Delete the option
372+
StreamResponseObject deleteResponse =
373+
Assertions.assertDoesNotThrow(
374+
() ->
375+
Poll.deleteOption(pollId, optionId)
376+
.userId(testUserRequestObject.getId())
377+
.request());
378+
379+
Assertions.assertNotNull(deleteResponse);
380+
}
353381
}

0 commit comments

Comments
 (0)