File tree Expand file tree Collapse file tree 3 files changed +68
-0
lines changed
main/java/io/getstream/chat/java
test/java/io/getstream/chat/java Expand file tree Collapse file tree 3 files changed +68
-0
lines changed Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff line change 66import io .getstream .chat .java .models .Poll .PartialUpdatePollRequestData ;
77import io .getstream .chat .java .models .Poll .UpdatePollRequestData ;
88import io .getstream .chat .java .models .Poll .UpdatePollResponse ;
9+ import io .getstream .chat .java .models .framework .StreamResponseObject ;
910import org .jetbrains .annotations .NotNull ;
1011import org .jetbrains .annotations .Nullable ;
1112import retrofit2 .Call ;
1213import retrofit2 .http .Body ;
14+ import retrofit2 .http .DELETE ;
1315import retrofit2 .http .GET ;
1416import retrofit2 .http .PATCH ;
1517import 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}
Original file line number Diff line number Diff line change 66import io .getstream .chat .java .models .Poll .PollOptionRequestObject ;
77import io .getstream .chat .java .models .Poll .UpdatePollResponse ;
88import io .getstream .chat .java .models .Poll .VotingVisibility ;
9+ import io .getstream .chat .java .models .framework .StreamResponseObject ;
910import java .util .UUID ;
1011import org .junit .jupiter .api .Assertions ;
1112import 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}
You can’t perform that action at this time.
0 commit comments