From d04d5a7ea22f9e235ccafdf8652a9db19dedf7bd Mon Sep 17 00:00:00 2001 From: Mate Farkas Date: Wed, 17 Apr 2024 17:42:36 +0200 Subject: [PATCH] Add version endpoint --- ConnectionsAPI.csproj | 3 ++ Features/Version/Get/GetVersionEndpoint.cs | 40 ++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 Features/Version/Get/GetVersionEndpoint.cs diff --git a/ConnectionsAPI.csproj b/ConnectionsAPI.csproj index 1f02ff4..ee78d84 100644 --- a/ConnectionsAPI.csproj +++ b/ConnectionsAPI.csproj @@ -12,6 +12,9 @@ + + all + diff --git a/Features/Version/Get/GetVersionEndpoint.cs b/Features/Version/Get/GetVersionEndpoint.cs new file mode 100644 index 0000000..74c33f8 --- /dev/null +++ b/Features/Version/Get/GetVersionEndpoint.cs @@ -0,0 +1,40 @@ + +using System.Text; + +namespace ConnectionsAPI.Features.Version.Get +{ + public class GetVersionEndpoint : EndpointWithoutRequest + { + private static readonly int START_YEAR = 2024; + + public override void Configure() + { + Get("/version"); + AllowAnonymous(); + } + + public override async Task HandleAsync(CancellationToken ct) + { + StringBuilder responseBuilder = new(); + + responseBuilder.Append("ConnectionsAPI ©"); + if (DateTime.UtcNow.Year != START_YEAR) + { + responseBuilder.AppendFormat("{0} - {1}; ", START_YEAR, DateTime.UtcNow.Year); + } + else + { + responseBuilder.AppendFormat("{0}; ", DateTime.UtcNow.Year); + } + + responseBuilder.Append("by Mate Farkas; "); + + responseBuilder.AppendFormat("v{0}-{1}+{2};", + GitVersionInformation.MajorMinorPatch, + GitVersionInformation.ShortSha, + GitVersionInformation.EscapedBranchName); + + await SendStringAsync(responseBuilder.ToString(), cancellation: ct); + } + } +}