API_SequentMicrosystems-RPI/Controllers/PointsController.cs

133 lines
3.7 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
{
[Tags("Internal Saving Points (Recommended only use \"Actual\" endpoint for read all data at once. Saving points is not recomended)")]
[Route("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>
/// <param name="start">id of 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>
/// <param name="max">max readed points</param>
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();
}
//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>
/// <param name="sec"></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
}
}
}