2022-09-05 22:42:41 +02:00
|
|
|
|
using AutoMapper;
|
|
|
|
|
using Giants.DataContract.Contracts.V1;
|
2020-08-10 09:22:33 +02:00
|
|
|
|
using Giants.Services;
|
2022-09-05 22:42:41 +02:00
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
2020-08-10 09:22:33 +02:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2022-09-05 22:42:41 +02:00
|
|
|
|
using Microsoft.Identity.Web.Resource;
|
2022-09-09 07:31:24 +02:00
|
|
|
|
using System;
|
2022-09-05 22:42:41 +02:00
|
|
|
|
using System.Threading.Tasks;
|
2020-08-10 09:22:33 +02:00
|
|
|
|
|
|
|
|
|
namespace Giants.WebApi.Controllers
|
|
|
|
|
{
|
|
|
|
|
[ApiController]
|
2020-10-12 23:42:44 +02:00
|
|
|
|
[ApiVersion("1.0")]
|
2022-09-05 05:29:59 +02:00
|
|
|
|
[ApiVersion("1.1")]
|
2020-08-10 09:22:33 +02:00
|
|
|
|
[Route("api/[controller]")]
|
|
|
|
|
public class VersionController : ControllerBase
|
|
|
|
|
{
|
|
|
|
|
private readonly IMapper mapper;
|
2022-09-05 22:42:41 +02:00
|
|
|
|
private readonly IVersioningService versioningService;
|
|
|
|
|
private const string VersionWriteScope = "App.Write";
|
2020-08-10 09:22:33 +02:00
|
|
|
|
|
|
|
|
|
public VersionController(
|
|
|
|
|
IMapper mapper,
|
2022-09-05 22:42:41 +02:00
|
|
|
|
IVersioningService versioningService)
|
2020-08-10 09:22:33 +02:00
|
|
|
|
{
|
|
|
|
|
this.mapper = mapper;
|
2022-09-05 22:42:41 +02:00
|
|
|
|
this.versioningService = versioningService;
|
2020-08-10 09:22:33 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
2022-09-09 07:31:24 +02:00
|
|
|
|
public async Task<DataContract.V1.VersionInfo> GetVersionInfo(string appName, string branchName)
|
|
|
|
|
{
|
|
|
|
|
ArgumentUtility.CheckStringForNullOrEmpty(appName);
|
|
|
|
|
|
|
|
|
|
VersionInfo versionInfo = await this.versioningService.GetVersionInfo(appName, branchName);
|
|
|
|
|
|
|
|
|
|
if (versionInfo == null)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentException($"No version information for {appName} ({branchName}) found.", appName);
|
|
|
|
|
}
|
2020-08-10 09:22:33 +02:00
|
|
|
|
|
2020-09-06 01:47:00 +02:00
|
|
|
|
return this.mapper.Map<DataContract.V1.VersionInfo>(versionInfo);
|
2020-08-10 09:22:33 +02:00
|
|
|
|
}
|
2022-09-05 22:42:41 +02:00
|
|
|
|
|
|
|
|
|
[Authorize]
|
|
|
|
|
[RequiredScopeOrAppPermission(
|
|
|
|
|
AcceptedAppPermission = new[] { VersionWriteScope }) ]
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public async Task UpdateVersionInfo([FromBody] VersionInfoUpdate versionInfoUpdate)
|
|
|
|
|
{
|
|
|
|
|
ArgumentUtility.CheckForNull(versionInfoUpdate);
|
|
|
|
|
|
2022-09-09 07:31:24 +02:00
|
|
|
|
await this.versioningService.UpdateVersionInfo(
|
|
|
|
|
appName: versionInfoUpdate.AppName,
|
|
|
|
|
appVersion: versionInfoUpdate.AppVersion,
|
|
|
|
|
fileName: versionInfoUpdate.FileName,
|
|
|
|
|
branchName: versionInfoUpdate.BranchName,
|
|
|
|
|
force: versionInfoUpdate.ForceUpdate);
|
2022-09-05 22:42:41 +02:00
|
|
|
|
}
|
2020-08-10 09:22:33 +02:00
|
|
|
|
}
|
|
|
|
|
}
|