add: основной круд
This commit is contained in:
parent
7b751b7072
commit
db3cbde0af
@ -66,7 +66,16 @@ namespace Cloud.Controllers
|
||||
[HttpGet("{greenhouseId}/settings")]
|
||||
public async Task<ActionResult<Greenhouse>> GetGreenhouse(int farmId, int greenhouseId)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
try
|
||||
{
|
||||
var greenhouse = await _greenhouseService.GetGreenhouse(greenhouseId);
|
||||
if (greenhouse == null) return NotFound("Greenhouses is not found");
|
||||
return Ok(greenhouse);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -78,7 +87,23 @@ namespace Cloud.Controllers
|
||||
[HttpPost]
|
||||
public async Task<ActionResult<Greenhouse>> SaveToDatabase(int farmId, GreenhouseRequest greenhouse)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
try
|
||||
{
|
||||
var greenhouseEntity = new Greenhouse()
|
||||
{
|
||||
RecomendedTemperature = greenhouse.RecomendedTemperature,
|
||||
WateringMode = greenhouse.WateringMode,
|
||||
HeatingMode = greenhouse.HeatingMode
|
||||
};
|
||||
|
||||
var result = await _greenhouseService.Create(greenhouseEntity);
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -92,7 +117,24 @@ namespace Cloud.Controllers
|
||||
[HttpPut("{greenhouseId}/settings")]
|
||||
public async Task<ActionResult<Greenhouse>> Update(int farmId, int greenhouseId, GreenhouseRequest greenhouse)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
try
|
||||
{
|
||||
var greenhouseEntity = new Greenhouse()
|
||||
{
|
||||
Id = greenhouseId,
|
||||
FarmId = farmId,
|
||||
WateringMode = greenhouse.WateringMode,
|
||||
HeatingMode = greenhouse.HeatingMode,
|
||||
RecomendedTemperature = greenhouse.RecomendedTemperature
|
||||
};
|
||||
|
||||
var result = await _greenhouseService.Update(greenhouseEntity);
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -104,8 +146,15 @@ namespace Cloud.Controllers
|
||||
[HttpDelete("{greenhouseId}")]
|
||||
public async Task<ActionResult> Delete(int farmId, int greenhouseId)
|
||||
{
|
||||
|
||||
throw new NotImplementedException();
|
||||
try
|
||||
{
|
||||
_ = await _greenhouseService.Delete(greenhouseId);
|
||||
return Ok();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user