no errors after merge. update database please

This commit is contained in:
LilleBRG 2025-03-31 15:49:35 +02:00
parent db023ac84e
commit c9155d582b
13 changed files with 58 additions and 77 deletions

View File

@ -41,21 +41,12 @@ 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(string referenceId, int userId)
public async Task<IActionResult> AddDevice(Device device, 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

@ -102,7 +102,7 @@ namespace Api.BusinessLogic
/// <returns>returns the updated user 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> EditProfile(User user, int userId)
{
return await _dbAccess.UpdateUser(userRequest, userId);
return await _dbAccess.UpdateUser(user, userId);
}
public async Task<IActionResult> changePassword(ChangePasswordRequest passwordRequest, int userId)

View File

@ -68,13 +68,5 @@ namespace Api.Controllers
{
return await _deviceLogic.EditDevice(device, deviceId);
}
[Authorize]
[HttpDelete("Delete/{referenceId}")]
public async Task<IActionResult> EditDevice(string referenceId)
{
return await _deviceLogic.EditDevice(referenceId);
}
}
}

View File

@ -19,13 +19,15 @@ namespace Api.Controllers
}
//[Authorize]
[HttpGet("{userId}")]
public async Task<IActionResult> GetUSer(int userId)
[HttpGet("Get")]
public async Task<IActionResult> GetUSer()
{
var claims = HttpContext.User.Claims;
string userIdString = claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value;
int userId = Convert.ToInt32(userIdString);
return await _userLogic.getUser(userId);
}
[HttpPost("login")]
// Sends the login to userLogic
[HttpPost("Login")]
public async Task<IActionResult> Login([FromBody] Login login)
{

View File

@ -21,13 +21,6 @@ namespace Api.DBAccess
return await _context.Users.FirstOrDefaultAsync(u => u.Id == userId);
}
public async Task<User> getUser(int userId)
{
return await _context.Users.FirstOrDefaultAsync(u => u.Id == userId);
}
/// <summary>
/// Creates a user using entityframework core
/// </summary>

View File

@ -13,16 +13,16 @@
<body>
<div id="container">
<div class="topnav">
<a href="/home/index.html">Home</a>
<div class="topnav">
<a href="/home/index.html">Home</a>
<div style="display: flex; justify-content: flex-end;">
<a class="active" href="/devices/index.html">Devices</a>
<div style="display: flex; justify-content: flex-end;">
<a href="/profile/index.html">Profile</a>
<span class="logoutContainer">
<img class="logout" src="/img/logout.png">
</span>
</div>
</div>
<a href="/profile/index.html">Profile</a>
<span class="logoutContainer">
<img class="logout" src="/img/logout.png">
</span>
</div>
</div>
<div class="addDeviceContainer">
<button id="addDevice">Add Device</button>
</div>

View File

@ -8,16 +8,20 @@
<script defer type="module" src="/scripts/home.js"></script>
<link rel="stylesheet" href="/styles/common.css">
<link rel="stylesheet" href="/styles/home.css" />
<link rel="stylesheet" href="/styles/auth.css" />
</head>
<body>
<div class="topnav">
<a class="active" href="/home/index.html">Home</a>
<div style="display: flex; justify-content: flex-end;">
<a class="" href="/home/index.html">Devices</a>
<a class="" href="/profile/index.html">Profile</a>
<a href="/devices/index.html">Devices</a>
<a href="/profile/index.html">Profile</a>
<span class="logoutContainer">
<img class="logout" src="/img/logout.png">
</span>
</div>
</div>
</div>
<div id="container">
<div class="chart-container">
<canvas id="myChart" style="width: 49%; height: 49%;"></canvas>

View File

@ -13,20 +13,23 @@
<div id="container">
<div class="topnav">
<a href="/home/index.html">Home</a>
<a href="/devices/index.html">Devices</a>
<div style="display: flex; justify-content: flex-end;">
<a href="/devices/index.html">Devices</a>
<a class="active" href="/profile/index.html">Profile</a>
<span class="logoutContainer">
<img class="logout" src="/img/logout.png">
</span>
</div>
</div>
<div id="profileCard"></div>
<div class="btnContainer">
<button class="btn" id="openEditModal">Edit</button>
<button class="btn" id="openPasswordModal">Change Password</button>
</div>
<div style="display: flex; justify-content: center;">
<div class="profileContainer">
<div id="profileCard"></div>
<div class="btnContainer">
<button class="btn" id="openEditModal">Edit</button>
<button class="btn" id="openPasswordModal">Change Password</button>
</div>
</div>
</div>
</div>
<div id="editModal" class="modal">

View File

@ -1,10 +1,10 @@
import { getDevicesOnUserId, deleteDevice, update, add } from "./services/devices.service.js";
import { getDevices, deleteDevice, update, add } from "./services/devices.service.js";
import { devices } from "../mockdata/devices.mockdata.js";
let id = localStorage.getItem("id");
// getDevicesOnUserId(id).then(res => {
// buildTable(res)
// })
getDevices().then(res => {
buildTable(res)
})
buildTable(devices);
let selectedReferenceId = null; // Store the selected referenceId

View File

@ -1,17 +1,7 @@
import { address } from "../../shared/constants.js";
import { request } from "../../shared/utils.js";
export function getDevicesOnUserId(userId) {
fetch(`${address}/device/${userId}`, {
method: "GET",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({ id: id })
})
.then(response => response.json())
.then(data => console.log("Success:", data))
.catch(error => console.error("Error:", error));
export function getDevices() {
return request("GET", "/device");
}
export function update(ids) {

View File

@ -1,17 +1,8 @@
import { request } from "../../shared/utils.js";
import { address } from "../../shared/constants.js";
import { handleResponse } from "../../shared/utils.js";
export function get(userId) {
return fetch(`${address}/user/${userId}`, {
method: "GET",
headers: {
"Content-Type": "application/json"
},
})
.then(handleResponse)
.catch(err => { error: err.message });
export function get() {
return request("GET",`/user/get`)
}
export function login(usernameOrEmail, password) {

View File

@ -8,3 +8,9 @@
margin-top: 1rem;
}
.logout{
width: 20px;
height: 24px;
}

View File

@ -85,3 +85,12 @@ h2{
width: 90%;
}
.profileContainer {
margin: 2rem 0;
background-color: white;
border-radius: 8px;
border: 1px solid #DDD;
box-shadow: 2px 2px 2px rgba(0, 0, 0, 0.1);
width: 400px;
}