Cucumber/Cloud/Controllers/GreengouseController.cs

111 lines
4.0 KiB
C#
Raw Normal View History

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