using System; using System.Collections.Generic; using System.Diagnostics; using System.Threading.Tasks; using BO.AppServer.Business; using BO.AppServer.Business.Services; using BO.AppServer.Metadata.Dto; using BO.AppServer.Metadata.Enums; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using Quadarax.Foundation.Core.Data.Interface.Entity.Dto; namespace BO.AppServer.Web.Services { [Authorize] [Route("api/[controller]")] [ApiController] public class ConsoleController : Base { private UserService _srvUsers; private CatalogueService _srvCatalogue; protected override RoleEnum LoginRoleAllowed => RoleEnum.Console; public ConsoleController(UserService srvUsers, CatalogueService srvCatalogue, ILoggerFactory logger, AccessService srvAccess) : base(logger, srvAccess) { _srvUsers = srvUsers ?? throw new ArgumentNullException(nameof(srvUsers)); _srvCatalogue = srvCatalogue ?? throw new ArgumentNullException(nameof(srvCatalogue)); } #region *** User *** [HttpGet("{ticket}/users/{scope}")] public async Task> GetAllUsers(string ticket, UserScopeEnums scope, [FromHeader] string page, [FromHeader] string pageSize) { CheckAccess(ticket); return await Call(async () => await _srvUsers.GetAllUsersAsync(scope, new HeaderPagingDto(page, pageSize))); } [HttpGet("{ticket}/user/{identificationType}/{identificationValue}")] public async Task> GetUser(string ticket, IdentificationTypeEnum identificationType, string identificationValue) { CheckAccess(ticket); return await Call(async () => await _srvUsers.GetUserAsync(1)); } [HttpPost("{ticket}/user")] public async Task> CreateUser(string ticket, [FromBody] UserCDto user) { CheckAccess(ticket); return await Call(async () => await _srvUsers.CreateUserAsync(user)); } #endregion #region *** Catalogues *** [HttpGet("{Ticket}/bplans/{scope}")] public async Task> GetAllBillingPlans(string ticket, BillingPlanScopeEnums scope, [FromHeader] string page, [FromHeader] string pageSize) { CheckAccess(ticket); return await Call(async () => await _srvCatalogue.GetBillingPlansAsync(scope, new HeaderPagingDto(page, pageSize))); } [HttpPost("{Ticket}/bplan")] public async Task> CreateBillingPlan(string ticket, [FromBody] BillingPlanCDto billingPlan) { CheckAccess(ticket); return await Call(async () => await _srvCatalogue.CreateBillingPlanAsync(billingPlan)); } [HttpPut("{Ticket}/bplan")] public async Task> UpdateBillingPlan(string ticket, [FromBody] BillingPlanUDto billingPlan) { CheckAccess(ticket); return await Call(async () => await _srvCatalogue.UpdateBillingPlanAsync(billingPlan)); } [HttpGet("{Ticket}/mtypes/{scope}")] public async Task> GetAllMimeTypes(string ticket, MimeTypeScopeEnums scope, [FromHeader] string page, [FromHeader] string pageSize) { CheckAccess(ticket); return await Call(async () => await _srvCatalogue.GetMimeTypesAsync(scope, new HeaderPagingDto(page, pageSize))); } [HttpPost("{Ticket}/mtype")] public async Task> CreateMimeType(string ticket, [FromBody] MimeTypeCDto mimeType) { CheckAccess(ticket); return await Call(async () => await _srvCatalogue.CreateMimeTypeAsync(mimeType)); } [HttpPut("{Ticket}/mtype")] public async Task> UpdateMimeType(string ticket, [FromBody] MimeTypeUDto mimeType) { CheckAccess(ticket); return await Call(async () => await _srvCatalogue.UpdateMimeTypeAsync(mimeType)); } #endregion #region *** Statistics *** [HttpGet("{ticket}/versions")] public async Task> GetVersions(string ticket) { CheckAccess(ticket); return await Call(async () => { var assemblies = AppDomain.CurrentDomain.GetAssemblies(); var result = new List(); foreach (var assembly in assemblies) { var fiv = FileVersionInfo.GetVersionInfo(assembly.Location); result.Add(new AssemblyInfoDto() { FileVersion = fiv.FileVersion, AssemblyVersion = assembly.GetName().Version?.ToString(), Name = assembly.GetName().Name }); } return new ResultsValueDto(result); }); } #endregion } }