First version of all structure
This commit is contained in:
parent
629e9c31f7
commit
1a1d7ccd9e
16
Manager.Interfaces/DTO/DisplayDTO.cs
Normal file
16
Manager.Interfaces/DTO/DisplayDTO.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Manager.Interfaces.DTO
|
||||
{
|
||||
public class DisplayDTO
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public string Label { get; set; }
|
||||
public List<string> SectionIds { get; set; }
|
||||
public string PrimaryColor { get; set; }
|
||||
public string SecondaryColor { get; set; }
|
||||
public DateTime DateCreation { get; set; }
|
||||
}
|
||||
}
|
||||
14
Manager.Interfaces/DTO/RessourceDTO.cs
Normal file
14
Manager.Interfaces/DTO/RessourceDTO.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using Manager.Interfaces.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Manager.Interfaces.DTO
|
||||
{
|
||||
public class RessourceDTO
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public RessourceType Type { get; set; }
|
||||
public string Label { get; set; }
|
||||
}
|
||||
}
|
||||
16
Manager.Interfaces/DTO/RessourceDetailDTO.cs
Normal file
16
Manager.Interfaces/DTO/RessourceDetailDTO.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using Manager.Interfaces.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Manager.Interfaces.DTO
|
||||
{
|
||||
public class RessourceDetailDTO
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public RessourceType Type { get; set; }
|
||||
public string Label { get; set; }
|
||||
public DateTime DateCreation { get; set; }
|
||||
public string Data { get; set; }
|
||||
}
|
||||
}
|
||||
18
Manager.Interfaces/DTO/SectionDTO.cs
Normal file
18
Manager.Interfaces/DTO/SectionDTO.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using Manager.Interfaces.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Manager.Interfaces.DTO
|
||||
{
|
||||
public class SectionDTO
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public string Label { get; set; } // Dictionary<string, object> with all languages
|
||||
public string ImageId { get; set; } // == RessourceId
|
||||
public string Data { get; set; } // == RessourceId
|
||||
public bool IsSubSection { get; set; } // true if part of menu type
|
||||
public string ParentId { get; set; } // only if it's an subsection
|
||||
public SectionType Type { get; set; } // !! If IsSubSection == true => Type can't not be menu !
|
||||
}
|
||||
}
|
||||
33
Manager.Interfaces/DTO/SubSection/Map.cs
Normal file
33
Manager.Interfaces/DTO/SubSection/Map.cs
Normal file
@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Manager.Interfaces.DTO.SubSection
|
||||
{
|
||||
public class Map
|
||||
{
|
||||
public int Zoom { get; set; } // Default = 18
|
||||
public MapType Type { get; set; } // Default = Hybrid
|
||||
public List<GeoPoint> Points { get; set; }
|
||||
public string Icon { get; set; } // url to ressource id (local) or on internet
|
||||
}
|
||||
|
||||
public class GeoPoint
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Title { get; set; } // Dictionary<string, object> with all languages
|
||||
public string Description { get; set; } // Dictionary<string, object> with all languages
|
||||
public string Image { get; set; } // url to ressource id (local) or on internet
|
||||
public string Text { get; set; } // Dictionary<string, object> with all languages
|
||||
public string Latitude { get; set; }
|
||||
public string Longitude { get; set; }
|
||||
}
|
||||
|
||||
public enum MapType {
|
||||
none,
|
||||
normal,
|
||||
satellite,
|
||||
terrain,
|
||||
hybrid
|
||||
}
|
||||
}
|
||||
12
Manager.Interfaces/DTO/SubSection/Menu.cs
Normal file
12
Manager.Interfaces/DTO/SubSection/Menu.cs
Normal file
@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Manager.Interfaces.DTO.SubSection
|
||||
{
|
||||
public class Menu
|
||||
{
|
||||
public string Title { get; set; } // Dictionary<string, object> with all languages
|
||||
public List<SectionDTO> Sections { get; set; }
|
||||
}
|
||||
}
|
||||
18
Manager.Interfaces/DTO/SubSection/Slider.cs
Normal file
18
Manager.Interfaces/DTO/SubSection/Slider.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Manager.Interfaces.DTO.SubSection
|
||||
{
|
||||
public class Slider
|
||||
{
|
||||
public string Title { get; set; } // Dictionary<string, object> with all languages
|
||||
public List<Image> Images { get; set; }
|
||||
}
|
||||
|
||||
public class Image {
|
||||
public string Title { get; set; } // Dictionary<string, object> with all languages
|
||||
public string Description { get; set; } // Dictionary<string, object> with all languages
|
||||
public string Source { get; set; } // url to ressource id (local) or on internet
|
||||
}
|
||||
}
|
||||
12
Manager.Interfaces/DTO/SubSection/Video.cs
Normal file
12
Manager.Interfaces/DTO/SubSection/Video.cs
Normal file
@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Manager.Interfaces.DTO.SubSection
|
||||
{
|
||||
public class Video
|
||||
{
|
||||
public string Title { get; set; } // Dictionary<string, object> with all languages
|
||||
public string Source { get; set; } // url to ressource id (local) or on internet
|
||||
}
|
||||
}
|
||||
12
Manager.Interfaces/DTO/SubSection/Web.cs
Normal file
12
Manager.Interfaces/DTO/SubSection/Web.cs
Normal file
@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Manager.Interfaces.DTO.SubSection
|
||||
{
|
||||
public class Web
|
||||
{
|
||||
public string Title { get; set; } // Dictionary<string, object> with all languages
|
||||
public string Source { get; set; } // url to ressource id (local) or on internet
|
||||
}
|
||||
}
|
||||
49
Manager.Interfaces/Models/Display.cs
Normal file
49
Manager.Interfaces/Models/Display.cs
Normal file
@ -0,0 +1,49 @@
|
||||
using Manager.Interfaces.DTO;
|
||||
using MongoDB.Bson.Serialization.Attributes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Manager.Interfaces.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// Display Information
|
||||
/// </summary>
|
||||
public class Display
|
||||
{
|
||||
[BsonId]
|
||||
[BsonRepresentation(MongoDB.Bson.BsonType.ObjectId)]
|
||||
public string Id { get; set; }
|
||||
|
||||
[BsonElement("Label")]
|
||||
[BsonRequired]
|
||||
public string Label { get; set; }
|
||||
|
||||
[BsonElement("PrimaryColor")]
|
||||
public string PrimaryColor { get; set; }
|
||||
|
||||
[BsonElement("SecondaryColor")]
|
||||
public string SecondaryColor { get; set; }
|
||||
|
||||
[BsonElement("SectionIds")]
|
||||
public List<string> SectionIds { get; set; }
|
||||
|
||||
[BsonElement("Languages")]
|
||||
public List<string> Languages { get; set; } // fr, en, de, nl => Sélection dans une liste déjà établie dans l'application !
|
||||
|
||||
[BsonElement("DateCreation")]
|
||||
public DateTime DateCreation { get; set; }
|
||||
|
||||
public DisplayDTO ToDTO()
|
||||
{
|
||||
return new DisplayDTO()
|
||||
{
|
||||
Id = Id,
|
||||
Label = Label,
|
||||
DateCreation = DateCreation,
|
||||
PrimaryColor = PrimaryColor,
|
||||
SecondaryColor = SecondaryColor
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
65
Manager.Interfaces/Models/Ressource.cs
Normal file
65
Manager.Interfaces/Models/Ressource.cs
Normal file
@ -0,0 +1,65 @@
|
||||
using Manager.Interfaces.DTO;
|
||||
using MongoDB.Bson.Serialization.Attributes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
|
||||
namespace Manager.Interfaces.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// Ressource Information
|
||||
/// </summary>
|
||||
public class Ressource
|
||||
{
|
||||
[BsonId]
|
||||
[BsonRepresentation(MongoDB.Bson.BsonType.ObjectId)]
|
||||
public string Id { get; set; }
|
||||
|
||||
[BsonElement("Type")]
|
||||
[BsonRequired]
|
||||
public RessourceType Type { get; set; }
|
||||
|
||||
[BsonElement("Label")]
|
||||
[BsonRequired]
|
||||
public string Label { get; set; }
|
||||
|
||||
[BsonElement("DateCreation")]
|
||||
public DateTime DateCreation { get; set; }
|
||||
|
||||
[BsonElement("Data")]
|
||||
[BsonRequired]
|
||||
public string Data { get; set; }
|
||||
|
||||
public RessourceDTO ToDTO()
|
||||
{
|
||||
return new RessourceDTO()
|
||||
{
|
||||
Id = Id,
|
||||
Label = Label,
|
||||
Type = Type
|
||||
};
|
||||
}
|
||||
|
||||
public RessourceDetailDTO ToDetailDTO()
|
||||
{
|
||||
return new RessourceDetailDTO()
|
||||
{
|
||||
Id = Id,
|
||||
Label = Label,
|
||||
Type = Type,
|
||||
Data = Data,
|
||||
DateCreation = DateCreation
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public enum RessourceType
|
||||
{
|
||||
Image,
|
||||
Video,
|
||||
ImageUrl,
|
||||
VideoUrl
|
||||
}
|
||||
}
|
||||
64
Manager.Interfaces/Models/Section.cs
Normal file
64
Manager.Interfaces/Models/Section.cs
Normal file
@ -0,0 +1,64 @@
|
||||
using Manager.Interfaces.DTO;
|
||||
using MongoDB.Bson.Serialization.Attributes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
|
||||
namespace Manager.Interfaces.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// Section Information
|
||||
/// </summary>
|
||||
public class Section
|
||||
{
|
||||
[BsonId]
|
||||
[BsonRepresentation(MongoDB.Bson.BsonType.ObjectId)]
|
||||
public string Id { get; set; }
|
||||
|
||||
[BsonElement("Label")]
|
||||
[BsonRequired]
|
||||
public string Label { get; set; } // Dictionary<string, object> with all languages
|
||||
|
||||
[BsonElement("ImageId")]
|
||||
[BsonRequired]
|
||||
public string ImageId { get; set; }
|
||||
|
||||
[BsonElement("Type")]
|
||||
[BsonRequired]
|
||||
public SectionType Type { get; set; }
|
||||
|
||||
[BsonElement("IsSubSection")]
|
||||
[BsonRequired]
|
||||
public bool IsSubSection { get; set; }
|
||||
|
||||
[BsonElement("ParentId")]
|
||||
public string ParentId { get; set; } // only if it's an subsection
|
||||
|
||||
[BsonElement("Data")]
|
||||
public string Data { get; set; } // Json encapsulated info
|
||||
|
||||
[BsonElement("DateCreation")]
|
||||
public DateTime DateCreation { get; set; }
|
||||
|
||||
public SectionDTO ToDTO()
|
||||
{
|
||||
return new SectionDTO()
|
||||
{
|
||||
Id = Id,
|
||||
Label = Label,
|
||||
Type = Type,
|
||||
ImageId = ImageId
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public enum SectionType
|
||||
{
|
||||
Map,
|
||||
Slider,
|
||||
Video,
|
||||
Web,
|
||||
Menu
|
||||
}
|
||||
}
|
||||
209
ManagerService/Controllers/DisplayController.cs
Normal file
209
ManagerService/Controllers/DisplayController.cs
Normal file
@ -0,0 +1,209 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
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")
|
||||
[Route("[controller]")]
|
||||
[ApiController]
|
||||
[OpenApiTag("Display", Description = "Display management")]
|
||||
public class DisplayController : ControllerBase
|
||||
{
|
||||
private DisplayDatabaseService _displayService;
|
||||
private readonly ILogger<DisplayController> _logger;
|
||||
|
||||
public DisplayController(ILogger<DisplayController> logger, DisplayDatabaseService displayService)
|
||||
{
|
||||
_logger = logger;
|
||||
_displayService = displayService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a list of all display (summary)
|
||||
/// </summary>
|
||||
[ProducesResponseType(typeof(List<DisplayDTO>), 200)]
|
||||
[ProducesResponseType(typeof(string), 500)]
|
||||
[HttpGet]
|
||||
public ObjectResult Get()
|
||||
{
|
||||
try
|
||||
{
|
||||
List<Display> displays = _displayService.GetAll();
|
||||
|
||||
return new OkObjectResult(displays.Select(r => r.ToDTO()));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new ObjectResult(ex.Message) { StatusCode = 500 };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Get a specific display
|
||||
/// </summary>
|
||||
/// <param name="id">id display</param>
|
||||
[AllowAnonymous]
|
||||
[ProducesResponseType(typeof(DisplayDTO), 200)]
|
||||
[ProducesResponseType(typeof(string), 404)]
|
||||
[ProducesResponseType(typeof(string), 500)]
|
||||
[HttpGet("{id}")]
|
||||
public ObjectResult GetDetail(string id)
|
||||
{
|
||||
try
|
||||
{
|
||||
Display display = _displayService.GetById(id);
|
||||
|
||||
if (display == null)
|
||||
throw new KeyNotFoundException("This display was not found");
|
||||
|
||||
return new OkObjectResult(display.ToDTO());
|
||||
}
|
||||
catch (KeyNotFoundException ex)
|
||||
{
|
||||
return new NotFoundObjectResult(ex.Message) {};
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new ObjectResult(ex.Message) { StatusCode = 500 };
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a new display
|
||||
/// </summary>
|
||||
/// <param name="newDisplay">New display info</param>
|
||||
[ProducesResponseType(typeof(RessourceDetailDTO), 200)]
|
||||
[ProducesResponseType(typeof(string), 400)]
|
||||
[ProducesResponseType(typeof(string), 409)]
|
||||
[ProducesResponseType(typeof(string), 500)]
|
||||
[HttpPost]
|
||||
public ObjectResult Create([FromBody] DisplayDTO newDisplay)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (newDisplay == null)
|
||||
throw new ArgumentNullException("Display param is null");
|
||||
|
||||
// Todo add some verification ?
|
||||
Display display = new Display();
|
||||
display.Label = newDisplay.Label;
|
||||
display.PrimaryColor = newDisplay.PrimaryColor;
|
||||
display.SecondaryColor = newDisplay.SecondaryColor;
|
||||
display.SectionIds = newDisplay.SectionIds;
|
||||
display.DateCreation = DateTime.Now;
|
||||
|
||||
Display displayCreated = _displayService.Create(display);
|
||||
|
||||
return new OkObjectResult(displayCreated.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 };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Update a display
|
||||
/// </summary>
|
||||
/// <param name="updatedDisplay">Display to update</param>
|
||||
[ProducesResponseType(typeof(DisplayDTO), 200)]
|
||||
[ProducesResponseType(typeof(string), 400)]
|
||||
[ProducesResponseType(typeof(string), 404)]
|
||||
[ProducesResponseType(typeof(string), 500)]
|
||||
[HttpPut]
|
||||
public ObjectResult Update([FromBody] DisplayDTO updatedDisplay)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (updatedDisplay == null)
|
||||
throw new ArgumentNullException("Display param is null");
|
||||
|
||||
Display display = _displayService.GetById(updatedDisplay.Id);
|
||||
|
||||
if (display == null)
|
||||
throw new KeyNotFoundException("Display does not exist");
|
||||
|
||||
// Todo add some verification ?
|
||||
display.Label = updatedDisplay.Label;
|
||||
display.PrimaryColor = updatedDisplay.PrimaryColor;
|
||||
display.SecondaryColor = updatedDisplay.SecondaryColor;
|
||||
display.SectionIds = updatedDisplay.SectionIds;
|
||||
|
||||
Display displayModified = _displayService.Update(updatedDisplay.Id, display);
|
||||
|
||||
return new OkObjectResult(displayModified.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 };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Delete a display
|
||||
/// </summary>
|
||||
/// <param name="id">Id of display to delete</param>
|
||||
[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("Display param is null");
|
||||
|
||||
if (!_displayService.IsExist(id))
|
||||
throw new KeyNotFoundException("Display does not exist");
|
||||
|
||||
_displayService.Remove(id);
|
||||
|
||||
return new ObjectResult("The display 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 };
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
247
ManagerService/Controllers/RessourceController.cs
Normal file
247
ManagerService/Controllers/RessourceController.cs
Normal file
@ -0,0 +1,247 @@
|
||||
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")
|
||||
[Route("[controller]")]
|
||||
[ApiController]
|
||||
[OpenApiTag("Ressource", Description = "Ressource management")]
|
||||
public class RessourceController : ControllerBase
|
||||
{
|
||||
private RessourceDatabaseService _ressourceService;
|
||||
private readonly ILogger<RessourceController> _logger;
|
||||
|
||||
public RessourceController(ILogger<RessourceController> logger, RessourceDatabaseService ressourceService)
|
||||
{
|
||||
_logger = logger;
|
||||
_ressourceService = ressourceService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a list of all ressources (summary)
|
||||
/// </summary>
|
||||
[ProducesResponseType(typeof(List<RessourceDTO>), 200)]
|
||||
[ProducesResponseType(typeof(string), 500)]
|
||||
[HttpGet]
|
||||
public ObjectResult Get()
|
||||
{
|
||||
try
|
||||
{
|
||||
List<Ressource> ressources = _ressourceService.GetAll();
|
||||
|
||||
return new OkObjectResult(ressources.Select(r => r.ToDTO()));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new ObjectResult(ex.Message) { StatusCode = 500 };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Get a specific ressource
|
||||
/// </summary>
|
||||
/// <param name="id">id ressource</param>
|
||||
[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 };
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Show a specific ressource (as a picture or video stream)
|
||||
/// </summary>
|
||||
/// <param name="id">id ressource</param>
|
||||
[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 };
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a new ressource
|
||||
/// </summary>
|
||||
/// <param name="newRessource">New ressource info</param>
|
||||
[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 };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Update a ressource
|
||||
/// </summary>
|
||||
/// <param name="updatedRessource">Ressource to update</param>
|
||||
[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 };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Delete a ressource
|
||||
/// </summary>
|
||||
/// <param name="id">Id of ressource to delete</param>
|
||||
[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 };
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
234
ManagerService/Controllers/SectionController.cs
Normal file
234
ManagerService/Controllers/SectionController.cs
Normal file
@ -0,0 +1,234 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
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")
|
||||
[Route("[controller]")]
|
||||
[ApiController]
|
||||
[OpenApiTag("Section", Description = "Section management")]
|
||||
public class SectionController : ControllerBase
|
||||
{
|
||||
private SectionDatabaseService _sectionService;
|
||||
private readonly ILogger<SectionController> _logger;
|
||||
|
||||
public SectionController(ILogger<SectionController> logger, SectionDatabaseService sectionService)
|
||||
{
|
||||
_logger = logger;
|
||||
_sectionService = sectionService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a list of all section (summary)
|
||||
/// </summary>
|
||||
[ProducesResponseType(typeof(List<SectionDTO>), 200)]
|
||||
[ProducesResponseType(typeof(string), 500)]
|
||||
[HttpGet]
|
||||
public ObjectResult Get()
|
||||
{
|
||||
try
|
||||
{
|
||||
List<Section> sections = _sectionService.GetAll();
|
||||
|
||||
return new OkObjectResult(sections.Select(r => r.ToDTO()));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new ObjectResult(ex.Message) { StatusCode = 500 };
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a list of all subsection (summary) of a specific section
|
||||
/// </summary>
|
||||
/// <param name="id">section id</param>
|
||||
[ProducesResponseType(typeof(List<SectionDTO>), 200)]
|
||||
[ProducesResponseType(typeof(string), 500)]
|
||||
[HttpGet("{id}/subsections")]
|
||||
public ObjectResult GetAllSectionSubSections(string id)
|
||||
{
|
||||
try
|
||||
{
|
||||
List<Section> sections = _sectionService.GetAllSubSection(id);
|
||||
|
||||
return new OkObjectResult(sections.Select(r => r.ToDTO()));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new ObjectResult(ex.Message) { StatusCode = 500 };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Get a specific section
|
||||
/// </summary>
|
||||
/// <param name="id">section id</param>
|
||||
[AllowAnonymous]
|
||||
[ProducesResponseType(typeof(SectionDTO), 200)]
|
||||
[ProducesResponseType(typeof(string), 404)]
|
||||
[ProducesResponseType(typeof(string), 500)]
|
||||
[HttpGet("{id}")]
|
||||
public ObjectResult GetDetail(string id)
|
||||
{
|
||||
try
|
||||
{
|
||||
Section section = _sectionService.GetById(id);
|
||||
|
||||
if (section == null)
|
||||
throw new KeyNotFoundException("This section was not found");
|
||||
|
||||
return new OkObjectResult(section.ToDTO());
|
||||
}
|
||||
catch (KeyNotFoundException ex)
|
||||
{
|
||||
return new NotFoundObjectResult(ex.Message) {};
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new ObjectResult(ex.Message) { StatusCode = 500 };
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a new section
|
||||
/// </summary>
|
||||
/// <param name="newSection">New section info</param>
|
||||
[ProducesResponseType(typeof(SectionDTO), 200)]
|
||||
[ProducesResponseType(typeof(string), 400)]
|
||||
[ProducesResponseType(typeof(string), 409)]
|
||||
[ProducesResponseType(typeof(string), 500)]
|
||||
[HttpPost]
|
||||
public ObjectResult Create([FromBody] SectionDTO newSection)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (newSection == null)
|
||||
throw new ArgumentNullException("Section param is null");
|
||||
|
||||
// Todo add some verification ?
|
||||
Section section = new Section();
|
||||
section.Label = newSection.Label;
|
||||
section.ImageId = newSection.ImageId;
|
||||
section.IsSubSection = newSection.IsSubSection;
|
||||
section.ParentId = newSection.ParentId;
|
||||
section.Type = newSection.Type;
|
||||
section.Data = newSection.Data;
|
||||
section.DateCreation = DateTime.Now;
|
||||
|
||||
Section sectionCreated = _sectionService.Create(section);
|
||||
|
||||
return new OkObjectResult(sectionCreated.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 };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Update a section
|
||||
/// </summary>
|
||||
/// <param name="updatedSection">Section to update</param>
|
||||
[ProducesResponseType(typeof(SectionDTO), 200)]
|
||||
[ProducesResponseType(typeof(string), 400)]
|
||||
[ProducesResponseType(typeof(string), 404)]
|
||||
[ProducesResponseType(typeof(string), 500)]
|
||||
[HttpPut]
|
||||
public ObjectResult Update([FromBody] SectionDTO updatedSection)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (updatedSection == null)
|
||||
throw new ArgumentNullException("Section param is null");
|
||||
|
||||
Section section = _sectionService.GetById(updatedSection.Id);
|
||||
|
||||
if (section == null)
|
||||
throw new KeyNotFoundException("Section does not exist");
|
||||
|
||||
// Todo add some verification ?
|
||||
section.Label = updatedSection.Label;
|
||||
section.ImageId = updatedSection.ImageId;
|
||||
section.IsSubSection = updatedSection.IsSubSection;
|
||||
section.ParentId = updatedSection.ParentId;
|
||||
section.Type = updatedSection.Type;
|
||||
section.Data = updatedSection.Data;
|
||||
|
||||
Section sectionModified = _sectionService.Update(updatedSection.Id, section);
|
||||
|
||||
return new OkObjectResult(sectionModified.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 };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Delete a section
|
||||
/// </summary>
|
||||
/// <param name="id">Id of section to delete</param>
|
||||
[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("Section param is null");
|
||||
|
||||
if (!_sectionService.IsExist(id))
|
||||
throw new KeyNotFoundException("Section does not exist");
|
||||
|
||||
_sectionService.Remove(id);
|
||||
|
||||
return new ObjectResult("The section 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 };
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -9,12 +9,14 @@ 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")
|
||||
[Route("[controller]")]
|
||||
[ApiController]
|
||||
[OpenApiTag("User", Description = "User management")]
|
||||
public class UserController : ControllerBase
|
||||
{
|
||||
private UserDatabaseService _userService;
|
||||
@ -57,7 +59,7 @@ namespace ManagerService.Controllers
|
||||
[ProducesResponseType(typeof(string), 404)]
|
||||
[ProducesResponseType(typeof(string), 500)]
|
||||
[HttpGet("{id}")]
|
||||
public ObjectResult Get(string id)
|
||||
public ObjectResult GetDetail(string id)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
54
ManagerService/Services/DisplayDatabaseService.cs
Normal file
54
ManagerService/Services/DisplayDatabaseService.cs
Normal file
@ -0,0 +1,54 @@
|
||||
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 DisplayDatabaseService
|
||||
{
|
||||
private readonly IMongoCollection<Display> _Displays;
|
||||
|
||||
public DisplayDatabaseService(IConfiguration config)
|
||||
{
|
||||
var client = new MongoClient(config.GetConnectionString("TabletDb"));
|
||||
var database = client.GetDatabase("TabletDb");
|
||||
_Displays = database.GetCollection<Display>("Displays");
|
||||
}
|
||||
public List<Display> GetAll()
|
||||
{
|
||||
return _Displays.Find(d => true).ToList();
|
||||
}
|
||||
|
||||
public Display GetById(string id)
|
||||
{
|
||||
return _Displays.Find<Display>(d => d.Id == id).FirstOrDefault();
|
||||
}
|
||||
|
||||
public bool IsExist(string id)
|
||||
{
|
||||
return _Displays.Find<Display>(d => d.Id == id).FirstOrDefault() != null ? true : false;
|
||||
}
|
||||
|
||||
public Display Create(Display display)
|
||||
{
|
||||
_Displays.InsertOne(display);
|
||||
return display;
|
||||
}
|
||||
|
||||
public Display Update(string id, Display displayIn)
|
||||
{
|
||||
_Displays.ReplaceOne(d => d.Id == id, displayIn);
|
||||
return displayIn;
|
||||
}
|
||||
|
||||
public void Remove(string id)
|
||||
{
|
||||
_Displays.DeleteOne(d => d.Id == id);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
59
ManagerService/Services/RessourceDatabaseService.cs
Normal file
59
ManagerService/Services/RessourceDatabaseService.cs
Normal file
@ -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 RessourceDatabaseService
|
||||
{
|
||||
private readonly IMongoCollection<Ressource> _Ressources;
|
||||
|
||||
public RessourceDatabaseService(IConfiguration config)
|
||||
{
|
||||
var client = new MongoClient(config.GetConnectionString("TabletDb"));
|
||||
var database = client.GetDatabase("TabletDb");
|
||||
_Ressources = database.GetCollection<Ressource>("Ressources");
|
||||
}
|
||||
public List<Ressource> GetAll()
|
||||
{
|
||||
return _Ressources.Find(r => true).ToList();
|
||||
}
|
||||
|
||||
public Ressource GetByType(RessourceType type)
|
||||
{
|
||||
return _Ressources.Find<Ressource>(r => r.Type == type).FirstOrDefault();
|
||||
}
|
||||
|
||||
public Ressource GetById(string id)
|
||||
{
|
||||
return _Ressources.Find<Ressource>(r => r.Id == id).FirstOrDefault();
|
||||
}
|
||||
|
||||
public bool IsExist(string id)
|
||||
{
|
||||
return _Ressources.Find<Ressource>(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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
59
ManagerService/Services/SectionDatabaseService.cs
Normal file
59
ManagerService/Services/SectionDatabaseService.cs
Normal file
@ -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 SectionDatabaseService
|
||||
{
|
||||
private readonly IMongoCollection<Section> _Sections;
|
||||
|
||||
public SectionDatabaseService(IConfiguration config)
|
||||
{
|
||||
var client = new MongoClient(config.GetConnectionString("TabletDb"));
|
||||
var database = client.GetDatabase("TabletDb");
|
||||
_Sections = database.GetCollection<Section>("Sections");
|
||||
}
|
||||
public List<Section> GetAll()
|
||||
{
|
||||
return _Sections.Find(s => !s.IsSubSection).ToList();
|
||||
}
|
||||
|
||||
public List<Section> GetAllSubSection(string parentId)
|
||||
{
|
||||
return _Sections.Find(s => s.IsSubSection && s.ParentId == parentId).ToList();
|
||||
}
|
||||
|
||||
public Section GetById(string id)
|
||||
{
|
||||
return _Sections.Find<Section>(s => s.Id == id).FirstOrDefault();
|
||||
}
|
||||
|
||||
public bool IsExist(string id)
|
||||
{
|
||||
return _Sections.Find<Section>(s => s.Id == id).FirstOrDefault() != null ? true : false;
|
||||
}
|
||||
|
||||
public Section Create(Section section)
|
||||
{
|
||||
_Sections.InsertOne(section);
|
||||
return section;
|
||||
}
|
||||
|
||||
public Section Update(string id, Section sectionIn)
|
||||
{
|
||||
_Sections.ReplaceOne(s => s.Id == id, sectionIn);
|
||||
return sectionIn;
|
||||
}
|
||||
|
||||
public void Remove(string id)
|
||||
{
|
||||
_Sections.DeleteOne(s => s.Id == id);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user