2024-11-13 03:33:03 +04:00
|
|
|
|
using Cloud.Models;
|
|
|
|
|
using Cloud.Requests;
|
|
|
|
|
using Cloud.Services.Broker;
|
|
|
|
|
using Cloud.Services.Broker.Support;
|
2024-12-04 01:57:29 +04:00
|
|
|
|
using Cloud.Services.Domain;
|
2024-11-13 03:33:03 +04:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
|
|
|
|
namespace Cloud.Controllers
|
|
|
|
|
{
|
|
|
|
|
[ApiController]
|
2024-12-04 01:57:29 +04:00
|
|
|
|
[Route("api/farm/{farmId}/greenhouse")]
|
2024-11-13 03:33:03 +04:00
|
|
|
|
public class GreenhouseController : ControllerBase
|
|
|
|
|
{
|
2024-12-04 01:57:29 +04:00
|
|
|
|
private readonly IGreenhouseService _greenhouseService;
|
|
|
|
|
public GreenhouseController(IGreenhouseService greenhouseService)
|
2024-11-13 03:33:03 +04:00
|
|
|
|
{
|
2024-12-04 01:57:29 +04:00
|
|
|
|
_greenhouseService = greenhouseService;
|
2024-11-13 03:33:03 +04:00
|
|
|
|
}
|
|
|
|
|
|
2024-12-04 01:57:29 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Возвращает текущую информацию о всех теплицах пользователя
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="farmId"></param>
|
|
|
|
|
/// <returns></returns>
|
2024-11-13 03:33:03 +04:00
|
|
|
|
[HttpGet]
|
2024-12-04 01:57:29 +04:00
|
|
|
|
public async Task<ActionResult<List<GreenhouseInfo>>> GetAll(int farmId)
|
2024-11-13 03:33:03 +04:00
|
|
|
|
{
|
2024-12-04 01:57:29 +04:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var greenhouses = _greenhouseService.GetAll(farmId);
|
|
|
|
|
return Ok(greenhouses);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
return BadRequest(ex.Message);
|
|
|
|
|
}
|
2024-11-13 03:33:03 +04:00
|
|
|
|
}
|
|
|
|
|
|
2024-12-04 01:57:29 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Возвращает текущую информацию о конкретной теплице
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="farmId"></param>
|
|
|
|
|
/// <param name="greenhouseId"></param>
|
|
|
|
|
/// <returns></returns>
|
2024-11-13 03:33:03 +04:00
|
|
|
|
[HttpGet("{greenhouseId}")]
|
2024-12-04 01:57:29 +04:00
|
|
|
|
public async Task<ActionResult<GreenhouseInfo>> Get(int farmId, int greenhouseId)
|
2024-11-13 03:33:03 +04:00
|
|
|
|
{
|
2024-12-04 01:57:29 +04:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var greenhouses = _greenhouseService.GetGreenhouseInfo(greenhouseId, farmId);
|
|
|
|
|
return Ok(greenhouses);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
return BadRequest(ex.Message);
|
|
|
|
|
}
|
2024-11-13 03:33:03 +04:00
|
|
|
|
}
|
|
|
|
|
|
2024-12-04 01:57:29 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Возвращает сохраненные данные для автоматизации теплицы
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="farmId"></param>
|
|
|
|
|
/// <param name="greenhouseId"></param>
|
|
|
|
|
/// <returns></returns>
|
2024-11-13 03:33:03 +04:00
|
|
|
|
[HttpGet("{greenhouseId}/settings")]
|
2024-12-04 01:57:29 +04:00
|
|
|
|
public async Task<ActionResult<Greenhouse>> GetGreenhouse(int farmId, int greenhouseId)
|
2024-11-13 03:33:03 +04:00
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-04 01:57:29 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Сохраняет в базе данных API данные для автоматизации теплицы
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="farmId"></param>
|
|
|
|
|
/// <param name="greenhouse"></param>
|
|
|
|
|
/// <returns></returns>
|
2024-11-13 03:33:03 +04:00
|
|
|
|
[HttpPost]
|
2024-12-04 01:57:29 +04:00
|
|
|
|
public async Task<ActionResult<Greenhouse>> SaveToDatabase(int farmId, GreenhouseRequest greenhouse)
|
2024-11-13 03:33:03 +04:00
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-04 01:57:29 +04:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Обновляет в базе данных API данные для автоматизации теплицы
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="farmId">ID фермы</param>
|
|
|
|
|
/// <param name="greenhouseId">ID теплицы</param>
|
|
|
|
|
/// <param name="greenhouse">Данные для обновления</param>
|
|
|
|
|
/// <returns>Обновленный объект Greenhouse</returns>
|
2024-11-13 03:33:03 +04:00
|
|
|
|
[HttpPut("{greenhouseId}/settings")]
|
2024-12-04 01:57:29 +04:00
|
|
|
|
public async Task<ActionResult<Greenhouse>> Update(int farmId, int greenhouseId, GreenhouseRequest greenhouse)
|
2024-11-13 03:33:03 +04:00
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-04 01:57:29 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Удаляет из базы данных API запись настроек автоматизации теплицы
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="farmId"></param>
|
|
|
|
|
/// <param name="greenhouseId"></param>
|
|
|
|
|
/// <returns></returns>
|
2024-11-13 03:33:03 +04:00
|
|
|
|
[HttpDelete("{greenhouseId}")]
|
2024-12-04 01:57:29 +04:00
|
|
|
|
public async Task<ActionResult> Delete(int farmId, int greenhouseId)
|
2024-11-13 03:33:03 +04:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|