initially added fetch menu api
This commit is contained in:
parent
6c394f40ad
commit
ff5f673475
@ -1,11 +1,14 @@
|
|||||||
using Marco.Pms.Model.AppMenu;
|
using Marco.Pms.Model.AppMenu;
|
||||||
|
using Marco.Pms.Model.Dtos.AppMenu;
|
||||||
|
using Marco.Pms.Model.ViewModels.AppMenu;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using MongoDB.Driver;
|
|
||||||
using MongoDB.Bson;
|
using MongoDB.Bson;
|
||||||
|
using MongoDB.Driver;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using static System.Collections.Specialized.BitVector32;
|
||||||
|
|
||||||
namespace Marco.Pms.CacheHelper
|
namespace Marco.Pms.CacheHelper
|
||||||
{
|
{
|
||||||
@ -46,7 +49,8 @@ namespace Marco.Pms.CacheHelper
|
|||||||
|
|
||||||
var update = Builders<MenuSection>.Update
|
var update = Builders<MenuSection>.Update
|
||||||
.Set(s => s.Header, updatedSection.Header)
|
.Set(s => s.Header, updatedSection.Header)
|
||||||
.Set(s => s.Title, updatedSection.Title);
|
.Set(s => s.Title, updatedSection.Title)
|
||||||
|
.Set(s => s.Items, updatedSection.Items);
|
||||||
|
|
||||||
var result = await _collection.UpdateOneAsync(filter, update);
|
var result = await _collection.UpdateOneAsync(filter, update);
|
||||||
|
|
||||||
@ -104,9 +108,10 @@ namespace Marco.Pms.CacheHelper
|
|||||||
.Set("Items.$.Icon", updatedItem.Icon)
|
.Set("Items.$.Icon", updatedItem.Icon)
|
||||||
.Set("Items.$.Available", updatedItem.Available)
|
.Set("Items.$.Available", updatedItem.Available)
|
||||||
.Set("Items.$.Link", updatedItem.Link)
|
.Set("Items.$.Link", updatedItem.Link)
|
||||||
.Set("Items.$.PermissionKey",updatedItem.PermissionKey);
|
.Set("Items.$.PermissionKeys", updatedItem.PermissionKeys); // <-- updated
|
||||||
|
|
||||||
var result = await _collection.UpdateOneAsync(filter, update);
|
var result = await _collection.UpdateOneAsync(filter, update);
|
||||||
|
|
||||||
if (result.ModifiedCount > 0)
|
if (result.ModifiedCount > 0)
|
||||||
{
|
{
|
||||||
// Re-fetch section and return the updated item
|
// Re-fetch section and return the updated item
|
||||||
@ -172,7 +177,7 @@ namespace Marco.Pms.CacheHelper
|
|||||||
.Set("Items.$[item].Submenu.$[sub].Text", updatedSub.Text)
|
.Set("Items.$[item].Submenu.$[sub].Text", updatedSub.Text)
|
||||||
.Set("Items.$[item].Submenu.$[sub].Available", updatedSub.Available)
|
.Set("Items.$[item].Submenu.$[sub].Available", updatedSub.Available)
|
||||||
.Set("Items.$[item].Submenu.$[sub].Link", updatedSub.Link)
|
.Set("Items.$[item].Submenu.$[sub].Link", updatedSub.Link)
|
||||||
.Set("Items.$[item].Submenu.$[sub].PermissionKey", updatedSub.PermissionKey);
|
.Set("Items.$[item].Submenu.$[sub].PermissionKeys", updatedSub.PermissionKeys); // <-- updated
|
||||||
|
|
||||||
var options = new UpdateOptions { ArrayFilters = arrayFilters };
|
var options = new UpdateOptions { ArrayFilters = arrayFilters };
|
||||||
|
|
||||||
@ -184,9 +189,9 @@ namespace Marco.Pms.CacheHelper
|
|||||||
var updatedSection = await _collection.Find(x => x.Id == sectionId).FirstOrDefaultAsync();
|
var updatedSection = await _collection.Find(x => x.Id == sectionId).FirstOrDefaultAsync();
|
||||||
|
|
||||||
var subItem = updatedSection?.Items
|
var subItem = updatedSection?.Items
|
||||||
.FirstOrDefault(i => i.Id.ToString() == itemId.ToString())?
|
.FirstOrDefault(i => i.Id == itemId)?
|
||||||
.Submenu
|
.Submenu
|
||||||
.FirstOrDefault(s => s.Id.ToString() == subItemId.ToString());
|
.FirstOrDefault(s => s.Id == subItemId);
|
||||||
|
|
||||||
return subItem;
|
return subItem;
|
||||||
}
|
}
|
||||||
@ -197,5 +202,13 @@ namespace Marco.Pms.CacheHelper
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public async Task<List<MenuSection>> GetAllMenuSectionsAsync()
|
||||||
|
{
|
||||||
|
return await _collection.Find(_ => true).ToListAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
|
using MongoDB.Bson;
|
||||||
using MongoDB.Bson;
|
|
||||||
using MongoDB.Bson.Serialization.Attributes;
|
using MongoDB.Bson.Serialization.Attributes;
|
||||||
|
|
||||||
namespace Marco.Pms.Model.AppMenu
|
namespace Marco.Pms.Model.AppMenu
|
||||||
@ -27,9 +26,10 @@ namespace Marco.Pms.Model.AppMenu
|
|||||||
|
|
||||||
public string? Link { get; set; }
|
public string? Link { get; set; }
|
||||||
|
|
||||||
public string PermissionKey { get; set; } = string.Empty;
|
// Changed from string → List<string>
|
||||||
|
public List<string> PermissionKeys { get; set; } = new List<string>();
|
||||||
|
|
||||||
public List<SubMenuItem> Submenu { get; set; } = new List<SubMenuItem> ();
|
public List<SubMenuItem> Submenu { get; set; } = new List<SubMenuItem>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public class SubMenuItem
|
public class SubMenuItem
|
||||||
@ -38,12 +38,14 @@ namespace Marco.Pms.Model.AppMenu
|
|||||||
[BsonRepresentation(BsonType.String)]
|
[BsonRepresentation(BsonType.String)]
|
||||||
public Guid Id { get; set; } = Guid.NewGuid();
|
public Guid Id { get; set; } = Guid.NewGuid();
|
||||||
|
|
||||||
public string? Text { get; set; }
|
public string? Text { get; set; }
|
||||||
public bool Available { get; set; } = true;
|
public bool Available { get; set; } = true;
|
||||||
|
|
||||||
public string Link { get; set; } = string.Empty;
|
public string Link { get; set; } = string.Empty;
|
||||||
|
|
||||||
public string PermissionKey { get; set; } = string.Empty;
|
// Changed from string → List<string>
|
||||||
|
public List<string> PermissionKeys { get; set; } = new List<string>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -10,7 +10,6 @@ namespace Marco.Pms.Model.Dtos.AppMenu
|
|||||||
{
|
{
|
||||||
public class MenuSectionDto
|
public class MenuSectionDto
|
||||||
{
|
{
|
||||||
|
|
||||||
public string? Header { get; set; }
|
public string? Header { get; set; }
|
||||||
public string? Title { get; set; }
|
public string? Title { get; set; }
|
||||||
public List<MenuItemDto> Items { get; set; } = new List<MenuItemDto>();
|
public List<MenuItemDto> Items { get; set; } = new List<MenuItemDto>();
|
||||||
@ -18,26 +17,26 @@ namespace Marco.Pms.Model.Dtos.AppMenu
|
|||||||
|
|
||||||
public class MenuItemDto
|
public class MenuItemDto
|
||||||
{
|
{
|
||||||
|
|
||||||
public string? Text { get; set; }
|
public string? Text { get; set; }
|
||||||
public string? Icon { get; set; }
|
public string? Icon { get; set; }
|
||||||
public bool Available { get; set; } = true;
|
public bool Available { get; set; } = true;
|
||||||
|
|
||||||
public string? Link { get; set; }
|
public string? Link { get; set; }
|
||||||
|
|
||||||
public string PermissionKey { get; set; } = string.Empty;
|
// Changed from string → List<string>
|
||||||
|
public List<string> PermissionKeys { get; set; } = new List<string>();
|
||||||
|
|
||||||
public List<SubMenuItemDto> Submenu { get; set; } = new List<SubMenuItemDto>();
|
public List<SubMenuItemDto> Submenu { get; set; } = new List<SubMenuItemDto>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public class SubMenuItemDto
|
public class SubMenuItemDto
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
public string? Text { get; set; }
|
public string? Text { get; set; }
|
||||||
public bool Available { get; set; } = true;
|
public bool Available { get; set; } = true;
|
||||||
|
|
||||||
public string Link { get; set; } = string.Empty;
|
public string Link { get; set; } = string.Empty;
|
||||||
|
|
||||||
public string PermissionKey { get; set; } = string.Empty;
|
// Changed from string → List<string>
|
||||||
|
public List<string> PermissionKeys { get; set; } = new List<string>();
|
||||||
}
|
}
|
||||||
}
|
}
|
28
Marco.Pms.Model/ViewModels/AppMenu/AppMenuVM.cs
Normal file
28
Marco.Pms.Model/ViewModels/AppMenu/AppMenuVM.cs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Marco.Pms.Model.ViewModels.AppMenu
|
||||||
|
{
|
||||||
|
public class MenuSectionVm
|
||||||
|
{
|
||||||
|
public string? Header { get; set; }
|
||||||
|
public string? Title { get; set; }
|
||||||
|
public List<MenuItemVm> Items { get; set; } = new();
|
||||||
|
}
|
||||||
|
|
||||||
|
public class MenuItemVm
|
||||||
|
{
|
||||||
|
public string? Text { get; set; }
|
||||||
|
public string? Icon { get; set; }
|
||||||
|
public bool Available { get; set; } = true;
|
||||||
|
public string? Link { get; set; }
|
||||||
|
public List<SubMenuItemVm> Submenu { get; set; } = new();
|
||||||
|
}
|
||||||
|
|
||||||
|
public class SubMenuItemVm
|
||||||
|
{
|
||||||
|
public string? Text { get; set; }
|
||||||
|
public bool Available { get; set; } = true;
|
||||||
|
public string Link { get; set; } = string.Empty;
|
||||||
|
}
|
||||||
|
}
|
@ -32,8 +32,10 @@ namespace Marco.Pms.Services.Controllers
|
|||||||
private readonly SideBarMenu _sideBarMenuHelper;
|
private readonly SideBarMenu _sideBarMenuHelper;
|
||||||
private readonly IMapper _mapper;
|
private readonly IMapper _mapper;
|
||||||
private readonly ILoggingService _logger;
|
private readonly ILoggingService _logger;
|
||||||
|
private readonly PermissionServices _permissions;
|
||||||
|
|
||||||
public AppMenuController(EmployeeHelper employeeHelper, IProjectServices projectServices, UserHelper userHelper, RolesHelper rolesHelper, SideBarMenu sideBarMenuHelper, IMapper mapper, ILoggingService logger) {
|
public AppMenuController(EmployeeHelper employeeHelper, IProjectServices projectServices, UserHelper userHelper, RolesHelper rolesHelper, SideBarMenu sideBarMenuHelper, IMapper mapper, ILoggingService logger, PermissionServices permissions = null)
|
||||||
|
{
|
||||||
|
|
||||||
_userHelper = userHelper;
|
_userHelper = userHelper;
|
||||||
_employeeHelper = employeeHelper;
|
_employeeHelper = employeeHelper;
|
||||||
@ -41,6 +43,7 @@ namespace Marco.Pms.Services.Controllers
|
|||||||
_sideBarMenuHelper = sideBarMenuHelper;
|
_sideBarMenuHelper = sideBarMenuHelper;
|
||||||
_mapper = mapper;
|
_mapper = mapper;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
|
_permissions = permissions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -227,11 +230,11 @@ namespace Marco.Pms.Services.Controllers
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var menus = await _sideBarMenuHelper.GetAllMenuSectionsAsync();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return Ok(LoggedUser);
|
return Ok(menus);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user