diff --git a/Manager.Interfaces/DTO/RessourceDTO.cs b/Manager.Interfaces/DTO/ResourceDTO.cs similarity index 75% rename from Manager.Interfaces/DTO/RessourceDTO.cs rename to Manager.Interfaces/DTO/ResourceDTO.cs index e04e32f..82544bc 100644 --- a/Manager.Interfaces/DTO/RessourceDTO.cs +++ b/Manager.Interfaces/DTO/ResourceDTO.cs @@ -5,10 +5,10 @@ using System.Text; namespace Manager.Interfaces.DTO { - public class RessourceDTO + public class ResourceDTO { public string Id { get; set; } - public RessourceType Type { get; set; } + public ResourceType Type { get; set; } public string Label { get; set; } } } diff --git a/Manager.Interfaces/DTO/RessourceDetailDTO.cs b/Manager.Interfaces/DTO/ResourceDetailDTO.cs similarity index 79% rename from Manager.Interfaces/DTO/RessourceDetailDTO.cs rename to Manager.Interfaces/DTO/ResourceDetailDTO.cs index faeb7ed..9c15a33 100644 --- a/Manager.Interfaces/DTO/RessourceDetailDTO.cs +++ b/Manager.Interfaces/DTO/ResourceDetailDTO.cs @@ -5,10 +5,10 @@ using System.Text; namespace Manager.Interfaces.DTO { - public class RessourceDetailDTO + public class ResourceDetailDTO { public string Id { get; set; } - public RessourceType Type { get; set; } + public ResourceType Type { get; set; } public string Label { get; set; } public DateTime DateCreation { get; set; } public string Data { get; set; } diff --git a/Manager.Interfaces/DTO/SectionDTO.cs b/Manager.Interfaces/DTO/SectionDTO.cs index 4f8e6a1..09e88a2 100644 --- a/Manager.Interfaces/DTO/SectionDTO.cs +++ b/Manager.Interfaces/DTO/SectionDTO.cs @@ -11,7 +11,7 @@ namespace Manager.Interfaces.DTO public string Label { get; set; } // use in manager public List Title { get; set; } public List Description { get; set; } - public string ImageId { get; set; } // == RessourceId + public string ImageId { get; set; } // == ResourceId public string ConfigurationId { get; set; } public bool IsSubSection { get; set; } // true if part of menu type public string ParentId { get; set; } // only if it's an subsection diff --git a/Manager.Interfaces/DTO/SubSection/MapDTO.cs b/Manager.Interfaces/DTO/SubSection/MapDTO.cs index db80b61..1e4ab34 100644 --- a/Manager.Interfaces/DTO/SubSection/MapDTO.cs +++ b/Manager.Interfaces/DTO/SubSection/MapDTO.cs @@ -10,7 +10,7 @@ namespace Manager.Interfaces.DTO public int Zoom { get; set; } // Default = 18 public MapType MapType { get; set; } // Default = Hybrid public List Points { get; set; } - public string Icon { get; set; } // url to ressource id (local) or on internet + public string Icon { get; set; } // url to resource id (local) or on internet } public class GeoPointDTO @@ -18,8 +18,8 @@ namespace Manager.Interfaces.DTO public int Id { get; set; } public List Title { get; set; } public List Description { get; set; } - public string Image { get; set; } // url to ressource id (local) or on internet - public string ImageType { get; set; } // url or ressource + public string Image { get; set; } // url to resource id (local) or on internet + public string ImageType { get; set; } // url or resource public List Text { get; set; } public string Latitude { get; set; } public string Longitude { get; set; } diff --git a/Manager.Interfaces/DTO/SubSection/SliderDTO.cs b/Manager.Interfaces/DTO/SubSection/SliderDTO.cs index 47a01e5..f7961a5 100644 --- a/Manager.Interfaces/DTO/SubSection/SliderDTO.cs +++ b/Manager.Interfaces/DTO/SubSection/SliderDTO.cs @@ -12,6 +12,6 @@ namespace Manager.Interfaces.DTO public class ImageDTO { public List Title { get; set; } public List Description { get; set; } - public string Source { get; set; } // url to ressource id (local) or on internet + public string Source { get; set; } // url to resource id (local) or on internet } } diff --git a/Manager.Interfaces/DTO/SubSection/VideoDTO.cs b/Manager.Interfaces/DTO/SubSection/VideoDTO.cs index a34e8c3..02d62e0 100644 --- a/Manager.Interfaces/DTO/SubSection/VideoDTO.cs +++ b/Manager.Interfaces/DTO/SubSection/VideoDTO.cs @@ -7,6 +7,6 @@ namespace Manager.Interfaces.DTO public class VideoDTO { //public string Title { get; set; } // Dictionary with all languages - public string Source { get; set; } // url to ressource id (local) or on internet + public string Source { get; set; } // url to resource id (local) or on internet } } diff --git a/Manager.Interfaces/DTO/SubSection/WebDTO.cs b/Manager.Interfaces/DTO/SubSection/WebDTO.cs index 40621a3..384a093 100644 --- a/Manager.Interfaces/DTO/SubSection/WebDTO.cs +++ b/Manager.Interfaces/DTO/SubSection/WebDTO.cs @@ -7,6 +7,6 @@ namespace Manager.Interfaces.DTO public class WebDTO { //public string Title { get; set; } // Dictionary with all languages - public string Source { get; set; } // url to ressource id (local) or on internet + public string Source { get; set; } // url to resource id (local) or on internet } } diff --git a/Manager.Interfaces/Models/Ressource.cs b/Manager.Interfaces/Models/Resource.cs similarity index 78% rename from Manager.Interfaces/Models/Ressource.cs rename to Manager.Interfaces/Models/Resource.cs index 6859d2b..919c837 100644 --- a/Manager.Interfaces/Models/Ressource.cs +++ b/Manager.Interfaces/Models/Resource.cs @@ -8,9 +8,9 @@ using System.Text; namespace Manager.Interfaces.Models { /// - /// Ressource Information + /// Resource Information /// - public class Ressource + public class Resource { [BsonId] [BsonRepresentation(MongoDB.Bson.BsonType.ObjectId)] @@ -18,7 +18,7 @@ namespace Manager.Interfaces.Models [BsonElement("Type")] [BsonRequired] - public RessourceType Type { get; set; } + public ResourceType Type { get; set; } [BsonElement("Label")] [BsonRequired] @@ -31,9 +31,9 @@ namespace Manager.Interfaces.Models [BsonRequired] public string Data { get; set; } - public RessourceDTO ToDTO() + public ResourceDTO ToDTO() { - return new RessourceDTO() + return new ResourceDTO() { Id = Id, Label = Label, @@ -41,9 +41,9 @@ namespace Manager.Interfaces.Models }; } - public RessourceDetailDTO ToDetailDTO() + public ResourceDetailDTO ToDetailDTO() { - return new RessourceDetailDTO() + return new ResourceDetailDTO() { Id = Id, Label = Label, @@ -55,7 +55,7 @@ namespace Manager.Interfaces.Models } - public enum RessourceType + public enum ResourceType { Image, Video, diff --git a/Manager.Interfaces/Models/SubSection/Map.cs b/Manager.Interfaces/Models/SubSection/Map.cs index 3f30136..1d7b1f3 100644 --- a/Manager.Interfaces/Models/SubSection/Map.cs +++ b/Manager.Interfaces/Models/SubSection/Map.cs @@ -24,7 +24,7 @@ namespace Manager.Interfaces.Models public List Points { get; set; } [BsonElement("Icon")] - public string Icon { get; set; } // url to ressource id (local) or on internet + public string Icon { get; set; } // url to resource id (local) or on internet public MapDTO ToDetailDTO() { @@ -47,7 +47,7 @@ namespace Manager.Interfaces.Models public int Id { get; set; } public List Title { get; set; } public List Description { get; set; } - public string Image { get; set; } // url to ressource id (local) or on internet + public string Image { get; set; } // url to resource id (local) or on internet public List Text { get; set; } public string Latitude { get; set; } public string Longitude { get; set; } diff --git a/Manager.Interfaces/Models/SubSection/Slider.cs b/Manager.Interfaces/Models/SubSection/Slider.cs index d1d36b7..0e9ebce 100644 --- a/Manager.Interfaces/Models/SubSection/Slider.cs +++ b/Manager.Interfaces/Models/SubSection/Slider.cs @@ -33,7 +33,7 @@ namespace Manager.Interfaces.Models { public List Title { get; set; } public List Description { get; set; } - public string Source { get; set; } // url to ressource id (local) or on internet + public string Source { get; set; } // url to resource id (local) or on internet public ImageDTO ToDTO() { diff --git a/ManagerService/Controllers/DeviceController.cs b/ManagerService/Controllers/DeviceController.cs index dea80f7..9de9ca6 100644 --- a/ManagerService/Controllers/DeviceController.cs +++ b/ManagerService/Controllers/DeviceController.cs @@ -84,7 +84,7 @@ namespace ManagerService.Controllers /// /// Create a new device /// - /// New device info + /// New device info [ProducesResponseType(typeof(DeviceDetailDTO), 200)] [ProducesResponseType(typeof(string), 400)] [ProducesResponseType(typeof(string), 409)] diff --git a/ManagerService/Controllers/ResourceController.cs b/ManagerService/Controllers/ResourceController.cs new file mode 100644 index 0000000..079c198 --- /dev/null +++ b/ManagerService/Controllers/ResourceController.cs @@ -0,0 +1,318 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Drawing.Imaging; +using System.IO; +using System.Linq; +using System.Net.Http.Headers; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading.Tasks; +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 Newtonsoft.Json; +using NSwag.Annotations; + +namespace ManagerService.Controllers +{ + [Authorize] // TODO Add ROLES (Roles = "Admin") + [ApiController, Route("api/[controller]")] + [OpenApiTag("Resource", Description = "Resource management")] + public class ResourceController : ControllerBase + { + private ResourceDatabaseService _resourceService; + private readonly ILogger _logger; + + public ResourceController(ILogger logger, ResourceDatabaseService resourceService) + { + _logger = logger; + _resourceService = resourceService; + } + + /// + /// Get a list of all resources (summary) + /// + [ProducesResponseType(typeof(List), 200)] + [ProducesResponseType(typeof(string), 500)] + [HttpGet] + public ObjectResult Get() + { + try + { + List resources = _resourceService.GetAll(); + + return new OkObjectResult(resources.Select(r => r.ToDTO())); + } + catch (Exception ex) + { + return new ObjectResult(ex.Message) { StatusCode = 500 }; + } + } + + + /// + /// Get a specific resource + /// + /// id resource + [AllowAnonymous] + [ProducesResponseType(typeof(ResourceDetailDTO), 200)] + [ProducesResponseType(typeof(string), 404)] + [ProducesResponseType(typeof(string), 500)] + [HttpGet("{id}/detail")] + public ObjectResult GetDetail(string id) + { + try + { + Resource resource = _resourceService.GetById(id); + + if (resource == null) + throw new KeyNotFoundException("This resource was not found"); + + return new OkObjectResult(resource.ToDetailDTO()); + } + catch (KeyNotFoundException ex) + { + return new NotFoundObjectResult(ex.Message) {}; + } + catch (Exception ex) + { + return new ObjectResult(ex.Message) { StatusCode = 500 }; + } + } + + /// + /// Show a specific resource (as a picture or video stream) + /// + /// id resource + [AllowAnonymous] + [ProducesResponseType(typeof(FileResult), 200)] + [ProducesResponseType(typeof(string), 404)] + [ProducesResponseType(typeof(string), 500)] + [HttpGet("{id}")] + public ActionResult Show(string id) + { + try + { + Resource resource = _resourceService.GetById(id); + + if (resource == null) + throw new KeyNotFoundException("This resource was not found"); + + var file = Convert.FromBase64String(resource.Data); + + if (resource.Type == ResourceType.Image) + { + return new FileContentResult(file, "image/png"); + } + if (resource.Type == ResourceType.Video) + { + return new FileContentResult(file, "application/octet-stream"); + } + + return new FileContentResult(file, "image/png"); + } + catch (KeyNotFoundException ex) + { + return new NotFoundObjectResult(ex.Message) { }; + } + catch (Exception ex) + { + return new ObjectResult(ex.Message) { StatusCode = 500 }; + } + } + + /// + /// Upload a specific resource (picture or video) + /// + /// id resource + [AllowAnonymous] // TODO: TO DELETEEE + [ProducesResponseType(typeof(string), 200)] + [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 + { + try + { + + var test = label; + var test0 = type; + /*if (uploadResource == null) + throw new ArgumentNullException("Resource param is null");*/ + ResourceDetailDTO uploadResource = new ResourceDetailDTO(); + uploadResource.Type = (ResourceType) Enum.Parse(typeof(ResourceType), type); + uploadResource.Label = label; + + var file = Request.Form.Files[0]; + + if (file.Length > 0) + { + var stringResult = ""; + if (file.Length > 0) + { + using (var ms = new MemoryStream()) + { + file.CopyTo(ms); + var fileBytes = ms.ToArray(); + stringResult = Convert.ToBase64String(fileBytes); + } + } + // Todo add some verification ? + Resource resource = new Resource(); + resource.Label = uploadResource.Label; + resource.Type = uploadResource.Type; + resource.DateCreation = DateTime.Now; + resource.Data = stringResult; + Resource resourceCreated = _resourceService.Create(resource); + return Ok(resourceCreated.ToDTO()); + } + else + { + return BadRequest(); + } + } + 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 }; + } + } + + /// + /// Create a new resource + /// + /// New resource info + [ProducesResponseType(typeof(ResourceDetailDTO), 200)] + [ProducesResponseType(typeof(string), 400)] + [ProducesResponseType(typeof(string), 409)] + [ProducesResponseType(typeof(string), 500)] + [HttpPost] + public ObjectResult Create([FromBody] ResourceDetailDTO newResource) + { + try + { + if (newResource == null) + throw new ArgumentNullException("Resource param is null"); + + // Todo add some verification ? + Resource resource = new Resource(); + resource.Label = newResource.Label; + resource.Type = newResource.Type; + resource.DateCreation = DateTime.Now; + resource.Data = newResource.Data; + + Resource resourceCreated = _resourceService.Create(resource); + + return new OkObjectResult(resourceCreated.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 a resource + /// + /// Resource to update + [ProducesResponseType(typeof(ResourceDetailDTO), 200)] + [ProducesResponseType(typeof(string), 400)] + [ProducesResponseType(typeof(string), 404)] + [ProducesResponseType(typeof(string), 500)] + [HttpPut] + public ObjectResult Update([FromBody] ResourceDetailDTO updatedResource) + { + try + { + if (updatedResource == null) + throw new ArgumentNullException("Resource param is null"); + + Resource resource = _resourceService.GetById(updatedResource.Id); + + if (resource == null) + throw new KeyNotFoundException("Resource does not exist"); + + // Todo add some verification ? + resource.Label = updatedResource.Label; + resource.Type = updatedResource.Type; + resource.Data = updatedResource.Data; + + Resource resourceModified = _resourceService.Update(updatedResource.Id, resource); + + return new OkObjectResult(resourceModified.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 a resource + /// + /// Id of resource to delete + [ProducesResponseType(typeof(string), 202)] + [ProducesResponseType(typeof(string), 400)] + [ProducesResponseType(typeof(string), 404)] + [ProducesResponseType(typeof(string), 500)] + [HttpDelete("{id}")] + public ObjectResult Delete(string id) + { + try + { + if (id == null) + throw new ArgumentNullException("Resource param is null"); + + if (!_resourceService.IsExist(id)) + throw new KeyNotFoundException("Resource does not exist"); + + _resourceService.Remove(id); + + return new ObjectResult("The resource 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/RessourceController.cs b/ManagerService/Controllers/RessourceController.cs deleted file mode 100644 index 22ea333..0000000 --- a/ManagerService/Controllers/RessourceController.cs +++ /dev/null @@ -1,248 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Drawing; -using System.Drawing.Imaging; -using System.IO; -using System.Linq; -using System.Threading.Tasks; -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("Ressource", Description = "Ressource management")] - public class RessourceController : ControllerBase - { - private RessourceDatabaseService _ressourceService; - private readonly ILogger _logger; - - public RessourceController(ILogger logger, RessourceDatabaseService ressourceService) - { - _logger = logger; - _ressourceService = ressourceService; - } - - /// - /// Get a list of all ressources (summary) - /// - [ProducesResponseType(typeof(List), 200)] - [ProducesResponseType(typeof(string), 500)] - [HttpGet] - public ObjectResult Get() - { - try - { - List ressources = _ressourceService.GetAll(); - - return new OkObjectResult(ressources.Select(r => r.ToDTO())); - } - catch (Exception ex) - { - return new ObjectResult(ex.Message) { StatusCode = 500 }; - } - } - - - /// - /// Get a specific ressource - /// - /// id ressource - [AllowAnonymous] - [ProducesResponseType(typeof(RessourceDetailDTO), 200)] - [ProducesResponseType(typeof(string), 404)] - [ProducesResponseType(typeof(string), 500)] - [HttpGet("{id}/detail")] - public ObjectResult GetDetail(string id) - { - try - { - Ressource ressource = _ressourceService.GetById(id); - - if (ressource == null) - throw new KeyNotFoundException("This ressource was not found"); - - return new OkObjectResult(ressource.ToDetailDTO()); - } - catch (KeyNotFoundException ex) - { - return new NotFoundObjectResult(ex.Message) {}; - } - catch (Exception ex) - { - return new ObjectResult(ex.Message) { StatusCode = 500 }; - } - } - - /// - /// Show a specific ressource (as a picture or video stream) - /// - /// id ressource - [AllowAnonymous] - [ProducesResponseType(typeof(FileStreamResult), 200)] - [ProducesResponseType(typeof(string), 404)] - [ProducesResponseType(typeof(string), 500)] - [HttpGet("{id}")] - public ActionResult Show(string id) - { - try - { - Ressource ressource = _ressourceService.GetById(id); - - if (ressource == null) - throw new KeyNotFoundException("This ressource was not found"); - - switch (ressource.Type) { - case RessourceType.Image: - return new FileStreamResult(System.IO.File.OpenRead(ressource.Data), "image/jpeg"); - case RessourceType.Video: - return PhysicalFile(@"d:\test\somemovie.mp4", "application/octet-stream"); // TODO ! - default: - return new OkObjectResult(ressource.ToDetailDTO()); - } - } - catch (KeyNotFoundException ex) - { - return new NotFoundObjectResult(ex.Message) { }; - } - catch (Exception ex) - { - return new ObjectResult(ex.Message) { StatusCode = 500 }; - } - } - - // TODO upload ! - - /// - /// Create a new ressource - /// - /// New ressource info - [ProducesResponseType(typeof(RessourceDetailDTO), 200)] - [ProducesResponseType(typeof(string), 400)] - [ProducesResponseType(typeof(string), 409)] - [ProducesResponseType(typeof(string), 500)] - [HttpPost] - public ObjectResult Create([FromBody] RessourceDetailDTO newRessource) - { - try - { - if (newRessource == null) - throw new ArgumentNullException("Ressource param is null"); - - // Todo add some verification ? - Ressource ressource = new Ressource(); - ressource.Label = newRessource.Label; - ressource.Type = newRessource.Type; - ressource.DateCreation = DateTime.Now; - ressource.Data = newRessource.Data; - - Ressource ressourceCreated = _ressourceService.Create(ressource); - - return new OkObjectResult(ressourceCreated.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 a ressource - /// - /// Ressource to update - [ProducesResponseType(typeof(RessourceDetailDTO), 200)] - [ProducesResponseType(typeof(string), 400)] - [ProducesResponseType(typeof(string), 404)] - [ProducesResponseType(typeof(string), 500)] - [HttpPut] - public ObjectResult Update([FromBody] RessourceDetailDTO updatedRessource) - { - try - { - if (updatedRessource == null) - throw new ArgumentNullException("Ressource param is null"); - - Ressource ressource = _ressourceService.GetById(updatedRessource.Id); - - if (ressource == null) - throw new KeyNotFoundException("Ressource does not exist"); - - // Todo add some verification ? - ressource.Label = updatedRessource.Label; - ressource.Type = updatedRessource.Type; - ressource.Data = updatedRessource.Data; - - Ressource ressourceModified = _ressourceService.Update(updatedRessource.Id, ressource); - - return new OkObjectResult(ressourceModified.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 a ressource - /// - /// Id of ressource to delete - [ProducesResponseType(typeof(string), 202)] - [ProducesResponseType(typeof(string), 400)] - [ProducesResponseType(typeof(string), 404)] - [ProducesResponseType(typeof(string), 500)] - [HttpDelete("{id}")] - public ObjectResult Delete(string id) - { - try - { - if (id == null) - throw new ArgumentNullException("Ressource param is null"); - - if (!_ressourceService.IsExist(id)) - throw new KeyNotFoundException("Ressource does not exist"); - - _ressourceService.Remove(id); - - return new ObjectResult("The ressource 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/Properties/launchSettings.json b/ManagerService/Properties/launchSettings.json index b3e2c0e..d267a00 100644 --- a/ManagerService/Properties/launchSettings.json +++ b/ManagerService/Properties/launchSettings.json @@ -4,7 +4,7 @@ "anonymousAuthentication": true, "iisExpress": { "applicationUrl": "http://localhost:50185", - "sslPort": 44339 + "sslPort": 44316 } }, "$schema": "http://json.schemastore.org/launchsettings.json", diff --git a/ManagerService/Services/ResourceDatabaseService.cs b/ManagerService/Services/ResourceDatabaseService.cs new file mode 100644 index 0000000..6375d66 --- /dev/null +++ b/ManagerService/Services/ResourceDatabaseService.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 ResourceDatabaseService + { + private readonly IMongoCollection _Resources; + + public ResourceDatabaseService(IConfiguration config) + { + var client = new MongoClient(config.GetConnectionString("TabletDb")); + var database = client.GetDatabase("TabletDb"); + _Resources = database.GetCollection("Resources"); + } + public List GetAll() + { + return _Resources.Find(r => true).ToList(); + } + + public Resource GetByType(ResourceType type) + { + return _Resources.Find(r => r.Type == type).FirstOrDefault(); + } + + public Resource GetById(string id) + { + return _Resources.Find(r => r.Id == id).FirstOrDefault(); + } + + public bool IsExist(string id) + { + return _Resources.Find(r => r.Id == id).FirstOrDefault() != null ? true : false; + } + + public Resource Create(Resource resource) + { + _Resources.InsertOne(resource); + return resource; + } + + public Resource Update(string id, Resource resourceIn) + { + _Resources.ReplaceOne(r => r.Id == id, resourceIn); + return resourceIn; + } + + public void Remove(string id) + { + _Resources.DeleteOne(r => r.Id == id); + } + + } +} diff --git a/ManagerService/Services/RessourceDatabaseService.cs b/ManagerService/Services/RessourceDatabaseService.cs deleted file mode 100644 index be4e923..0000000 --- a/ManagerService/Services/RessourceDatabaseService.cs +++ /dev/null @@ -1,59 +0,0 @@ -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 RessourceDatabaseService - { - private readonly IMongoCollection _Ressources; - - public RessourceDatabaseService(IConfiguration config) - { - var client = new MongoClient(config.GetConnectionString("TabletDb")); - var database = client.GetDatabase("TabletDb"); - _Ressources = database.GetCollection("Ressources"); - } - public List GetAll() - { - return _Ressources.Find(r => true).ToList(); - } - - public Ressource GetByType(RessourceType type) - { - return _Ressources.Find(r => r.Type == type).FirstOrDefault(); - } - - public Ressource GetById(string id) - { - return _Ressources.Find(r => r.Id == id).FirstOrDefault(); - } - - public bool IsExist(string id) - { - return _Ressources.Find(r => r.Id == id).FirstOrDefault() != null ? true : false; - } - - public Ressource Create(Ressource ressource) - { - _Ressources.InsertOne(ressource); - return ressource; - } - - public Ressource Update(string id, Ressource ressourceIn) - { - _Ressources.ReplaceOne(r => r.Id == id, ressourceIn); - return ressourceIn; - } - - public void Remove(string id) - { - _Ressources.DeleteOne(r => r.Id == id); - } - - } -} diff --git a/ManagerService/Startup.cs b/ManagerService/Startup.cs index 560c700..b5419b4 100644 --- a/ManagerService/Startup.cs +++ b/ManagerService/Startup.cs @@ -9,10 +9,12 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Diagnostics; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.HttpsPolicy; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.FileProviders; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using Microsoft.IdentityModel.Tokens; @@ -21,6 +23,7 @@ using NSwag.Generation.AspNetCore; using NSwag.Generation.Processors.Security; using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Text; using System.Text.Json.Serialization; @@ -59,6 +62,12 @@ namespace ManagerService .AllowAnyHeader(); })); + services.Configure(o => { + o.ValueLengthLimit = int.MaxValue; + o.MultipartBodyLengthLimit = int.MaxValue; + o.MemoryBufferThreshold = int.MaxValue; + }); + // Authentication var tokensConfiguration = Configuration.GetSection("Tokens"); @@ -103,7 +112,7 @@ namespace ManagerService services.AddScoped(); services.AddScoped(); services.AddScoped(); - services.AddScoped(); + services.AddScoped(); services.AddScoped(); }