From 3b6c480cc6401a86f5df34d8310db635aa117088 Mon Sep 17 00:00:00 2001 From: Fransolet Thomas Date: Thu, 6 Oct 2022 17:07:11 +0200 Subject: [PATCH] Add instance model, dto, controller and service + update other objects and controllers --- Manager.Interfaces/DTO/ConfigurationDTO.cs | 1 + Manager.Interfaces/DTO/DeviceDTO.cs | 1 + Manager.Interfaces/DTO/InstanceDTO.cs | 13 ++ Manager.Interfaces/DTO/ResourceDTO.cs | 1 + Manager.Interfaces/DTO/SectionDTO.cs | 1 + Manager.Interfaces/DTO/TokenDTO.cs | 1 + Manager.Interfaces/Models/Configuration.cs | 10 +- Manager.Interfaces/Models/Device.cs | 9 +- Manager.Interfaces/Models/Instance.cs | 36 +++ Manager.Interfaces/Models/Resource.cs | 4 + Manager.Interfaces/Models/Section.cs | 4 + Manager.Interfaces/Models/User.cs | 4 + .../Controllers/ConfigurationController.cs | 5 +- .../Controllers/DeviceController.cs | 5 +- .../Controllers/InstanceController.cs | 216 ++++++++++++++++++ .../Controllers/ResourceController.cs | 23 +- .../Controllers/SectionController.cs | 5 +- .../Services/ConfigurationDatabaseService.cs | 4 +- .../Services/DeviceDatabaseService.cs | 4 +- .../Services/InstanceDatabaseService.cs | 59 +++++ .../Services/ResourceDatabaseService.cs | 4 +- .../Services/SectionDatabaseService.cs | 4 +- ManagerService/Services/TokensService.cs | 3 +- .../Services/UserDatabaseService.cs | 13 +- ManagerService/Startup.cs | 1 + ManagerService/appsettings.json | 4 +- 26 files changed, 399 insertions(+), 36 deletions(-) create mode 100644 Manager.Interfaces/DTO/InstanceDTO.cs create mode 100644 Manager.Interfaces/Models/Instance.cs create mode 100644 ManagerService/Controllers/InstanceController.cs create mode 100644 ManagerService/Services/InstanceDatabaseService.cs diff --git a/Manager.Interfaces/DTO/ConfigurationDTO.cs b/Manager.Interfaces/DTO/ConfigurationDTO.cs index 5f4a318..7a10f23 100644 --- a/Manager.Interfaces/DTO/ConfigurationDTO.cs +++ b/Manager.Interfaces/DTO/ConfigurationDTO.cs @@ -20,5 +20,6 @@ namespace Manager.Interfaces.DTO public bool isOffline { get; set; } // MyVisit - True if MyVisit is full offline /*public string latitude { get; set; } // MyVisit - latitude of visit ? (MyVisit) public string longitude { get; set; } // MyVisit - True if for mobile (MyVisit)*/ + public string instanceId { get; set; } } } diff --git a/Manager.Interfaces/DTO/DeviceDTO.cs b/Manager.Interfaces/DTO/DeviceDTO.cs index 0cd62f5..0d991fa 100644 --- a/Manager.Interfaces/DTO/DeviceDTO.cs +++ b/Manager.Interfaces/DTO/DeviceDTO.cs @@ -16,6 +16,7 @@ namespace Manager.Interfaces.DTO public bool connected{ get; set; } public DateTime dateCreation{ get; set; } public DateTime dateUpdate { get; set; } + public string instanceId { get; set; } } public class DeviceDetailDTO : DeviceDTO diff --git a/Manager.Interfaces/DTO/InstanceDTO.cs b/Manager.Interfaces/DTO/InstanceDTO.cs new file mode 100644 index 0000000..5e371a5 --- /dev/null +++ b/Manager.Interfaces/DTO/InstanceDTO.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Manager.Interfaces.DTO +{ + public class InstanceDTO + { + public string id { get; set; } + public string name { get; set; } + public DateTime dateCreation { get; set; } + } +} diff --git a/Manager.Interfaces/DTO/ResourceDTO.cs b/Manager.Interfaces/DTO/ResourceDTO.cs index 331c4d7..e9ed14d 100644 --- a/Manager.Interfaces/DTO/ResourceDTO.cs +++ b/Manager.Interfaces/DTO/ResourceDTO.cs @@ -12,5 +12,6 @@ namespace Manager.Interfaces.DTO public string label { get; set; } public DateTime dateCreation { get; set; } public string data { get; set; } + public string instanceId { get; set; } } } diff --git a/Manager.Interfaces/DTO/SectionDTO.cs b/Manager.Interfaces/DTO/SectionDTO.cs index 273dadf..d3dfbd1 100644 --- a/Manager.Interfaces/DTO/SectionDTO.cs +++ b/Manager.Interfaces/DTO/SectionDTO.cs @@ -20,5 +20,6 @@ namespace Manager.Interfaces.DTO public string data { get; set; } // == Include section type info public DateTime dateCreation { get; set; } // == Include section type info public int order { get; set; } // Order to show + public string instanceId { get; set; } } } diff --git a/Manager.Interfaces/DTO/TokenDTO.cs b/Manager.Interfaces/DTO/TokenDTO.cs index 7a74060..6a0b277 100644 --- a/Manager.Interfaces/DTO/TokenDTO.cs +++ b/Manager.Interfaces/DTO/TokenDTO.cs @@ -10,5 +10,6 @@ namespace Manager.Interfaces.DTO public string token_type { get; set; } public int expires_in { get; set; } public DateTimeOffset expiration { get; set; } + public string instanceId { get; set; } } } diff --git a/Manager.Interfaces/Models/Configuration.cs b/Manager.Interfaces/Models/Configuration.cs index d7ad02f..9b337d0 100644 --- a/Manager.Interfaces/Models/Configuration.cs +++ b/Manager.Interfaces/Models/Configuration.cs @@ -50,6 +50,10 @@ namespace Manager.Interfaces.Models [BsonElement("IsOffline")] public bool IsOffline { get; set; } + [BsonElement("InstanceId")] + [BsonRequired] + public string InstanceId { get; set; } + public ConfigurationDTO ToDTO() { return new ConfigurationDTO() @@ -65,7 +69,8 @@ namespace Manager.Interfaces.Models secondaryColor = SecondaryColor, isMobile = IsMobile, isTablet = IsTablet, - isOffline = IsOffline + isOffline = IsOffline, + instanceId = InstanceId, }; } @@ -85,7 +90,8 @@ namespace Manager.Interfaces.Models isTablet = IsTablet, isOffline = IsOffline, sections = sections, - resources = resources + resources = resources, + instanceId = InstanceId, }; } } diff --git a/Manager.Interfaces/Models/Device.cs b/Manager.Interfaces/Models/Device.cs index 07997e3..e862a3d 100644 --- a/Manager.Interfaces/Models/Device.cs +++ b/Manager.Interfaces/Models/Device.cs @@ -60,6 +60,9 @@ namespace Manager.Interfaces.Models [BsonElement("LastConnectionLevel")] public DateTime LastConnectionLevel { get; set; } + [BsonElement("InstanceId")] + [BsonRequired] + public string InstanceId { get; set; } public DeviceDTO ToDTO() { @@ -74,7 +77,8 @@ namespace Manager.Interfaces.Models configuration = Configuration, configurationId = ConfigurationId, dateUpdate = DateUpdate, - dateCreation = DateCreation + dateCreation = DateCreation, + instanceId = InstanceId }; } @@ -95,7 +99,8 @@ namespace Manager.Interfaces.Models batteryLevel = BatteryLevel, lastBatteryLevel = LastBatteryLevel, dateUpdate = DateUpdate, - dateCreation = DateCreation + dateCreation = DateCreation, + instanceId = InstanceId }; } } diff --git a/Manager.Interfaces/Models/Instance.cs b/Manager.Interfaces/Models/Instance.cs new file mode 100644 index 0000000..bcc0cf5 --- /dev/null +++ b/Manager.Interfaces/Models/Instance.cs @@ -0,0 +1,36 @@ +using Manager.Interfaces.DTO; +using MongoDB.Bson.Serialization.Attributes; +using System; +using System.Collections.Generic; +using System.Text; + +namespace Manager.Interfaces.Models +{ + /// + /// Instance Information + /// + public class Instance + { + [BsonId] + [BsonRepresentation(MongoDB.Bson.BsonType.ObjectId)] + public string Id { get; set; } + + [BsonElement("Name")] + [BsonRequired] + public string Name { get; set; } // UNIQUE !.. + + [BsonElement("DateCreation")] + public DateTime DateCreation { get; set; } + + public InstanceDTO ToDTO() + { + return new InstanceDTO() + { + id = Id, + name = Name, + dateCreation = DateCreation + }; + } + + } +} diff --git a/Manager.Interfaces/Models/Resource.cs b/Manager.Interfaces/Models/Resource.cs index ecc7826..5a505d8 100644 --- a/Manager.Interfaces/Models/Resource.cs +++ b/Manager.Interfaces/Models/Resource.cs @@ -31,6 +31,10 @@ namespace Manager.Interfaces.Models [BsonRequired] public string Data { get; set; } + [BsonElement("InstanceId")] + [BsonRequired] + public string InstanceId { get; set; } + public ResourceDTO ToDTO(bool isExport = false) { return new ResourceDTO() diff --git a/Manager.Interfaces/Models/Section.cs b/Manager.Interfaces/Models/Section.cs index 5e7fd98..c679f72 100644 --- a/Manager.Interfaces/Models/Section.cs +++ b/Manager.Interfaces/Models/Section.cs @@ -61,6 +61,10 @@ namespace Manager.Interfaces.Models [BsonRequired] public string Data { get; set; } // Json encapsulated section info + [BsonElement("InstanceId")] + [BsonRequired] + public string InstanceId { get; set; } + public SectionDTO ToDTO() { return new SectionDTO() diff --git a/Manager.Interfaces/Models/User.cs b/Manager.Interfaces/Models/User.cs index c06d2c5..29d1ff0 100644 --- a/Manager.Interfaces/Models/User.cs +++ b/Manager.Interfaces/Models/User.cs @@ -38,6 +38,10 @@ namespace Manager.Interfaces.Models [BsonElement("DateCreation")] public DateTime DateCreation { get; set; } + [BsonElement("InstanceId")] + [BsonRequired] + public string InstanceId { get; set; } + public UserDetailDTO ToDTO() { return new UserDetailDTO() diff --git a/ManagerService/Controllers/ConfigurationController.cs b/ManagerService/Controllers/ConfigurationController.cs index 04dd18e..6f9aa9a 100644 --- a/ManagerService/Controllers/ConfigurationController.cs +++ b/ManagerService/Controllers/ConfigurationController.cs @@ -42,15 +42,16 @@ namespace ManagerService.Controllers /// /// Get a list of all configuration (summary) /// + /// id instance [AllowAnonymous] [ProducesResponseType(typeof(List), 200)] [ProducesResponseType(typeof(string), 500)] [HttpGet] - public ObjectResult Get() + public ObjectResult Get([FromQuery] string instanceId) { try { - List configurations = _configurationService.GetAll(); + List configurations = _configurationService.GetAll(instanceId); return new OkObjectResult(configurations.Select(r => r.ToDTO())); } diff --git a/ManagerService/Controllers/DeviceController.cs b/ManagerService/Controllers/DeviceController.cs index bf041d3..3ee7bc9 100644 --- a/ManagerService/Controllers/DeviceController.cs +++ b/ManagerService/Controllers/DeviceController.cs @@ -37,14 +37,15 @@ namespace ManagerService.Controllers /// /// Get a list of all devices /// + /// id instance [ProducesResponseType(typeof(List), 200)] [ProducesResponseType(typeof(string), 500)] [HttpGet] - public ObjectResult Get() + public ObjectResult Get([FromQuery] string instanceId) { try { - List devices = _deviceService.GetAll(); + List devices = _deviceService.GetAll(instanceId); return new OkObjectResult(devices.Select(d => d.ToDTO())); } diff --git a/ManagerService/Controllers/InstanceController.cs b/ManagerService/Controllers/InstanceController.cs new file mode 100644 index 0000000..f461422 --- /dev/null +++ b/ManagerService/Controllers/InstanceController.cs @@ -0,0 +1,216 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Manager.Framework.Business; +using Manager.Interfaces.DTO; +using Manager.Interfaces.Models; +using Manager.Services; +using ManagerService.Service.Services; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Logging; +using NSwag.Annotations; + +namespace ManagerService.Controllers +{ + [Authorize] // TODO Add ROLES (Roles = "Admin") + [ApiController, Route("api/[controller]")] + [OpenApiTag("Instance", Description = "Instance management")] + public class InstanceController : ControllerBase + { + private InstanceDatabaseService _instanceService; + private UserDatabaseService _userService; + private readonly ILogger _logger; + private readonly ProfileLogic _profileLogic; + + public InstanceController(ILogger logger, InstanceDatabaseService instanceService, UserDatabaseService userService, ProfileLogic profileLogic) + { + _logger = logger; + _instanceService = instanceService; + _userService = userService; + _profileLogic = profileLogic; + } + + /// + /// Get a list of instance + /// + [ProducesResponseType(typeof(List), 200)] + [ProducesResponseType(typeof(string), 500)] + [HttpGet] + public ObjectResult Get() + { + try + { + List instances = _instanceService.GetAll(); + + return new OkObjectResult(instances); + } + catch (Exception ex) + { + return new ObjectResult(ex.Message) { StatusCode = 500 }; + } + } + + + /// + /// Get a specific instance + /// + /// id instance + [ProducesResponseType(typeof(InstanceDTO), 200)] + [ProducesResponseType(typeof(string), 404)] + [ProducesResponseType(typeof(string), 500)] + [HttpGet("{id}")] + public ObjectResult GetDetail(string id) + { + try + { + Instance instance = _instanceService.GetById(id); + + if (instance == null) + throw new KeyNotFoundException("This instance was not found"); + + return new OkObjectResult(instance.ToDTO()); + } + catch (KeyNotFoundException ex) + { + return new NotFoundObjectResult(ex.Message) {}; + } + catch (Exception ex) + { + return new ObjectResult(ex.Message) { StatusCode = 500 }; + } + } + + /// + /// Create an instance + /// + /// New instance info + //[AllowAnonymous] + [ProducesResponseType(typeof(InstanceDTO), 200)] + [ProducesResponseType(typeof(string), 400)] + [ProducesResponseType(typeof(string), 409)] + [ProducesResponseType(typeof(string), 500)] + [HttpPost] + public ObjectResult CreateInstance([FromBody] Instance newInstance) + { + try + { + if (newInstance == null) + throw new ArgumentNullException("instance param is null"); + + newInstance.DateCreation = DateTime.Now; + + List instances = _instanceService.GetAll(); + + if (instances.Select(i => i.Name).Contains(newInstance.Name)) + throw new InvalidOperationException("This name is already used"); + + Instance instanceCreated = _instanceService.Create(newInstance); + + return new OkObjectResult(instanceCreated.ToDTO()); + } + catch (ArgumentNullException ex) + { + return new BadRequestObjectResult(ex.Message) {}; + } + catch (InvalidOperationException ex) + { + return new ConflictObjectResult(ex.Message) {}; + } + catch (Exception ex) + { + return new ObjectResult(ex.Message) { StatusCode = 500 }; + } + } + + + /// + /// Update an instance + /// + /// instance to update + [ProducesResponseType(typeof(InstanceDTO), 200)] + [ProducesResponseType(typeof(string), 400)] + [ProducesResponseType(typeof(string), 404)] + [ProducesResponseType(typeof(string), 500)] + [HttpPut] + public ObjectResult Updateinstance([FromBody] Instance updatedInstance) + { + try + { + if (updatedInstance == null) + throw new ArgumentNullException("instance param is null"); + + Instance instance = _instanceService.GetById(updatedInstance.Id); + + if (instance == null) + throw new KeyNotFoundException("instance does not exist"); + + Instance instanceModified = _instanceService.Update(updatedInstance.Id, instance); + + return new OkObjectResult(instanceModified.ToDTO()); + } + catch (ArgumentNullException ex) + { + return new BadRequestObjectResult(ex.Message) {}; + } + catch (KeyNotFoundException ex) + { + return new NotFoundObjectResult(ex.Message) {}; + } + catch (Exception ex) + { + return new ObjectResult(ex.Message) { StatusCode = 500 }; + } + } + + + /// + /// Delete an instance + /// + /// Id of instance to delete + [ProducesResponseType(typeof(string), 202)] + [ProducesResponseType(typeof(string), 400)] + [ProducesResponseType(typeof(string), 404)] + [ProducesResponseType(typeof(string), 500)] + [HttpDelete("{id}")] + public ObjectResult DeleteInstance(string id) + { + try + { + if (id == null) + throw new ArgumentNullException("instance param is null"); + + Instance instance = _instanceService.GetById(id); + + // Delete all user in instance + List users = _userService.GetByInstanceId(instance.Id); + + foreach(var user in users) + { + _userService.Remove(user.Id); + } + + if (instance == null) + throw new KeyNotFoundException("instance does not exist"); + + _instanceService.Remove(id); + + return new ObjectResult("The instance has been deleted") { StatusCode = 202 }; + + } + catch (ArgumentNullException ex) + { + return new BadRequestObjectResult(ex.Message) { }; + } + catch (KeyNotFoundException ex) + { + return new NotFoundObjectResult(ex.Message) { }; + } + catch (Exception ex) + { + return new ObjectResult(ex.Message) { StatusCode = 500 }; + } + } + } +} diff --git a/ManagerService/Controllers/ResourceController.cs b/ManagerService/Controllers/ResourceController.cs index 0e5fb96..2e9b8e9 100644 --- a/ManagerService/Controllers/ResourceController.cs +++ b/ManagerService/Controllers/ResourceController.cs @@ -39,14 +39,15 @@ namespace ManagerService.Controllers /// /// Get a list of all resources (summary) /// + /// id instance [ProducesResponseType(typeof(List), 200)] [ProducesResponseType(typeof(string), 500)] [HttpGet] - public ObjectResult Get() + public ObjectResult Get([FromQuery] string instanceId) { try { - List resources = _resourceService.GetAll(); + List resources = _resourceService.GetAll(instanceId); return new OkObjectResult(resources.Select(r => r.ToDTO(r.Type == ResourceType.ImageUrl))); } @@ -135,15 +136,12 @@ namespace ManagerService.Controllers [ProducesResponseType(typeof(string), 404)] [ProducesResponseType(typeof(string), 500)] [HttpPost("upload"), DisableRequestSizeLimit] - public IActionResult Upload([FromForm] string label, [FromForm] string type) // Create but with local //[FromBody] ResourceDetailDTO uploadResource + public IActionResult Upload([FromForm] string label, [FromForm] string type, [FromForm] string instanceId) // Create but with local //[FromBody] ResourceDetailDTO uploadResource { try { - if (label == null || type == null) + if (label == null || type == null || instanceId == null) throw new ArgumentNullException("One of resource params is null"); - ResourceDTO uploadResource = new ResourceDTO(); - uploadResource.type = (ResourceType) Enum.Parse(typeof(ResourceType), type); - uploadResource.label = label; List resources = new List(); @@ -163,10 +161,11 @@ namespace ManagerService.Controllers } // Todo add some verification ? Resource resource = new Resource(); - resource.Label = uploadResource.label; - resource.Type = uploadResource.type; + resource.Label = label; + resource.Type = (ResourceType)Enum.Parse(typeof(ResourceType), type); resource.DateCreation = DateTime.Now; resource.Data = stringResult; + resource.InstanceId = instanceId; Resource resourceCreated = _resourceService.Create(resource); resources.Add(resourceCreated); } @@ -209,6 +208,7 @@ namespace ManagerService.Controllers resource.Type = newResource.type; resource.DateCreation = DateTime.Now; resource.Data = newResource.data; + resource.InstanceId = newResource.instanceId; Resource resourceCreated = _resourceService.Create(resource); @@ -290,12 +290,13 @@ namespace ManagerService.Controllers if (id == null) throw new ArgumentNullException("Resource param is null"); - if (!_resourceService.IsExist(id)) + var ressource = _resourceService.GetById(id); + if (ressource == null) throw new KeyNotFoundException("Resource does not exist"); // Delete all resource occurence - foreach (var section in _sectionService.GetAll()) + foreach (var section in _sectionService.GetAll(ressource.InstanceId)) { if (section.ImageId == id) { diff --git a/ManagerService/Controllers/SectionController.cs b/ManagerService/Controllers/SectionController.cs index 0b974fc..1eac2c2 100644 --- a/ManagerService/Controllers/SectionController.cs +++ b/ManagerService/Controllers/SectionController.cs @@ -35,14 +35,15 @@ namespace ManagerService.Controllers /// /// Get a list of all section (summary) /// + /// id instance [ProducesResponseType(typeof(List), 200)] [ProducesResponseType(typeof(string), 500)] [HttpGet] - public ObjectResult Get() + public ObjectResult Get([FromQuery] string instanceId) { try { - List
sections = _sectionService.GetAll(); + List
sections = _sectionService.GetAll(instanceId); return new OkObjectResult(sections.Select(r => r.ToDTO())); } diff --git a/ManagerService/Services/ConfigurationDatabaseService.cs b/ManagerService/Services/ConfigurationDatabaseService.cs index 45e416b..19bd1c4 100644 --- a/ManagerService/Services/ConfigurationDatabaseService.cs +++ b/ManagerService/Services/ConfigurationDatabaseService.cs @@ -18,9 +18,9 @@ namespace Manager.Services var database = client.GetDatabase("TabletDb"); _Configurations = database.GetCollection("Configurations"); } - public List GetAll() + public List GetAll(string instanceId) { - return _Configurations.Find(d => true).ToList(); + return _Configurations.Find(d => d.InstanceId == instanceId).ToList(); } public Configuration GetById(string id) diff --git a/ManagerService/Services/DeviceDatabaseService.cs b/ManagerService/Services/DeviceDatabaseService.cs index da39b09..37d2d1b 100644 --- a/ManagerService/Services/DeviceDatabaseService.cs +++ b/ManagerService/Services/DeviceDatabaseService.cs @@ -19,9 +19,9 @@ namespace Manager.Services _Devices = database.GetCollection("Devices"); } - public List GetAll() + public List GetAll(string instanceId) { - return _Devices.Find(d => true).ToList(); + return _Devices.Find(d => d.InstanceId == instanceId).ToList(); } public List GetAllConnected() diff --git a/ManagerService/Services/InstanceDatabaseService.cs b/ManagerService/Services/InstanceDatabaseService.cs new file mode 100644 index 0000000..6b6e8c7 --- /dev/null +++ b/ManagerService/Services/InstanceDatabaseService.cs @@ -0,0 +1,59 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Manager.Interfaces.Models; +using Microsoft.Extensions.Configuration; +using MongoDB.Driver; + +namespace Manager.Services +{ + public class InstanceDatabaseService + { + private readonly IMongoCollection _Instances; + + public InstanceDatabaseService(IConfiguration config) + { + var client = new MongoClient(config.GetConnectionString("TabletDb")); + var database = client.GetDatabase("TabletDb"); + _Instances = database.GetCollection("Instances"); + } + public List GetAll() + { + return _Instances.Find(m => true).ToList(); + } + + public Instance GetByName(string name) + { + return _Instances.Find(i => i.Name == name).FirstOrDefault(); + } + + public Instance GetById(string id) + { + return _Instances.Find(i => i.Id == id).FirstOrDefault(); + } + + public bool IsExist(string id) + { + return _Instances.Find(i => i.Id == id).FirstOrDefault() != null ? true : false; + } + + public Instance Create(Instance instance) + { + _Instances.InsertOne(instance); + return instance; + } + + public Instance Update(string id, Instance instanceIn) + { + _Instances.ReplaceOne(instance => instance.Id == id, instanceIn); + return instanceIn; + } + + public void Remove(string id) + { + _Instances.DeleteOne(instance => instance.Id == id); + } + + } +} diff --git a/ManagerService/Services/ResourceDatabaseService.cs b/ManagerService/Services/ResourceDatabaseService.cs index 6375d66..e1f062e 100644 --- a/ManagerService/Services/ResourceDatabaseService.cs +++ b/ManagerService/Services/ResourceDatabaseService.cs @@ -18,9 +18,9 @@ namespace Manager.Services var database = client.GetDatabase("TabletDb"); _Resources = database.GetCollection("Resources"); } - public List GetAll() + public List GetAll(string instanceId) { - return _Resources.Find(r => true).ToList(); + return _Resources.Find(r => r.InstanceId == instanceId).ToList(); } public Resource GetByType(ResourceType type) diff --git a/ManagerService/Services/SectionDatabaseService.cs b/ManagerService/Services/SectionDatabaseService.cs index 01f78c2..6024f00 100644 --- a/ManagerService/Services/SectionDatabaseService.cs +++ b/ManagerService/Services/SectionDatabaseService.cs @@ -19,9 +19,9 @@ namespace Manager.Services _Sections = database.GetCollection
("Sections"); } - public List
GetAll() + public List
GetAll(string instanceId) { - return _Sections.Find(s => !s.IsSubSection).ToList(); + return _Sections.Find(s => !s.IsSubSection && s.InstanceId == instanceId).ToList(); } public List
GetAllFromConfiguration(string configurationId) diff --git a/ManagerService/Services/TokensService.cs b/ManagerService/Services/TokensService.cs index afd22bd..3b37266 100644 --- a/ManagerService/Services/TokensService.cs +++ b/ManagerService/Services/TokensService.cs @@ -79,7 +79,8 @@ namespace ManagerService.Service.Services expires_in = _tokenSettings.AccessTokenExpiration * 60, expiration = new DateTimeOffset(token.ValidTo), token_type = "Bearer", - scope = Security.Scope + scope = Security.Scope, + instanceId = user.InstanceId }; } catch (UnauthorizedAccessException ex) diff --git a/ManagerService/Services/UserDatabaseService.cs b/ManagerService/Services/UserDatabaseService.cs index 5596876..cf3ab2b 100644 --- a/ManagerService/Services/UserDatabaseService.cs +++ b/ManagerService/Services/UserDatabaseService.cs @@ -20,22 +20,27 @@ namespace Manager.Services } public List GetAll() { - return _Users.Find(m => true).ToList(); + return _Users.Find(u => true).ToList(); } public User GetByEmail(string email) { - return _Users.Find(m => m.Email == email).FirstOrDefault(); + return _Users.Find(u => u.Email == email).FirstOrDefault(); } public User GetById(string id) { - return _Users.Find(m => m.Id == id).FirstOrDefault(); + return _Users.Find(u => u.Id == id).FirstOrDefault(); + } + + public List GetByInstanceId(string id) + { + return _Users.Find(u => u.InstanceId == id).ToList(); } public bool IsExist(string id) { - return _Users.Find(d => d.Id == id).FirstOrDefault() != null ? true : false; + return _Users.Find(u => u.Id == id).FirstOrDefault() != null ? true : false; } public User Create(User user) diff --git a/ManagerService/Startup.cs b/ManagerService/Startup.cs index 243042c..862a43d 100644 --- a/ManagerService/Startup.cs +++ b/ManagerService/Startup.cs @@ -141,6 +141,7 @@ namespace ManagerService services.AddScoped(); services.AddScoped(); services.AddScoped(); + services.AddScoped(); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. diff --git a/ManagerService/appsettings.json b/ManagerService/appsettings.json index 6c4d2e4..1538c85 100644 --- a/ManagerService/appsettings.json +++ b/ManagerService/appsettings.json @@ -2,9 +2,9 @@ "ConnectionStrings": { //"TabletDb": "mongodb://admin:MioTech4ever!@localhost:27017" //DEV //"TabletDb": "mongodb://admin:MioTech4ever!@localhost:27017", //PROD - Thomas - //"TabletDb": "mongodb://admin:MioTech4ever!@192.168.31.140:27017" //PROD - Thomas + "TabletDb": "mongodb://admin:MioTech4ever!@192.168.31.140:27017" //PROD - Thomas //"TabletDb": "mongodb://admin:mdlf2021!@localhost:27017" //PROD MDLF - "TabletDb": "mongodb://admin:MyMuseum2022!@51.77.222.154:27017" //PROD MyMuseum + //"TabletDb": "mongodb://admin:MyMuseum2022!@51.77.222.154:27017" //PROD MyMuseum }, "Logging": { "LogLevel": {