| | 1 | | using Microsoft.AspNetCore.Authorization; |
| | 2 | | using Microsoft.AspNetCore.Mvc; |
| | 3 | | using WebApi.Models; |
| | 4 | | using WebApi.Services; |
| | 5 | |
|
| | 6 | | namespace WebApi.Controllers |
| | 7 | | { |
| | 8 | | [ApiController] |
| | 9 | | [Route("[controller]")] |
| | 10 | | public class PostEnvironmentDataGoalController : ControllerBase |
| | 11 | | { |
| | 12 | | private readonly ISensorGoalService _sensorGoalService; |
| | 13 | |
|
| 2 | 14 | | public PostEnvironmentDataGoalController(ISensorGoalService sensorGoalService) |
| 2 | 15 | | { |
| 2 | 16 | | _sensorGoalService = sensorGoalService; |
| 2 | 17 | | } |
| | 18 | |
|
| | 19 | | [HttpPost] |
| | 20 | | [Authorize(Policy = "MustBeAdmin")] |
| | 21 | | public async Task<IActionResult> PostSensorDataGoal([FromBody] SensorGoal sensorGoal) |
| 2 | 22 | | { |
| | 23 | | try |
| 2 | 24 | | { |
| 2 | 25 | | await _sensorGoalService.AddOrUpdateSensorGoalAsync(sensorGoal); |
| 1 | 26 | | return Ok(new |
| 1 | 27 | | { |
| 1 | 28 | | success = true, |
| 1 | 29 | | hallId = sensorGoal.HallId, |
| 1 | 30 | | desiredTemperature = sensorGoal.DesiredTemperature, |
| 1 | 31 | | desiredHumidity = sensorGoal.DesiredHumidity, |
| 1 | 32 | | desiredCo2 = sensorGoal.DesiredCo2 |
| 1 | 33 | | }); |
| | 34 | | } |
| 1 | 35 | | catch (Exception e) |
| 1 | 36 | | { |
| 1 | 37 | | return BadRequest(new { success = false, error = e.Message }); |
| | 38 | | } |
| 2 | 39 | | } |
| | 40 | | } |
| | 41 | | } |