mirror of
https://bitbucket.org/myhomie/mycorerepository.git
synced 2025-12-06 09:41:19 +00:00
MC #1 Model (Device, ScreenConfiguration, UserInfo, Widget, WidgetAgenda, WidgetHourAndDate, WidgetMessage, WidgetNews, WidgetRadio, WidgetTraffic, WidgetWeather), #1 Controllers (Device) & #2 Service (Device)
This commit is contained in:
parent
0b08ffcf51
commit
36a745d219
Binary file not shown.
Binary file not shown.
Binary file not shown.
96
MyCore/Controllers/DeviceController.cs
Normal file
96
MyCore/Controllers/DeviceController.cs
Normal file
@ -0,0 +1,96 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using MongoDB.Bson;
|
||||
using MyCore.Models;
|
||||
using MyCore.Services;
|
||||
|
||||
namespace MyCore.Controllers
|
||||
{
|
||||
[Authorize(Roles = "Admin")]
|
||||
[Route("api/device")]
|
||||
[ApiController]
|
||||
public class DeviceController : ControllerBase
|
||||
{
|
||||
private readonly DeviceService _DeviceService;
|
||||
|
||||
public DeviceController(DeviceService DeviceService)
|
||||
{
|
||||
_DeviceService = DeviceService;
|
||||
}
|
||||
|
||||
// GET: Devices
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="id">Id of the device you want to get informatiun</param>
|
||||
[HttpGet]
|
||||
public ActionResult<List<Device>> GetAllDevices()
|
||||
{
|
||||
return _DeviceService.GetAll();
|
||||
}
|
||||
|
||||
// GET: Device
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="idDevice">Id of the device you want to get information</param>
|
||||
[HttpGet("{idDevice}")]
|
||||
public ActionResult<Device> GetDeviceInfo(string idDevice)
|
||||
{
|
||||
return _DeviceService.GetDeviceInfo(idDevice);
|
||||
}
|
||||
|
||||
// POST: Device/Create
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[HttpPost("{idDevice}")]
|
||||
public IActionResult CreateDevice(int idDevice, [FromBody] Device device)
|
||||
{
|
||||
if (idDevice == 0)
|
||||
{
|
||||
_DeviceService.CreateDevice(device);
|
||||
|
||||
return StatusCode(201);
|
||||
}
|
||||
return StatusCode(500);
|
||||
}
|
||||
|
||||
// PUT: Device/Update
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[HttpPut("{idDevice}")]
|
||||
public IActionResult UpdateDevice(int idDevice, [FromBody] Device device)
|
||||
{
|
||||
if (idDevice == 0)
|
||||
{
|
||||
_DeviceService.Update(device.Id, device);
|
||||
|
||||
return StatusCode(201);
|
||||
}
|
||||
return StatusCode(500);
|
||||
}
|
||||
|
||||
// Delete: Device/Delete
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[HttpDelete("{idDevice}")]
|
||||
public IActionResult DeleteDevice(int idDevice, [FromBody] string deviceId)
|
||||
{
|
||||
if (idDevice == 0)
|
||||
{
|
||||
_DeviceService.Remove(deviceId);
|
||||
|
||||
return StatusCode(201);
|
||||
}
|
||||
return StatusCode(500);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -7,6 +7,7 @@ using Microsoft.AspNetCore.Mvc;
|
||||
using MQTTnet;
|
||||
using MQTTnet.Client;
|
||||
using MQTTnet.Server;
|
||||
using MyCore.Models;
|
||||
|
||||
namespace MyCore.Controllers
|
||||
{
|
||||
@ -24,6 +25,8 @@ namespace MyCore.Controllers
|
||||
[HttpGet]
|
||||
public ActionResult<IEnumerable<string>> Get()
|
||||
{
|
||||
WidgetWeather widgetWeather = new WidgetWeather();
|
||||
|
||||
return new string[] { "value1", "value2" };
|
||||
}
|
||||
|
||||
|
||||
36
MyCore/Models/Device.cs
Normal file
36
MyCore/Models/Device.cs
Normal file
@ -0,0 +1,36 @@
|
||||
using MongoDB.Bson;
|
||||
using MongoDB.Bson.Serialization.Attributes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MyCore.Models
|
||||
{
|
||||
public class Device
|
||||
{
|
||||
[BsonId]
|
||||
[BsonRepresentation(BsonType.ObjectId)]
|
||||
public string Id { get; set; }
|
||||
|
||||
[BsonElement("Name")]
|
||||
public string Name { get; set; }
|
||||
|
||||
[BsonElement("Type")]
|
||||
public string Type { get; set; }
|
||||
|
||||
[BsonElement("Location")]
|
||||
public string Location { get; set; }
|
||||
|
||||
[BsonElement("LocationExplanation")]
|
||||
public string LocationExplanation { get; set; }
|
||||
|
||||
[BsonElement("Height")]
|
||||
public int Height { get; set; }
|
||||
|
||||
[BsonElement("Width")]
|
||||
public int Width { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
31
MyCore/Models/ScreenConfiguration.cs
Normal file
31
MyCore/Models/ScreenConfiguration.cs
Normal file
@ -0,0 +1,31 @@
|
||||
using MongoDB.Bson;
|
||||
using MongoDB.Bson.Serialization.Attributes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MyCore.Models
|
||||
{
|
||||
public class ScreenConfiguration
|
||||
{
|
||||
[BsonId]
|
||||
[BsonRepresentation(BsonType.ObjectId)]
|
||||
public string Id { get; set; }
|
||||
|
||||
[BsonElement("Name")]
|
||||
public string Name { get; set; }
|
||||
|
||||
[BsonElement("Type")]
|
||||
public string Type { get; set; }
|
||||
|
||||
[BsonElement("Widgets")]
|
||||
public Widget[] Widgets { get; set; }
|
||||
|
||||
[BsonElement("Height")]
|
||||
public int Height { get; set; }
|
||||
|
||||
[BsonElement("Width")]
|
||||
public int Width { get; set; }
|
||||
}
|
||||
}
|
||||
@ -17,8 +17,8 @@ namespace MyCore.Models
|
||||
[BsonElement("Role")]
|
||||
public string Role { get; set; }
|
||||
|
||||
[BsonElement("Username")]
|
||||
public string Username { get; set; }
|
||||
[BsonElement("Email")]
|
||||
public string Email { get; set; } // UNIQUE !..
|
||||
|
||||
[BsonElement("Password")]
|
||||
public string Password { get; set; }
|
||||
@ -34,6 +34,31 @@ namespace MyCore.Models
|
||||
|
||||
[BsonElement("Birthday")]
|
||||
public string Birthday { get; set; }
|
||||
|
||||
[BsonElement("Address")]
|
||||
public string Address { get; set; }
|
||||
|
||||
[BsonElement("City")]
|
||||
public string City { get; set; }
|
||||
|
||||
[BsonElement("State")]
|
||||
public string State { get; set; }
|
||||
|
||||
[BsonElement("Language")]
|
||||
public string Language { get; set; }
|
||||
|
||||
[BsonElement("TimeZone")]
|
||||
public string TimeZone { get; set; }
|
||||
|
||||
[BsonElement("PostalCode")]
|
||||
public int PostalCode { get; set; }
|
||||
|
||||
[BsonElement("ScreenConfigurationIds")]
|
||||
public int[] ScreenConfigurationIds { get; set; }
|
||||
|
||||
[BsonElement("DeviceIds")]
|
||||
public int[] DeviceIds { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
53
MyCore/Models/Widget.cs
Normal file
53
MyCore/Models/Widget.cs
Normal file
@ -0,0 +1,53 @@
|
||||
using MongoDB.Bson;
|
||||
using MongoDB.Bson.Serialization.Attributes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
namespace MyCore.Models
|
||||
{
|
||||
public class Widget
|
||||
{
|
||||
[BsonId]
|
||||
[BsonRepresentation(BsonType.ObjectId)]
|
||||
public string Id { get; set; }
|
||||
|
||||
[BsonElement("Name")]
|
||||
public string Name { get; set; }
|
||||
|
||||
[BsonElement("DisplayName")]
|
||||
public string DisplayName { get; set; }
|
||||
|
||||
[BsonElement("Type")]
|
||||
public string Type { get; set; }
|
||||
|
||||
[BsonElement("Activated")]
|
||||
public bool Activated { get; set; }
|
||||
|
||||
[BsonElement("Form")]
|
||||
public string Form { get; set; }
|
||||
|
||||
[BsonElement("Font")]
|
||||
public string Font { get; set; }
|
||||
|
||||
[BsonElement("Color")]
|
||||
public string Color { get; set; }
|
||||
|
||||
[BsonElement("Size")]
|
||||
public string Size { get; set; }
|
||||
|
||||
[BsonElement("Width")]
|
||||
public int Width { get; set; }
|
||||
|
||||
[BsonElement("Height")]
|
||||
public int Height { get; set; }
|
||||
|
||||
[BsonElement("PositionX")]
|
||||
public int PositionX { get; set; }
|
||||
|
||||
[BsonElement("PositionY")]
|
||||
public int PositionY { get; set; }
|
||||
}
|
||||
}
|
||||
20
MyCore/Models/WidgetAgenda.cs
Normal file
20
MyCore/Models/WidgetAgenda.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using MongoDB.Bson.Serialization.Attributes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MyCore.Models
|
||||
{
|
||||
public class WidgetAgenda : Widget
|
||||
{
|
||||
[BsonElement("Provider")]
|
||||
public string Provider { get; set; }
|
||||
|
||||
[BsonElement("Link")]
|
||||
public string Link { get; set; } // ?
|
||||
|
||||
[BsonElement("ApiKey")]
|
||||
public string ApiKey { get; set; } // ?
|
||||
}
|
||||
}
|
||||
14
MyCore/Models/WidgetHourAndDate.cs
Normal file
14
MyCore/Models/WidgetHourAndDate.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using MongoDB.Bson.Serialization.Attributes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MyCore.Models
|
||||
{
|
||||
public class WidgetHourAndDate : Widget
|
||||
{
|
||||
[BsonElement("Timezone")]
|
||||
public string Timezone { get; set; }
|
||||
}
|
||||
}
|
||||
23
MyCore/Models/WidgetMessage.cs
Normal file
23
MyCore/Models/WidgetMessage.cs
Normal file
@ -0,0 +1,23 @@
|
||||
using MongoDB.Bson.Serialization.Attributes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MyCore.Models
|
||||
{
|
||||
public class WidgetMessage : Widget
|
||||
{
|
||||
[BsonElement("Message")]
|
||||
public string Message { get; set; }
|
||||
|
||||
[BsonElement("Permanent")]
|
||||
public bool Permanent { get; set; }
|
||||
|
||||
[BsonElement("VisibleDuration")]
|
||||
public int VisibleDuration { get; set; }
|
||||
|
||||
[BsonElement("Link")] // LINK RSS FEED Motivational message .. ? / Citations etc
|
||||
public string Link { get; set; }
|
||||
}
|
||||
}
|
||||
20
MyCore/Models/WidgetNews.cs
Normal file
20
MyCore/Models/WidgetNews.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using MongoDB.Bson.Serialization.Attributes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MyCore.Models
|
||||
{
|
||||
public class WidgetNews : Widget
|
||||
{
|
||||
[BsonElement("Country")]
|
||||
public string Country { get; set; }
|
||||
|
||||
[BsonElement("Provider")]
|
||||
public string Provider { get; set; }
|
||||
|
||||
[BsonElement("Speed")]
|
||||
public string Speed { get; set; } // Or int ?
|
||||
}
|
||||
}
|
||||
17
MyCore/Models/WidgetRadio.cs
Normal file
17
MyCore/Models/WidgetRadio.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using MongoDB.Bson.Serialization.Attributes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MyCore.Models
|
||||
{
|
||||
public class WidgetRadio : Widget
|
||||
{
|
||||
[BsonElement("Provider")]
|
||||
public string Provider { get; set; }
|
||||
|
||||
[BsonElement("Link")]
|
||||
public string Link { get; set; }
|
||||
}
|
||||
}
|
||||
23
MyCore/Models/WidgetTraffic.cs
Normal file
23
MyCore/Models/WidgetTraffic.cs
Normal file
@ -0,0 +1,23 @@
|
||||
using MongoDB.Bson.Serialization.Attributes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MyCore.Models
|
||||
{
|
||||
public class WidgetTraffic : Widget
|
||||
{
|
||||
[BsonElement("WorkAddress")]
|
||||
public string WorkAddress { get; set; }
|
||||
|
||||
[BsonElement("WorkCity")]
|
||||
public string WorkCity { get; set; }
|
||||
|
||||
[BsonElement("WorkPostCode")]
|
||||
public string WorkPostCode { get; set; }
|
||||
|
||||
[BsonElement("WorkDays")]
|
||||
public bool[] WorkDays { get; set; } // [1,1,1,1,1,0,0]
|
||||
}
|
||||
}
|
||||
24
MyCore/Models/WidgetWeather.cs
Normal file
24
MyCore/Models/WidgetWeather.cs
Normal file
@ -0,0 +1,24 @@
|
||||
using MongoDB.Bson;
|
||||
using MongoDB.Bson.Serialization.Attributes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MyCore.Models
|
||||
{
|
||||
public class WidgetWeather : Widget
|
||||
{
|
||||
[BsonElement("City")]
|
||||
public string City { get; set; }
|
||||
|
||||
[BsonElement("Wind")]
|
||||
public string Wind { get; set; }
|
||||
|
||||
[BsonElement("Rain")]
|
||||
public int Rain { get; set; }
|
||||
|
||||
[BsonElement("Nextdays")]
|
||||
public int Nextdays { get; set; }
|
||||
}
|
||||
}
|
||||
55
MyCore/Services/DeviceService.cs
Normal file
55
MyCore/Services/DeviceService.cs
Normal file
@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using MyCore.Models;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using MongoDB.Driver;
|
||||
|
||||
namespace MyCore.Services
|
||||
{
|
||||
public class DeviceService
|
||||
{
|
||||
private readonly IMongoCollection<Device> _devices;
|
||||
|
||||
public DeviceService(IConfiguration config)
|
||||
{
|
||||
var client = new MongoClient(config.GetConnectionString("MyCoreDb"));
|
||||
var database = client.GetDatabase("MyCoreDb");
|
||||
_devices = database.GetCollection<Device>("Devices");
|
||||
}
|
||||
|
||||
public List<Device> GetAll()
|
||||
{
|
||||
return _devices.Find(m => true).ToList();
|
||||
}
|
||||
|
||||
public Device GetDeviceInfo(string id)
|
||||
{
|
||||
return _devices.Find<Device>(m => m.Id == id).FirstOrDefault();
|
||||
}
|
||||
|
||||
public Device CreateDevice(Device device)
|
||||
{
|
||||
_devices.InsertOne(device);
|
||||
return device;
|
||||
}
|
||||
|
||||
public void Update(string id, Device deviceIn)
|
||||
{
|
||||
_devices.ReplaceOne(device => device.Id == id, deviceIn);
|
||||
}
|
||||
|
||||
public void Remove(Device deviceIn)
|
||||
{
|
||||
_devices.DeleteOne(device => device.Id == deviceIn.Id);
|
||||
}
|
||||
|
||||
public void Remove(string id)
|
||||
{
|
||||
_devices.DeleteOne(device => device.Id == id);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user