Skip to content

Commit

Permalink
feat: implement DeleteConversationRequest
Browse files Browse the repository at this point in the history
  • Loading branch information
Tr00d committed Dec 18, 2023
1 parent e36996a commit 77cf0ce
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ namespace Vonage.Test.Unit.Conversations.DeleteConversation
{
public class RequestTest
{
[Fact]
public void GetEndpointPath_ShouldReturnApiEndpoint() =>
DeleteConversationRequest.Parse("CON-123")
.Map(request => request.GetEndpointPath())
.Should()
.BeSuccess("/v1/conversations/CON-123");

[Theory]
[InlineData("")]
[InlineData(" ")]
Expand Down
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));
}

0 comments on commit 77cf0ce

Please sign in to comment.