renamed model folder

This commit is contained in:
LilleBRG 2025-04-01 13:15:25 +02:00
parent 82efeff40b
commit 9529d2cdc8
12 changed files with 37 additions and 16 deletions

View File

@ -1,5 +1,6 @@
using Api.DBAccess;
using Api.Models;
using Api.Models.Devices;
using Microsoft.AspNetCore.Mvc;
namespace Api.BusinessLogic
@ -41,12 +42,22 @@ namespace Api.BusinessLogic
/// <param name="device">The new device</param>
/// <param name="userId">The user that owns the device</param>
/// <returns>returns true in a OkObjectResult and if there is some error it returns a ConflictObjectResult and a message that explain the reason</returns>
public async Task<IActionResult> AddDevice(Device device, int userId)
public async Task<IActionResult> AddDevice(string referenceId, int userId)
{
var profile = await _dbAccess.ReadUser(userId);
if (profile == null) { return new ConflictObjectResult(new { message = "Could not find user" }); }
Device device = new Device
{
Name = "Undefined",
TempHigh = 0,
TempLow = 0,
ReferenceId = referenceId,
Logs = new List<TemperatureLogs>(),
};
return await _dbAccess.CreateDevice(device, userId);
}

View File

@ -1,6 +1,7 @@
using Api.DBAccess;
using Api.Models;
using Api.Models.User;
using Api.Models.Devices;
using Api.Models.Users;
using Microsoft.AspNetCore.Http.HttpResults;
using Microsoft.AspNetCore.Mvc;
using Microsoft.IdentityModel.Tokens;

View File

@ -4,6 +4,7 @@ using Api.DBAccess;
using Microsoft.AspNetCore.Authorization;
using Api.BusinessLogic;
using System.Security.Claims;
using Api.Models.Devices;
namespace Api.Controllers
{
@ -34,12 +35,12 @@ namespace Api.Controllers
// Sends the device and userId to deviceLogic
[Authorize]
[HttpPost("adddevice")]
public async Task<IActionResult> AddDevice([FromBody] Device device)
public async Task<IActionResult> AddDevice([FromBody] string referenceId)
{
var claims = HttpContext.User.Claims;
string userIdString = claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value;
int userId = Convert.ToInt32(userIdString);
return await _deviceLogic.AddDevice(device, userId);
return await _deviceLogic.AddDevice(referenceId, userId);
}
// Sends the deviceId to deviceLogic

View File

@ -3,7 +3,7 @@ using Api.Models;
using System.Security.Claims;
using Microsoft.AspNetCore.Authorization;
using Api.BusinessLogic;
using Api.Models.User;
using Api.Models.Users;
namespace Api.Controllers
{

View File

@ -2,7 +2,8 @@
using Api.Models;
using Microsoft.AspNetCore.Mvc;
using static System.Runtime.InteropServices.JavaScript.JSType;
using Api.Models.User;
using Api.Models.Devices;
using Api.Models.Users;
namespace Api.DBAccess

View File

@ -1,6 +1,6 @@
using Microsoft.EntityFrameworkCore;
using Api.Models;
using Api.Models.User;
using Api.Models.Users;
using Api.Models.Devices;
namespace Api
{

View File

@ -1,4 +1,4 @@
namespace Api.Models
namespace Api.Models.Devices
{
public class Device
{

View File

@ -0,0 +1,6 @@
namespace Api.Models.Devices
{
public class EditDeviceRequest
{
}
}

View File

@ -1,4 +1,4 @@
namespace Api.Models.User
namespace Api.Models.Users
{
public class ChangePasswordRequest
{

View File

@ -1,4 +1,4 @@
namespace Api.Models.User
namespace Api.Models.Users
{
public class EditUserRequest
{

View File

@ -1,4 +1,6 @@
namespace Api.Models.User
using Api.Models.Devices;
namespace Api.Models.Users
{
public class User
{

View File

@ -1,10 +1,9 @@
import { getDevices, deleteDevice, update, add } from "./services/devices.service.js";
import { devices } from "../mockdata/devices.mockdata.js";
import { logout } from "../shared/utils.js";
getDevices().then(res => {
buildTable(res)
})
// getDevices().then(res => {
// buildTable(res)
// })
buildTable(devices);