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-25 18:00:12 +00:00
|
|
|
|
[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()
|
|
|
|
|
{
|
2023-11-25 18:00:12 +00:00
|
|
|
|
return _PointsService.GetPoints().Take(1000).ToList(); ;
|
2023-11-25 08:24:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-11-25 18:00:12 +00:00
|
|
|
|
// GET api/<PointsController>/5/5
|
2023-11-25 08:24:04 +00:00
|
|
|
|
/// <summary>
|
2023-11-25 18:00:12 +00:00
|
|
|
|
/// Read points from and to specified points positions
|
2023-11-25 08:24:04 +00:00
|
|
|
|
/// </summary>
|
2023-11-25 18:00:12 +00:00
|
|
|
|
/// <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>
|
2023-11-25 18:00:12 +00:00
|
|
|
|
[HttpGet("{start}/{limit}")]
|
|
|
|
|
public List<PointsModel> Get(int limit, int start)
|
2023-11-25 08:24:04 +00:00
|
|
|
|
{
|
2023-11-25 18:00:12 +00:00
|
|
|
|
if (limit > 1000)
|
|
|
|
|
limit = 1000;
|
|
|
|
|
|
|
|
|
|
return _PointsService.GetPoints(start, limit);
|
2023-11-25 08:24:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-11-25 18:00:12 +00:00
|
|
|
|
// POST api/<PointsController>/5
|
2023-11-25 08:24:04 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Read points from and to specified points positions
|
|
|
|
|
/// </summary>
|
2023-11-25 18:00:12 +00:00
|
|
|
|
/// <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/<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>
|
2023-11-25 18:00:12 +00:00
|
|
|
|
[HttpGet("Count")]
|
|
|
|
|
public int GetCount()
|
2023-11-25 08:24:04 +00:00
|
|
|
|
{
|
2023-11-25 18:00:12 +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>
|
2023-11-25 18:00:12 +00:00
|
|
|
|
[HttpGet("AutoSave/{msec}")]
|
|
|
|
|
public void GetSaveSec(int msec)
|
2023-11-25 08:24:04 +00:00
|
|
|
|
{
|
2023-11-25 18:00:12 +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>
|
2023-11-25 18:00:12 +00:00
|
|
|
|
[HttpDelete("AutoSave")]
|
2023-11-25 08:24:04 +00:00
|
|
|
|
public void DeleteSaveSec()
|
|
|
|
|
{
|
2023-11-25 18:00:12 +00:00
|
|
|
|
_PointsService.AutoSaveStop();
|
2023-11-25 08:24:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|