Skip to content
Snippets Groups Projects
APIController.cs 1.65 KiB
Newer Older
using Microsoft.AspNetCore.Mvc;
using Public_API.Server.DAL;
using Public_API.Shared.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

namespace Public_API.Server.Controllers
{
    [Route("[controller]")]
    [ApiController]
    public class APIController : ControllerBase
    {

        ApiContext db = new ApiContext();

        // GET: api/<APIController>
        [HttpGet]
        public IEnumerable<string> Get()
        {
            return new string[] { "value1", "value2" };
        }

        // GET api/sensor/logValue/...
        [HttpGet("sensor/logValue/{sensorID}/{temperature}/{humidity}/{co2}/{ppm25}")]
        public string Get(int sensorID, string temperature, string humidity, string co2, string ppm25)
        {
            // TODO Error Handling!
            SensorValue sensorValue = new SensorValue(sensorID, decimal.Parse(temperature), decimal.Parse(humidity), decimal.Parse(co2), decimal.Parse(ppm25));

            db.SensorValue.Add(sensorValue);
            db.SaveChanges();

            return "Got value from " + sensorID + ". Sorted with ID " + sensorValue.valueID;
        }



        // POST api/<APIController>
        [HttpPost]
        public void Post([FromBody] string value)
        {
        }

        // PUT api/<APIController>/5
        [HttpPut("{id}")]
        public void Put(int id, [FromBody] string value)
        {
        }

        // DELETE api/<APIController>/5
        [HttpDelete("{id}")]
        public void Delete(int id)
        {
        }
    }
}