-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement DeleteConversationRequest
- Loading branch information
Showing
2 changed files
with
35 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 28 additions & 16 deletions
44
Vonage/Conversations/DeleteConversation/DeleteConversationRequest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,37 @@ | ||
using System; | ||
using System.Net.Http; | ||
using System.Net.Http; | ||
using Vonage.Common.Client; | ||
using Vonage.Common.Monads; | ||
using Vonage.Common.Validation; | ||
|
||
namespace Vonage.Conversations.DeleteConversation | ||
namespace Vonage.Conversations.DeleteConversation; | ||
|
||
/// <inheritdoc /> | ||
public readonly struct DeleteConversationRequest : IVonageRequest | ||
{ | ||
public readonly struct DeleteConversationRequest : IVonageRequest | ||
{ | ||
public string ConversationId { get; private init; } | ||
public HttpRequestMessage BuildRequestMessage() => throw new NotImplementedException(); | ||
/// <summary> | ||
/// The conversation Id. | ||
/// </summary> | ||
public string ConversationId { get; private init; } | ||
|
||
/// <inheritdoc /> | ||
public HttpRequestMessage BuildRequestMessage() => VonageRequestBuilder | ||
.Initialize(HttpMethod.Delete, this.GetEndpointPath()) | ||
.Build(); | ||
|
||
public string GetEndpointPath() => throw new NotImplementedException(); | ||
/// <inheritdoc /> | ||
public string GetEndpointPath() => $"/v1/conversations/{this.ConversationId}"; | ||
|
||
public static Result<DeleteConversationRequest> Parse(string conversationId) => | ||
Result<DeleteConversationRequest> | ||
.FromSuccess(new DeleteConversationRequest {ConversationId = conversationId}) | ||
.Map(InputEvaluation<DeleteConversationRequest>.Evaluate) | ||
.Bind(evaluation => evaluation.WithRules(VerifyConversationId)); | ||
/// <summary> | ||
/// Parses the input into a DeleteConversationRequest. | ||
/// </summary> | ||
/// <param name="conversationId">The conversation Id.</param> | ||
/// <returns>A success state with the request if the parsing succeeded. A failure state with an error if it failed.</returns> | ||
public static Result<DeleteConversationRequest> Parse(string conversationId) => | ||
Result<DeleteConversationRequest> | ||
.FromSuccess(new DeleteConversationRequest { ConversationId = conversationId }) | ||
.Map(InputEvaluation<DeleteConversationRequest>.Evaluate) | ||
.Bind(evaluation => evaluation.WithRules(VerifyConversationId)); | ||
|
||
private static Result<DeleteConversationRequest> VerifyConversationId(DeleteConversationRequest request) => | ||
InputValidation.VerifyNotEmpty(request, request.ConversationId, nameof(ConversationId)); | ||
} | ||
private static Result<DeleteConversationRequest> VerifyConversationId(DeleteConversationRequest request) => | ||
InputValidation.VerifyNotEmpty(request, request.ConversationId, nameof(ConversationId)); | ||
} |