add PointCloudController

This commit is contained in:
Tim Wundenberg
2021-07-21 21:42:22 +02:00
parent 41f3567fbc
commit 4abb44ba2f
4 changed files with 76 additions and 2 deletions

View File

@@ -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<PointCloudDto> GetAll()
{
var result = new List<PointCloudDto>();
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);
}
}
}

View File

@@ -46,7 +46,7 @@ namespace PointCloudWeb.Server.Models
private ObservableCollection<Point> points; private ObservableCollection<Point> points;
private Matrix4x4 transformation; private Matrix4x4 transformation;
public PointCloud(string name, Guid id) public PointCloud(Guid id, string name)
{ {
points = new ObservableCollection<Point>(); points = new ObservableCollection<Point>();
points.CollectionChanged += PointsCollectionChanged; points.CollectionChanged += PointsCollectionChanged;
@@ -110,7 +110,7 @@ namespace PointCloudWeb.Server.Models
public PointCloud AddNew() public PointCloud AddNew()
{ {
var id = Guid.NewGuid(); var id = Guid.NewGuid();
var pc = new PointCloud(id.ToString(), id); var pc = new PointCloud(id, "Scan #" + (Count + 1).ToString());
Add(pc); Add(pc);
return pc; return pc;
} }

View File

@@ -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<Point> points)
{
Id = id;
Name = name;
Points = points;
}
public Guid Id { get; }
public string Name { get; }
public IList<Point> Points { get; }
}
}

View File

@@ -31,6 +31,16 @@ namespace PointCloudWeb.Server.Services
pc.Points.Add(point); pc.Points.Add(point);
} }
public IList<PointCloud> GetAll()
{
return pointClouds;
}
public PointCloud GetById(Guid id)
{
return pointClouds.GetById(id);
}
public void RegisterPointCloud(Guid id) public void RegisterPointCloud(Guid id)
{ {
RaiseIfNotExists(id); RaiseIfNotExists(id);