Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add reactoring BuildRequestUrl() #1

Merged
merged 1 commit into from
Sep 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/nt-sms/Triggers/GetMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
using Toast.Common.Models;
using Toast.Common.Validators;
using Toast.Sms.Configurations;
using Toast.Sms.Examples;
using Toast.Sms.Models;
using Toast.Sms.Validators;
using Toast.Sms.Workflows;
Expand Down Expand Up @@ -65,7 +66,7 @@ public GetMessage(ToastSettings<SmsEndpointSettings> settings, IHttpTriggerWorkf

var workflow = new HttpTriggerWorkflow();
await workflow.ValidateHeaderAsync(req)
.ValidateQueriesAsync(req, this._validator)
.ValidateQueriesAsync<GetMessageRequestQueries>(req, this._validator)
.ConfigureAwait(false);

var headers = default(RequestHeaderModel);
Expand Down
25 changes: 24 additions & 1 deletion src/nt-sms/Workflows/HttpTriggerWorkflow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@

using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

using Toast.Common.Builders;
using Toast.Common.Configurations;
using Toast.Common.Extensions;
using Toast.Common.Models;
using Toast.Common.Validators;
using Toast.Sms.Configurations;
using Toast.Sms.Validators;

namespace Toast.Sms.Workflows
Expand All @@ -30,6 +32,8 @@ public interface IHttpTriggerWorkflow
Task<IHttpTriggerWorkflow> ValidateHeaderAsync(HttpRequest req);

Task<IHttpTriggerWorkflow> ValidateQueriesAsync<T>(HttpRequest req, IValidator<T> validator) where T : BaseRequestQueries;

Task<IHttpTriggerWorkflow> BuildRequestUrl<Tresult>(ToastSettings<SmsEndpointSettings> settings, BaseRequestPaths paths = null);
}

/// <summary>
Expand All @@ -40,6 +44,8 @@ public class HttpTriggerWorkflow : IHttpTriggerWorkflow
private RequestHeaderModel _headers;
private BaseRequestQueries _queries;

private string _requestUrl;

/// <inheritdoc />
public async Task<IHttpTriggerWorkflow> ValidateHeaderAsync(HttpRequest req)
{
Expand All @@ -61,5 +67,22 @@ public async Task<IHttpTriggerWorkflow> ValidateHeaderAsync(HttpRequest req)

return await Task.FromResult(this).ConfigureAwait(false);
}

public async Task<IHttpTriggerWorkflow> BuildRequestUrl<Tresult>(ToastSettings<SmsEndpointSettings> settings, BaseRequestPaths paths = null) {
// var paths = new GetMessageRequestPaths() { RequestId = requestId };

var _endpoint = nameof(Tresult);

var requestUrl = new RequestUrlBuilder()
.WithSettings(settings, _endpoint)
.WithHeaders(_headers)
.WithQueries(_queries)
.WithPaths(paths).Build();

this._requestUrl = requestUrl;

return await Task.FromResult(this).ConfigureAwait(false);
}

}
}