From dc145649d66e6aa1c8d8b45122a282cf246ee501 Mon Sep 17 00:00:00 2001 From: William Lewis Date: Thu, 29 Feb 2024 22:32:12 -0600 Subject: [PATCH] Added versioning --- .../ClientApp/src/AppRoutes.js | 2 +- .../ClientApp/src/components/Home.js | 59 ++++++++++++------- .../src/components/services/AccessAPI.js | 1 + .../Controllers/AppInfoController.cs | 32 ++++++++++ ActiveAllocator.API/Program.cs | 2 + .../Services/VersionService.cs | 35 +++++++++++ 6 files changed, 108 insertions(+), 23 deletions(-) create mode 100644 ActiveAllocator.API/Controllers/AppInfoController.cs create mode 100644 ActiveAllocator.API/Services/VersionService.cs diff --git a/ActiveAllocator.API/ClientApp/src/AppRoutes.js b/ActiveAllocator.API/ClientApp/src/AppRoutes.js index 0361564..982e26a 100644 --- a/ActiveAllocator.API/ClientApp/src/AppRoutes.js +++ b/ActiveAllocator.API/ClientApp/src/AppRoutes.js @@ -1,6 +1,6 @@ import { Counter } from "./components/Counter"; import { FetchData } from "./components/FetchData"; -import { Home } from "./components/Home"; +import Home from "./components/Home"; import CreateAccount from "./components/accounts/CreateAccount"; import DeleteAccount from "./components/accounts/DeleteAccount"; import UpdateAccount from "./components/accounts/UpdateAccount"; diff --git a/ActiveAllocator.API/ClientApp/src/components/Home.js b/ActiveAllocator.API/ClientApp/src/components/Home.js index 26fdbc3..46f3b2b 100644 --- a/ActiveAllocator.API/ClientApp/src/components/Home.js +++ b/ActiveAllocator.API/ClientApp/src/components/Home.js @@ -1,26 +1,41 @@ -import React, { Component } from 'react'; +import React from 'react'; +import { useEffect } from "react"; +import { useState } from 'react'; +import { EndPoints, getData } from './services/AccessAPI'; -export class Home extends Component { - static displayName = Home.name; +export default function Home() { + useEffect(() => { + getVersion(); + }, []) - render() { - return ( -
-

Hello, world!

-

Welcome to your new single-page application, built with:

- -

To help you get started, we have also set up:

- -

The ClientApp subdirectory is a standard React application based on the create-react-app template. If you open a command prompt in that directory, you can run npm commands such as npm test or npm install.

-
- ); + const [version, setVersion] = useState(""); + + function getVersion() { + getData(EndPoints.APPVERSION).then( + (result) => { + if (result) { + setVersion(result.version); + } + } + ); } + + return ( +
+

Budget Software - Version {version}

+

Welcome to your new single-page application, built with:

+ +

To help you get started, we have also set up:

+ +

The ClientApp subdirectory is a standard React application based on the create-react-app template. If you open a command prompt in that directory, you can run npm commands such as npm test or npm install.

+
+ ); } diff --git a/ActiveAllocator.API/ClientApp/src/components/services/AccessAPI.js b/ActiveAllocator.API/ClientApp/src/components/services/AccessAPI.js index 0c4b8ba..7b55a0f 100644 --- a/ActiveAllocator.API/ClientApp/src/components/services/AccessAPI.js +++ b/ActiveAllocator.API/ClientApp/src/components/services/AccessAPI.js @@ -20,6 +20,7 @@ export const EndPoints = { AUTOCLASS_TRIGGERTRANSACTIONRULES: "Autoclass/TriggerTransactionRules", APIKEY: "ApiKey", APIKEY_CREATENEW: "ApiKey/CreateNew", + APPVERSION: "AppInfo/ApplicationVersion", } function getOrigin() { diff --git a/ActiveAllocator.API/Controllers/AppInfoController.cs b/ActiveAllocator.API/Controllers/AppInfoController.cs new file mode 100644 index 0000000..0b1b03b --- /dev/null +++ b/ActiveAllocator.API/Controllers/AppInfoController.cs @@ -0,0 +1,32 @@ +namespace ActiveAllocator.API.Controllers; + +using AutoMapper; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Options; +using ActiveAllocator.API.Models.Users; +using ActiveAllocator.API.Services; +using ActiveAllocator.API.Config; +using System; +using System.Security.Claims; +using Microsoft.AspNetCore.Authorization; + +[ApiController] +[Route("[controller]")] +public class AppInfoController : ControllerBase +{ + private IVersionService _versionService; + + public AppInfoController( + IVersionService versionService) + { + _versionService = versionService; + } + + [HttpGet("ApplicationVersion")] + public IActionResult GetApplicationVersion() + { + string appVersion = _versionService.GetVersion(); + + return Ok(new { version = appVersion }); + } +} \ No newline at end of file diff --git a/ActiveAllocator.API/Program.cs b/ActiveAllocator.API/Program.cs index 03d158f..9665bd4 100644 --- a/ActiveAllocator.API/Program.cs +++ b/ActiveAllocator.API/Program.cs @@ -105,6 +105,8 @@ internal class Program builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); + builder.Services.AddScoped(); + builder.Services.AddScoped(); builder.Services.AddSingleton(); diff --git a/ActiveAllocator.API/Services/VersionService.cs b/ActiveAllocator.API/Services/VersionService.cs new file mode 100644 index 0000000..f1d4d42 --- /dev/null +++ b/ActiveAllocator.API/Services/VersionService.cs @@ -0,0 +1,35 @@ +namespace ActiveAllocator.API.Services; + +using AutoMapper; +using ActiveAllocator.API.Entities; +using ActiveAllocator.API.Config; +using ActiveAllocator.API.Models.Accounts; +using System.Collections.Generic; +using System.Linq; +using System; +using System.Security.Policy; + +public interface IVersionService +{ + string GetVersion(); +} + +public class VersionService : IVersionService +{ + const string APP_VERSION = "1.0.0"; + + ILogger _logger; + + public VersionService( + ILogger logger) + { + _logger = logger; + + _logger.LogInformation("App Version: " + APP_VERSION); + } + + public string GetVersion() + { + return APP_VERSION; + } +} \ No newline at end of file