diff --git a/PointCloudWeb.Server/PointCloudWeb.Server/Controllers/PointCloudController.cs b/PointCloudWeb.Server/PointCloudWeb.Server/Controllers/PointCloudController.cs new file mode 100644 index 0000000..2cf9ce3 --- /dev/null +++ b/PointCloudWeb.Server/PointCloudWeb.Server/Controllers/PointCloudController.cs @@ -0,0 +1,43 @@ +using Microsoft.AspNetCore.Mvc; +using PointCloudWeb.Server.Models; +using PointCloudWeb.Server.Services; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace PointCloudWeb.Server.Controllers +{ + [ApiController] + [Route("[controller]")] + public class PointCloudController + { + private readonly PointCloudService pointCloudService; + + public PointCloudController(PointCloudService pointCloudService) + { + this.pointCloudService = pointCloudService; + } + + private PointCloudDto ConvertPointCloudToDto(PointCloud pc) + { + return new PointCloudDto(pc.Id, pc.Name, pc.TransformedPoints); + } + + [HttpGet] + public IList GetAll() + { + var result = new List(); + foreach (var pc in pointCloudService.GetAll()) + result.Add(ConvertPointCloudToDto(pc)); + + return result; + } + + [HttpGet] + public PointCloudDto GetById(Guid id) + { + var pc = pointCloudService.GetById(id) ?? throw new KeyNotFoundException(); + return ConvertPointCloudToDto(pc); + } + } +} \ No newline at end of file diff --git a/PointCloudWeb.Server/PointCloudWeb.Server/Models/PointCloud.cs b/PointCloudWeb.Server/PointCloudWeb.Server/Models/PointCloud.cs index f2b00d3..18d6c3a 100644 --- a/PointCloudWeb.Server/PointCloudWeb.Server/Models/PointCloud.cs +++ b/PointCloudWeb.Server/PointCloudWeb.Server/Models/PointCloud.cs @@ -46,7 +46,7 @@ namespace PointCloudWeb.Server.Models private ObservableCollection points; private Matrix4x4 transformation; - public PointCloud(string name, Guid id) + public PointCloud(Guid id, string name) { points = new ObservableCollection(); points.CollectionChanged += PointsCollectionChanged; @@ -110,7 +110,7 @@ namespace PointCloudWeb.Server.Models public PointCloud AddNew() { var id = Guid.NewGuid(); - var pc = new PointCloud(id.ToString(), id); + var pc = new PointCloud(id, "Scan #" + (Count + 1).ToString()); Add(pc); return pc; } diff --git a/PointCloudWeb.Server/PointCloudWeb.Server/Models/PointCloudDto.cs b/PointCloudWeb.Server/PointCloudWeb.Server/Models/PointCloudDto.cs new file mode 100644 index 0000000..1e202b9 --- /dev/null +++ b/PointCloudWeb.Server/PointCloudWeb.Server/Models/PointCloudDto.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace PointCloudWeb.Server.Models +{ + public class PointCloudDto + { + public PointCloudDto(Guid id, string name, IList points) + { + Id = id; + Name = name; + Points = points; + } + + public Guid Id { get; } + public string Name { get; } + public IList Points { get; } + } +} \ No newline at end of file diff --git a/PointCloudWeb.Server/PointCloudWeb.Server/Services/PointCloudService.cs b/PointCloudWeb.Server/PointCloudWeb.Server/Services/PointCloudService.cs index 80ac7a7..d77bd9c 100644 --- a/PointCloudWeb.Server/PointCloudWeb.Server/Services/PointCloudService.cs +++ b/PointCloudWeb.Server/PointCloudWeb.Server/Services/PointCloudService.cs @@ -31,6 +31,16 @@ namespace PointCloudWeb.Server.Services pc.Points.Add(point); } + public IList GetAll() + { + return pointClouds; + } + + public PointCloud GetById(Guid id) + { + return pointClouds.GetById(id); + } + public void RegisterPointCloud(Guid id) { RaiseIfNotExists(id);