From 0ac28c35fb71e7e64cc94928134ea0e7c1eced3e Mon Sep 17 00:00:00 2001 From: Adam R Grey Date: Sun, 23 Jun 2024 20:31:09 -0400 Subject: [PATCH] the api to commit web interface changes to a channel works --- Program.cs | 13 +++++ .../Controllers/api/ChannelsControler.cs | 37 +++++++++----- WebInterface/Views/Channels/Details.cshtml | 51 ++++++++++++------- vassago.csproj | 1 + wwwroot/js/site.js | 4 +- 5 files changed, 73 insertions(+), 33 deletions(-) diff --git a/Program.cs b/Program.cs index 469c76c..7b5c9f0 100644 --- a/Program.cs +++ b/Program.cs @@ -1,13 +1,18 @@ using Microsoft.AspNetCore.Mvc.Razor; using Microsoft.EntityFrameworkCore; +using Microsoft.AspNetCore.Mvc.NewtonsoftJson; using vassago.Models; +#pragma warning disable CA2254 + var builder = WebApplication.CreateBuilder(args); // Add services to the container. builder.Services.AddControllersWithViews(); builder.Services.AddSingleton(); builder.Services.AddDbContext(); +builder.Services.AddControllers().AddNewtonsoftJson(); +builder.Services.AddProblemDetails(); builder.Services.Configure(o => { o.ViewLocationFormats.Clear(); o.ViewLocationFormats.Add("/WebInterface/Views/{1}/{0}" + RazorViewEngine.ViewExtension); @@ -37,4 +42,12 @@ app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "api"); }); +app.UseExceptionHandler(); +app.UseStatusCodePages(); + +if (app.Environment.IsDevelopment()) +{ + app.UseDeveloperExceptionPage(); +} + app.Run(); diff --git a/WebInterface/Controllers/api/ChannelsControler.cs b/WebInterface/Controllers/api/ChannelsControler.cs index 784ffc5..4bdb097 100644 --- a/WebInterface/Controllers/api/ChannelsControler.cs +++ b/WebInterface/Controllers/api/ChannelsControler.cs @@ -18,18 +18,27 @@ public class ChannelsController : ControllerBase _db = db; } - [HttpGet("{id}")] - [Produces("application/json")] - public Channel Get(Guid id) - { - return _db.Find(id); - } + [HttpGet("{id}")] + [Produces("application/json")] + public Channel Get(Guid id) + { + return _db.Find(id); + } - [HttpPost] - [Produces("application/json")] - public Channel Post([FromBody] Channel channel) - { - // Write logic to insert employee data - return new Channel(); - } -} \ No newline at end of file + [HttpPatch] + [Produces("application/json")] + public IActionResult Patch([FromBody] Channel channel) + { + var fromDb = _db.Channels.Find(channel.Id); + if (fromDb == null) + { + _logger.LogError($"attempt to update channel {channel.Id}, not found"); //ca2254 is moronic. maybe if it wasn't filed under "code quality" and instead was filed under "you didn't include a workaround for the weaknesses of other external junk" i'd be kinder to it ;) + return NotFound(); + } + //settable values: lewdness filter level, meanness filter level. maybe i could decorate them... + fromDb.LewdnessFilterLevel = channel.LewdnessFilterLevel; + fromDb.MeannessFilterLevel = channel.MeannessFilterLevel; + _db.SaveChanges(); + return Ok(fromDb); + } +} diff --git a/WebInterface/Views/Channels/Details.cshtml b/WebInterface/Views/Channels/Details.cshtml index b35024b..342ffb2 100644 --- a/WebInterface/Views/Channels/Details.cshtml +++ b/WebInterface/Views/Channels/Details.cshtml @@ -17,11 +17,13 @@ Lewdness Filter Level - inhereted - @foreach (Enumerations.LewdnessFilterLevel enumVal in Enum.GetValues(typeof(Enumerations.LewdnessFilterLevel))) + @foreach (Enumerations.LewdnessFilterLevel enumVal in + Enum.GetValues(typeof(Enumerations.LewdnessFilterLevel))) { - @(Enumerations.GetDescription(enumVal)) + + @(Enumerations.GetDescription(enumVal)) } @@ -44,7 +46,17 @@ Meanness Filter Level - @(Model.MeannessFilterLevel != null ? Enumerations.GetDescription(Model.MeannessFilterLevel.GetValueOrDefault()) : "inherited") + + + Messages (count) @@ -72,19 +84,24 @@ @section Scripts{ } \ No newline at end of file diff --git a/vassago.csproj b/vassago.csproj index 958e03f..f4baece 100644 --- a/vassago.csproj +++ b/vassago.csproj @@ -9,6 +9,7 @@ + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/wwwroot/js/site.js b/wwwroot/js/site.js index ad5f755..ec49115 100644 --- a/wwwroot/js/site.js +++ b/wwwroot/js/site.js @@ -7,7 +7,7 @@ function testfunct(caller){ console.log("[gibberish]"); console.log(caller); } -function postmodelupdate(model) +function patchModel(model) { //structure the model your (dang) self into a nice object console.log(model); @@ -28,7 +28,7 @@ function postmodelupdate(model) console.log("dexter impression: I am now ready to post the following content:"); console.log(JSON.stringify(model)); fetch(apiUrl, { - method: 'POST', + method: 'PATCH', headers: { 'Content-Type': 'application/json', },