API_SequentMicrosystems-RPI/Controllers/PointsController.cs

143 lines
3.9 KiB
C#
Raw Normal View History

2023-11-25 08:24:04 +00:00
using API_SequentMicrosystems.Models;
using API_SequentMicrosystems.Services;
using Microsoft.AspNetCore.Mvc;
// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
namespace API_SequentMicrosystems.Controllers
{
2023-11-30 16:09:08 +00:00
[Tags("Internal Saving Points (Recommended use only \"Actual\" endpoint for read all data at once. Saving points is not recomended)")]
2024-01-15 09:33:10 +00:00
[Route("api/Points")]
2023-11-25 08:24:04 +00:00
[ApiController]
public class PointsController : ControllerBase
{
private PointsService _PointsService;
public PointsController(PointsService _PS)
{
_PointsService = _PS;
}
// GET: api/<PointsController>
/// <summary>
/// Get all saved points
/// </summary>
/// <returns></returns>
[HttpGet]
public List<PointsModel> Get()
{
return _PointsService.GetPoints().Take(1000).ToList(); ;
2023-11-25 08:24:04 +00:00
}
// GET api/<PointsController>/5/5
2023-11-25 08:24:04 +00:00
/// <summary>
/// Read points from and to specified points positions
2023-11-25 08:24:04 +00:00
/// </summary>
/// <param name="limit">limit of returned points (Maximum 1000)</param>
/// <param name="start">id of start element</param>
2023-11-25 08:24:04 +00:00
/// <returns></returns>
[HttpGet("{start}/{limit}")]
public List<PointsModel> Get(int limit, int start)
2023-11-25 08:24:04 +00:00
{
if (limit > 1000)
limit = 1000;
return _PointsService.GetPoints(start, limit);
2023-11-25 08:24:04 +00:00
}
// POST api/<PointsController>/5
2023-11-25 08:24:04 +00:00
/// <summary>
/// Read points from and to specified points positions
/// </summary>
/// <param name="limit">limit of returned points (Maximum 1000)</param>
2023-11-30 15:46:33 +00:00
/// <param name="pm">start element</param>
/// <returns></returns>
[HttpPost("{limit}")]
public List<PointsModel> Post(int limit, [FromBody] PointsModel pm)
{
if (limit > 1000)
limit = 1000;
return _PointsService.GetPoints(limit, pm);
}
//GET api/Points/Actual
/// <summary>
/// Get Actual Point
/// </summary>
/// <returns></returns>
[HttpGet("Actual")]
public PointsModel GetActual()
{
return _PointsService.GetPoint();
}
// GET api/<PointsController>/5
/// <summary>
/// Read points from first to specified number
/// </summary>
2023-11-25 08:24:04 +00:00
/// <returns></returns>
[HttpGet("Count")]
public int GetCount()
2023-11-25 08:24:04 +00:00
{
return _PointsService.GetPoints().Count;
2023-11-25 08:24:04 +00:00
}
//DELETE api/points
/// <summary>
/// Delete saved points
/// </summary>
[HttpDelete]
public void Delete()
{
_PointsService.DeletePoints();
}
2023-11-30 15:46:33 +00:00
//DELETE api/points
/// <summary>
/// Delete Specified saved point
/// </summary>
/// <param name="id">Point ID</param>
[HttpDelete("{id}")]
public void Delete(int id)
{
_PointsService.DeletePoint(id);
}
2023-11-25 08:24:04 +00:00
//GET api/points/save
/// <summary>
/// Save new point
/// </summary>
[HttpGet("save")]
public void GetSave()
{
_PointsService.SavePoint();
}
//GET api/points/save/300
/// <summary>
/// Start timer to automatic saving points in specified interval
/// </summary>
2023-11-30 15:46:33 +00:00
/// <param name="msec"></param>
[HttpGet("AutoSave/{msec}")]
public void GetSaveSec(int msec)
2023-11-25 08:24:04 +00:00
{
_PointsService.AutoSaveStart(msec);
2023-11-25 08:24:04 +00:00
}
//GET api/points/save
/// <summary>
/// Stop timer for automatic save points
/// </summary>
[HttpDelete("AutoSave")]
2023-11-25 08:24:04 +00:00
public void DeleteSaveSec()
{
_PointsService.AutoSaveStop();
2023-11-25 08:24:04 +00:00
}
}
}