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; private WorkspaceService _srvWorkspace; protected override RoleEnum LoginRoleAllowed => RoleEnum.Console; public ConsoleController(UserService srvUsers, CatalogueService srvCatalogue, WorkspaceService srvWorkspace, ILoggerFactory logger, AccessService srvAccess) : base(logger, srvAccess) { _srvUsers = srvUsers ?? throw new ArgumentNullException(nameof(srvUsers)); _srvCatalogue = srvCatalogue ?? throw new ArgumentNullException(nameof(srvCatalogue)); _srvWorkspace = srvWorkspace ?? throw new ArgumentNullException(nameof(srvWorkspace)); } #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 #region *** Workspace *** [HttpGet("{Ticket}/workspace/{scope}")] public async Task> GetAllWorkspaces(string ticket, WorkspaceScopeEnums scope, [FromHeader] string page, [FromHeader] string pageSize, [FromHeader] string context) { CheckAccess(ticket); return await Call(async () => await _srvWorkspace.GetWorkspacesAsync(scope, new HeaderPagingDto(page, pageSize), context)); } [HttpPost("{ticket}/workspace")] public async Task> CreateWorkspace(string ticket, [FromBody] WorkspaceCDto workspace) { CheckAccess(ticket); return await Call(async () => await _srvWorkspace.CreateWorkspaceAsync(workspace)); } #endregion } }