From 2feb822e8e1d3b4fd364afe27572e5c63cf4f567 Mon Sep 17 00:00:00 2001 From: Alexandertp Date: Tue, 19 Dec 2023 14:28:48 +0100 Subject: [PATCH] Add frontend display child list, add allow updating dispenses --- backend/Controllers/UserController.cs | 24 ++++++++++++++++++ backend/Program.cs | 1 + frontend/src/assets/main.css | 7 ++++++ frontend/src/views/HomeView.vue | 36 +++++++++++++++++++++++++++ 4 files changed, 68 insertions(+) diff --git a/backend/Controllers/UserController.cs b/backend/Controllers/UserController.cs index c1670d9..10360c0 100644 --- a/backend/Controllers/UserController.cs +++ b/backend/Controllers/UserController.cs @@ -135,10 +135,34 @@ public class UserController : ControllerBase var users = ApplicationState.DbContext!.Users .Where(user => !user.IsParent) .Select(user => new { + id = user.Id, username = user.Username, dispenses = user.Dispenses, }); return new JsonResult(users); } + + [HttpPut] + [Route("Children/{id}/Dispenses")] + [MiddlewareFilter(typeof(ParentMiddlewareBuilder))] + public IActionResult UpdateChildDispenses(int id, [FromBody] JsonObject input) + { + int dispenses; + if (!int.TryParse(input["dispenses"]?.ToString(), out dispenses)) { + return BadRequest("Dispenses must be number"); + } + if (dispenses < 0) { + return BadRequest("Dispenses cannot be less than 0"); + } + + var user = ApplicationState.DbContext!.Users.Find(id); + if (user == null) { + return BadRequest("Invalid user ID"); + } + user.Dispenses = dispenses; + + ApplicationState.DbContext!.SaveChanges(); + return Ok(); + } } diff --git a/backend/Program.cs b/backend/Program.cs index 6478baa..4bc5031 100644 --- a/backend/Program.cs +++ b/backend/Program.cs @@ -24,6 +24,7 @@ app.UseCors(builder => { builder.AllowAnyHeader(); builder.WithOrigins("http://localhost:5173"); builder.AllowCredentials(); + builder.AllowAnyMethod(); }); //app.UseHttpsRedirection(); diff --git a/frontend/src/assets/main.css b/frontend/src/assets/main.css index ef37760..3d82917 100644 --- a/frontend/src/assets/main.css +++ b/frontend/src/assets/main.css @@ -52,3 +52,10 @@ nav a:not(.router-link-active):hover { height: 1em; } +td, th { + border: 1px solid white; + padding: 5px; +} +th { + background-color: black; +} diff --git a/frontend/src/views/HomeView.vue b/frontend/src/views/HomeView.vue index 55f6909..c2fe04a 100644 --- a/frontend/src/views/HomeView.vue +++ b/frontend/src/views/HomeView.vue @@ -1,13 +1,27 @@