版本号
This commit is contained in:
1 parent
8cb9b4f57b
commit
f7c73247d6
9 files changed
+163
-1
No files matched your search
@@ -0,0 +1,28 @@
|
|||||||
|
using System.Reflection;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace Jiaowu.Api.Controllers;
|
||||||
|
|
||||||
|
[ApiController]
|
||||||
|
[Route("api/system")]
|
||||||
|
public sealed class SystemController : ControllerBase
|
||||||
|
{
|
||||||
|
[AllowAnonymous]
|
||||||
|
[HttpGet("version")]
|
||||||
|
[ProducesResponseType<SystemVersionResponse>(StatusCodes.Status200OK)]
|
||||||
|
public SystemVersionResponse GetVersion()
|
||||||
|
{
|
||||||
|
var assembly = typeof(SystemController).Assembly;
|
||||||
|
var informationalVersion = assembly
|
||||||
|
.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?
|
||||||
|
.InformationalVersion;
|
||||||
|
var version = informationalVersion?.Split('+', 2)[0]
|
||||||
|
?? assembly.GetName().Version?.ToString(3)
|
||||||
|
?? "unknown";
|
||||||
|
|
||||||
|
return new SystemVersionResponse(version);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public sealed record SystemVersionResponse(string Version);
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net10.0</TargetFramework>
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
|
<Version>2.2.0</Version>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<SpaRoot>$([System.IO.Path]::GetFullPath('$(MSBuildProjectDirectory)/../../web'))</SpaRoot>
|
<SpaRoot>$([System.IO.Path]::GetFullPath('$(MSBuildProjectDirectory)/../../web'))</SpaRoot>
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
using Jiaowu.Api.Controllers;
|
||||||
|
|
||||||
|
namespace Jiaowu.Api.Tests;
|
||||||
|
|
||||||
|
public sealed class SystemControllerTests
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public void GetVersion_ReturnsConfiguredApplicationVersion()
|
||||||
|
{
|
||||||
|
var response = new SystemController().GetVersion();
|
||||||
|
|
||||||
|
Assert.Equal("1.0.0", response.Version);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loaded 3 of 9 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user