create menu api created
This commit is contained in:
parent
56d3b754d9
commit
cc5badeb0f
@ -1,14 +1,45 @@
|
||||
using Marco.Pms.Model.AppMenu;
|
||||
|
||||
using Marco.Pms.Model.AppMenu;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using MongoDB.Driver;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Marco.Pms.CacheHelper
|
||||
{
|
||||
|
||||
private readonly IMongoCollection<MenuSection>? _collection;
|
||||
public class SideBarMenu
|
||||
{
|
||||
private readonly IMongoCollection<MenuSection> _collection;
|
||||
private readonly ILogger<SideBarMenu> _logger;
|
||||
|
||||
public SideBarMenu(IConfiguration configuration, ILogger<SideBarMenu> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
var connectionString = configuration["MongoDB:ConnectionMenu"];
|
||||
var mongoUrl = new MongoUrl(connectionString);
|
||||
var client = new MongoClient(mongoUrl);
|
||||
var database = client.GetDatabase(mongoUrl.DatabaseName);
|
||||
_collection = database.GetCollection<MenuSection>("Menus");
|
||||
}
|
||||
|
||||
public async Task<MenuSection?> CreateMenuSectionAsync(MenuSection section)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _collection.InsertOneAsync(section);
|
||||
return section;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error occured while added in mongo");
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// You can add Get, Update, Delete later here
|
||||
}
|
||||
|
||||
}
|
@ -1,11 +1,6 @@
|
||||
|
||||
using MongoDB.Bson;
|
||||
using MongoDB.Bson.Serialization.Attributes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Marco.Pms.Model.AppMenu
|
||||
{
|
||||
@ -14,6 +9,7 @@ namespace Marco.Pms.Model.AppMenu
|
||||
[BsonId]
|
||||
[BsonRepresentation(BsonType.String)]
|
||||
public Guid Id { get; set; } = Guid.NewGuid();
|
||||
|
||||
public string? Header { get; set; }
|
||||
public string? Title { get; set; }
|
||||
public List<MenuItem> Items { get; set; } = new List<MenuItem>();
|
||||
@ -24,23 +20,28 @@ namespace Marco.Pms.Model.AppMenu
|
||||
[BsonId]
|
||||
[BsonRepresentation(BsonType.String)]
|
||||
public Guid Id { get; set; } = Guid.NewGuid();
|
||||
|
||||
public string? Text { get; set; }
|
||||
public string? Icon { get; set; }
|
||||
public bool? Available { get; set; }
|
||||
public bool Available { get; set; } = true;
|
||||
|
||||
public string? Link { get; set; }
|
||||
public List<SubMenuItem> Submenu { get; set; }
|
||||
|
||||
public List<SubMenuItem> Submenu { get; set; } = new List<SubMenuItem> ();
|
||||
}
|
||||
|
||||
public class SubMenuItem
|
||||
{
|
||||
|
||||
[BsonId]
|
||||
[BsonRepresentation(BsonType.String)]
|
||||
public Guid Id { get; set; } = Guid.NewGuid();
|
||||
public string Text { get; set; }
|
||||
public bool Available { get; set; }
|
||||
public string Link { get; set; }
|
||||
public string permissionKey { get; set; }
|
||||
|
||||
public string? Text { get; set; }
|
||||
public bool Available { get; set; } = true;
|
||||
|
||||
public string Link { get; set; } = string.Empty;
|
||||
|
||||
public string PermissionKey { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
|
42
Marco.Pms.Model/Dtos/AppMenu/SideBarMenuDtco.cs
Normal file
42
Marco.Pms.Model/Dtos/AppMenu/SideBarMenuDtco.cs
Normal file
@ -0,0 +1,42 @@
|
||||
using MongoDB.Bson;
|
||||
using MongoDB.Bson.Serialization.Attributes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Marco.Pms.Model.Dtos.AppMenu
|
||||
{
|
||||
public class MenuSectionDto
|
||||
{
|
||||
|
||||
public string? Header { get; set; }
|
||||
public string? Title { get; set; }
|
||||
public List<MenuItemDto> Items { get; set; } = new List<MenuItemDto>();
|
||||
}
|
||||
|
||||
public class MenuItemDto
|
||||
{
|
||||
|
||||
public string? Text { get; set; }
|
||||
public string? Icon { get; set; }
|
||||
public bool Available { get; set; } = true;
|
||||
|
||||
public string? Link { get; set; }
|
||||
|
||||
public List<SubMenuItemDto> Submenu { get; set; } = new List<SubMenuItemDto>();
|
||||
}
|
||||
|
||||
public class SubMenuItemDto
|
||||
{
|
||||
|
||||
|
||||
public string? Text { get; set; }
|
||||
public bool Available { get; set; } = true;
|
||||
|
||||
public string Link { get; set; } = string.Empty;
|
||||
|
||||
public string PermissionKey { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
@ -1,64 +1,91 @@
|
||||
using Marco.Pms.Model.AppMenu;
|
||||
using AutoMapper;
|
||||
using Azure;
|
||||
using Marco.Pms.CacheHelper;
|
||||
using Marco.Pms.Model.AppMenu;
|
||||
using Marco.Pms.Model.Dtos.AppMenu;
|
||||
using Marco.Pms.Model.Employees;
|
||||
using Marco.Pms.Model.Entitlements;
|
||||
using Marco.Pms.Model.Utilities;
|
||||
using Marco.Pms.Services.Service;
|
||||
using Marco.Pms.Services.Service.ServiceInterfaces;
|
||||
using MarcoBMS.Services.Helpers;
|
||||
using MarcoBMS.Services.Service;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Org.BouncyCastle.Asn1.Ocsp;
|
||||
using System.Threading.Tasks;
|
||||
using static System.Collections.Specialized.BitVector32;
|
||||
|
||||
namespace Marco.Pms.Services.Controllers
|
||||
{
|
||||
public class AppMenuController
|
||||
[Authorize]
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class AppMenuController : ControllerBase
|
||||
{
|
||||
|
||||
private readonly UserHelper _userHelper;
|
||||
private readonly EmployeeHelper _employeeHelper;
|
||||
private readonly RolesHelper _rolesHelper;
|
||||
private readonly SideBarMenu _sideBarMenuHelper;
|
||||
private readonly IMapper _mapper;
|
||||
private readonly ILoggingService _logger;
|
||||
|
||||
public AppMenuController(EmployeeHelper employeeHelper, IProjectServices projectServices, UserHelper userHelper, RolesHelper rolesHelper) {
|
||||
public AppMenuController(EmployeeHelper employeeHelper, IProjectServices projectServices, UserHelper userHelper, RolesHelper rolesHelper, SideBarMenu sideBarMenuHelper, IMapper mapper, ILoggingService logger) {
|
||||
|
||||
_userHelper = userHelper;
|
||||
_employeeHelper = employeeHelper;
|
||||
_rolesHelper = rolesHelper;
|
||||
_sideBarMenuHelper = sideBarMenuHelper;
|
||||
_mapper = mapper;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
|
||||
[HttpGet("/appMenu")]
|
||||
//[HttpGet("/appMenu")]
|
||||
|
||||
public async Task<IActionResult> getAppSideBarMenu()
|
||||
//public async Task<IActionResult> getAppSideBarMenu()
|
||||
//{
|
||||
// return Ok();
|
||||
//}
|
||||
|
||||
|
||||
[HttpPost("create/appsidebar")]
|
||||
public async Task<IActionResult> PostAppSideBarMenu([FromBody] MenuSectionDto sidebarMenu)
|
||||
{
|
||||
return Ok();
|
||||
}
|
||||
|
||||
|
||||
[HttpPost("/create/appsidebar")]
|
||||
public async Task<IActionResult> PostAppSideBarMenu([FromForm] MenuSection sidebarmenu)
|
||||
{
|
||||
var user = await _userHelper.GetCurrentEmployeeAsync();
|
||||
Employee? loginUser = null;
|
||||
|
||||
if (user != null)
|
||||
if (!(user.ApplicationUser?.IsRootUser ?? false))
|
||||
{
|
||||
loginUser = await _employeeHelper.GetEmployeeByApplicationUserID(user.Id.ToString());
|
||||
|
||||
|
||||
List<FeaturePermission> featurePermission = await _rolesHelper.GetFeaturePermissionByEmployeeId(loginUser.Id);
|
||||
string[] projectsId = [];
|
||||
|
||||
|
||||
|
||||
|
||||
return Ok(loginUser);
|
||||
_logger.LogWarning("Access Denied while creating side menu");
|
||||
return StatusCode(403, ApiResponse<object>.ErrorResponse("access denied", "User haven't permission", 403));
|
||||
}
|
||||
|
||||
var sideMenu = _mapper.Map<MenuSection>(sidebarMenu);
|
||||
try
|
||||
{
|
||||
sideMenu = await _sideBarMenuHelper.CreateMenuSectionAsync(sideMenu);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error Occurred while creating Menu");
|
||||
return StatusCode(500, ApiResponse<object>.ErrorResponse("Server Error", ex, 500));
|
||||
}
|
||||
|
||||
if (sideMenu == null) {
|
||||
_logger.LogWarning("Error Occurred while creating Menu");
|
||||
return BadRequest(ApiResponse<object>.ErrorResponse("Menu creation failed", 400));
|
||||
}
|
||||
|
||||
_logger.LogInfo("Error Occurred while creating Menu");
|
||||
return Ok(ApiResponse<object>.SuccessResponse(sideMenu, "Sidebar menu created successfully.", 201));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -68,5 +95,3 @@ namespace Marco.Pms.Services.Controllers
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,4 +1,6 @@
|
||||
using AutoMapper;
|
||||
using Marco.Pms.Model.AppMenu;
|
||||
using Marco.Pms.Model.Dtos.AppMenu;
|
||||
using Marco.Pms.Model.Dtos.Project;
|
||||
using Marco.Pms.Model.Employees;
|
||||
using Marco.Pms.Model.Master;
|
||||
@ -63,6 +65,12 @@ namespace Marco.Pms.Services.MappingProfiles
|
||||
#region ======================================================= Projects =======================================================
|
||||
CreateMap<Employee, EmployeeVM>();
|
||||
#endregion
|
||||
|
||||
#region ======================================================= AppMenu =======================================================
|
||||
CreateMap<MenuSectionDto, MenuSection>();
|
||||
CreateMap<MenuItemDto, MenuItem>();
|
||||
CreateMap<SubMenuItemDto, SubMenuItem>();
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -189,6 +189,7 @@ builder.Services.AddScoped<CacheUpdateHelper>();
|
||||
builder.Services.AddScoped<ProjectCache>();
|
||||
builder.Services.AddScoped<EmployeeCache>();
|
||||
builder.Services.AddScoped<ReportCache>();
|
||||
builder.Services.AddScoped<SideBarMenu>();
|
||||
#endregion
|
||||
|
||||
// Singleton services (one instance for the app's lifetime)
|
||||
|
@ -1,53 +1,55 @@
|
||||
{
|
||||
"Cors": {
|
||||
"AllowedOrigins": "*",
|
||||
"AllowedMethods": "*",
|
||||
"AllowedHeaders": "*"
|
||||
},
|
||||
"Environment": {
|
||||
"Name": "Development",
|
||||
"Title": "Dev"
|
||||
},
|
||||
"ConnectionStrings": {
|
||||
"DefaultConnectionString": "Server=147.93.98.152;User ID=devuser;Password=AppUser@123$;Database=MarcoBMS1"
|
||||
},
|
||||
"SmtpSettings": {
|
||||
"SmtpServer": "smtp.gmail.com",
|
||||
"Port": 587,
|
||||
"SenderName": "MarcoAIOT",
|
||||
"SenderEmail": "marcoioitsoft@gmail.com",
|
||||
"Password": "qrtq wfuj hwpp fhqr"
|
||||
},
|
||||
//"SmtpSettings": {
|
||||
// "SmtpServer": "mail.marcoaiot.com",
|
||||
// "Port": 587,
|
||||
// "SenderName": "MarcoAIOT",
|
||||
// "SenderEmail": "ashutosh.nehete@marcoaiot.com",
|
||||
// "Password": "Reset@123"
|
||||
//},
|
||||
"AppSettings": {
|
||||
"WebFrontendUrl": "http://localhost:5173",
|
||||
"ImagesBaseUrl": "http://localhost:5173"
|
||||
},
|
||||
"Jwt": {
|
||||
"Issuer": "http://localhost:5246",
|
||||
"Audience": "http://localhost:5246",
|
||||
"Key": "sworffishhkjfa9dnfdndfu33infnajfj",
|
||||
"ExpiresInMinutes": 60,
|
||||
"RefreshTokenExpiresInDays": 7
|
||||
},
|
||||
"MailingList": {
|
||||
"RequestDemoReceivers": "ashutosh.nehete@marcoaiot.com;vikas@marcoaiot.com;umesh@marcoait.com"
|
||||
//"ProjectStatisticsReceivers": "ashutosh.nehete@marcoaiot.com;vikas@marcoaiot.com;umesh@marcoait.com"
|
||||
},
|
||||
"AWS": {
|
||||
"AccessKey": "AKIARZDBH3VDMSUUY2FX",
|
||||
"SecretKey": "NTS5XXgZINQbU6ctpNuLXtIY/Qk9GCgD9Rr5yNJP",
|
||||
"Region": "us-east-1",
|
||||
"BucketName": "testenv-marco-pms-documents"
|
||||
},
|
||||
"MongoDB": {
|
||||
"SerilogDatabaseUrl": "mongodb://localhost:27017/DotNetLogs",
|
||||
"ConnectionString": "mongodb://localhost:27017/MarcoBMS_Caches?socketTimeoutMS=500&serverSelectionTimeoutMS=500&connectTimeoutMS=500"
|
||||
}
|
||||
"Cors": {
|
||||
"AllowedOrigins": "*",
|
||||
"AllowedMethods": "*",
|
||||
"AllowedHeaders": "*"
|
||||
},
|
||||
"Environment": {
|
||||
"Name": "Development",
|
||||
"Title": "Dev"
|
||||
},
|
||||
"ConnectionStrings": {
|
||||
"DefaultConnectionString": "Server=147.93.98.152;User ID=devuser;Password=AppUser@123$;Database=MarcoBMS1"
|
||||
},
|
||||
"SmtpSettings": {
|
||||
"SmtpServer": "smtp.gmail.com",
|
||||
"Port": 587,
|
||||
"SenderName": "MarcoAIOT",
|
||||
"SenderEmail": "marcoioitsoft@gmail.com",
|
||||
"Password": "qrtq wfuj hwpp fhqr"
|
||||
},
|
||||
//"SmtpSettings": {
|
||||
// "SmtpServer": "mail.marcoaiot.com",
|
||||
// "Port": 587,
|
||||
// "SenderName": "MarcoAIOT",
|
||||
// "SenderEmail": "ashutosh.nehete@marcoaiot.com",
|
||||
// "Password": "Reset@123"
|
||||
//},
|
||||
"AppSettings": {
|
||||
"WebFrontendUrl": "http://localhost:5173",
|
||||
"ImagesBaseUrl": "http://localhost:5173"
|
||||
},
|
||||
"Jwt": {
|
||||
"Issuer": "http://localhost:5246",
|
||||
"Audience": "http://localhost:5246",
|
||||
"Key": "sworffishhkjfa9dnfdndfu33infnajfj",
|
||||
"ExpiresInMinutes": 60,
|
||||
"RefreshTokenExpiresInDays": 7
|
||||
},
|
||||
"MailingList": {
|
||||
"RequestDemoReceivers": "ashutosh.nehete@marcoaiot.com;vikas@marcoaiot.com;umesh@marcoait.com"
|
||||
//"ProjectStatisticsReceivers": "ashutosh.nehete@marcoaiot.com;vikas@marcoaiot.com;umesh@marcoait.com"
|
||||
},
|
||||
"AWS": {
|
||||
"AccessKey": "AKIARZDBH3VDMSUUY2FX",
|
||||
"SecretKey": "NTS5XXgZINQbU6ctpNuLXtIY/Qk9GCgD9Rr5yNJP",
|
||||
"Region": "us-east-1",
|
||||
"BucketName": "testenv-marco-pms-documents"
|
||||
},
|
||||
"MongoDB": {
|
||||
"SerilogDatabaseUrl": "mongodb://devuser:DevPass123@147.93.98.152:27017/DotNetLogs?authSource=admin",
|
||||
"ConnectionString": "mongodb://devuser:DevPass123@147.93.98.152:27017/DevelopmentCache?authSource=admin&socketTimeoutMS=500&serverSelectionTimeoutMS=500&connectTimeoutMS=500",
|
||||
"ConnectionMenu": "mongodb://devuser:DevPass123@147.93.98.152:27017/UpdateLogs?authSource=admin&socketTimeoutMS=500&serverSelectionTimeoutMS=500&connectTimeoutMS=500",
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user