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 @@ @@ -21,6 +35,28 @@ async function dispense() { Your touch code is: {{ userStore.state.userInfo.touchCode }} Use this code to login on the dispenser + + + + Users: + + + + Username + Dispenses + + + {{ child.username }} + + + Save + + + + + + + {{ error }}
Use this code to login on the dispenser
{{ error }}