Files
PointCloudWeb/PointCloudWeb.Server/PointCloudWeb.Server/Controllers/PointCloudController.cs
2021-07-28 11:42:39 +02:00

40 lines
1.1 KiB
C#

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) => 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);
}
}
}