< Summary

Information
Class: WebApi.Controllers.PostEnvironmentDataGoalController
Assembly: IndeklimaWebApi
File(s): /home/runner/work/SEP4/SEP4/backend/microservices/indeklima/WebApi/Controllers/Frontend_Endpoints/PostEnvironmentDataGoalController.cs
Line coverage
100%
Covered lines: 19
Uncovered lines: 0
Coverable lines: 19
Total lines: 41
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
PostSensorDataGoal()100%11100%

File(s)

/home/runner/work/SEP4/SEP4/backend/microservices/indeklima/WebApi/Controllers/Frontend_Endpoints/PostEnvironmentDataGoalController.cs

#LineLine coverage
 1using Microsoft.AspNetCore.Authorization;
 2using Microsoft.AspNetCore.Mvc;
 3using WebApi.Models;
 4using WebApi.Services;
 5
 6namespace WebApi.Controllers
 7{
 8    [ApiController]
 9    [Route("[controller]")]
 10    public class PostEnvironmentDataGoalController : ControllerBase
 11    {
 12        private readonly ISensorGoalService _sensorGoalService;
 13
 214        public PostEnvironmentDataGoalController(ISensorGoalService sensorGoalService)
 215        {
 216            _sensorGoalService = sensorGoalService;
 217        }
 18
 19        [HttpPost]
 20        [Authorize(Policy = "MustBeAdmin")]
 21        public async Task<IActionResult> PostSensorDataGoal([FromBody] SensorGoal sensorGoal)
 222        {
 23            try
 224            {
 225                await _sensorGoalService.AddOrUpdateSensorGoalAsync(sensorGoal);
 126                return Ok(new
 127                {
 128                    success = true,
 129                    hallId = sensorGoal.HallId,
 130                    desiredTemperature = sensorGoal.DesiredTemperature,
 131                    desiredHumidity = sensorGoal.DesiredHumidity,
 132                    desiredCo2 = sensorGoal.DesiredCo2
 133                });
 34            }
 135            catch (Exception e)
 136            {
 137                return BadRequest(new { success = false, error = e.Message });
 38            }
 239        }
 40    }
 41}