Skip to content

Commit c1c7ef4

Browse files
GwFreak01GwFreak01
authored andcommitted
feat(poll): add delete poll endpoint
- Add DeletePollRequest class with userId support - Add delete() static factory method - Add DELETE /polls/{poll_id} service method - Add unit test for poll deletion
1 parent 97c4b33 commit c1c7ef4

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,26 @@ protected Call<UpdatePollResponse> generateCall(Client client) throws StreamExce
407407
}
408408
}
409409

410+
/** Request for deleting a poll. */
411+
@Getter
412+
@EqualsAndHashCode
413+
@RequiredArgsConstructor
414+
public static class DeletePollRequest extends StreamRequest<StreamResponseObject> {
415+
@NotNull private final String pollId;
416+
@Nullable private String userId;
417+
418+
@NotNull
419+
public DeletePollRequest userId(@NotNull String userId) {
420+
this.userId = userId;
421+
return this;
422+
}
423+
424+
@Override
425+
protected Call<StreamResponseObject> generateCall(Client client) throws StreamException {
426+
return client.create(PollService.class).delete(this.pollId, this.userId);
427+
}
428+
}
429+
410430
/** Request data for creating a poll. */
411431
@Builder(
412432
builderClassName = "CreatePollRequest",
@@ -512,4 +532,15 @@ public static PartialUpdatePollRequestData.PartialUpdatePollRequest partialUpdat
512532
@NotNull String pollId) {
513533
return new PartialUpdatePollRequestData.PartialUpdatePollRequest(pollId);
514534
}
535+
536+
/**
537+
* Deletes a poll.
538+
*
539+
* @param pollId the poll ID
540+
* @return the created request
541+
*/
542+
@NotNull
543+
public static DeletePollRequest delete(@NotNull String pollId) {
544+
return new DeletePollRequest(pollId);
545+
}
515546
}

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
import io.getstream.chat.java.models.Poll.PartialUpdatePollRequestData;
77
import io.getstream.chat.java.models.Poll.UpdatePollRequestData;
88
import io.getstream.chat.java.models.Poll.UpdatePollResponse;
9+
import io.getstream.chat.java.models.framework.StreamResponseObject;
910
import org.jetbrains.annotations.NotNull;
1011
import org.jetbrains.annotations.Nullable;
1112
import retrofit2.Call;
1213
import retrofit2.http.Body;
14+
import retrofit2.http.DELETE;
1315
import retrofit2.http.GET;
1416
import retrofit2.http.PATCH;
1517
import retrofit2.http.POST;
@@ -59,4 +61,15 @@ Call<GetPollResponse> get(
5961
@PATCH("polls/{poll_id}")
6062
Call<UpdatePollResponse> partialUpdate(
6163
@NotNull @Path("poll_id") String pollId, @NotNull @Body PartialUpdatePollRequestData request);
64+
65+
/**
66+
* Deletes a poll.
67+
*
68+
* @param pollId The poll ID
69+
* @param userId Optional user ID
70+
* @return A response indicating success
71+
*/
72+
@DELETE("polls/{poll_id}")
73+
Call<StreamResponseObject> delete(
74+
@NotNull @Path("poll_id") String pollId, @Nullable @Query("user_id") String userId);
6275
}

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import io.getstream.chat.java.models.Poll.PollOptionRequestObject;
77
import io.getstream.chat.java.models.Poll.UpdatePollResponse;
88
import io.getstream.chat.java.models.Poll.VotingVisibility;
9+
import io.getstream.chat.java.models.framework.StreamResponseObject;
910
import java.util.UUID;
1011
import org.junit.jupiter.api.Assertions;
1112
import org.junit.jupiter.api.DisplayName;
@@ -261,4 +262,27 @@ void whenPartiallyUpdatingPollWithUnset_thenNoException() {
261262
Assertions.assertNotNull(updateResponse);
262263
Assertions.assertNull(updateResponse.getPoll().getDescription());
263264
}
265+
266+
@DisplayName("Can delete a poll")
267+
@Test
268+
void whenDeletingPoll_thenNoException() {
269+
// Create a poll first
270+
CreatePollResponse createResponse =
271+
Assertions.assertDoesNotThrow(
272+
() ->
273+
Poll.create()
274+
.name("Poll to delete " + UUID.randomUUID())
275+
.userId(testUserRequestObject.getId())
276+
.option(PollOptionRequestObject.builder().text("A").build())
277+
.request());
278+
279+
String pollId = createResponse.getPoll().getId();
280+
281+
// Delete the poll
282+
StreamResponseObject deleteResponse =
283+
Assertions.assertDoesNotThrow(
284+
() -> Poll.delete(pollId).userId(testUserRequestObject.getId()).request());
285+
286+
Assertions.assertNotNull(deleteResponse);
287+
}
264288
}

0 commit comments

Comments
 (0)