forked from adam/discord-bot-shtik
the api to commit web interface changes to a channel works
This commit is contained in:
parent
942b11fcce
commit
0ac28c35fb
13
Program.cs
13
Program.cs
@ -1,13 +1,18 @@
|
|||||||
using Microsoft.AspNetCore.Mvc.Razor;
|
using Microsoft.AspNetCore.Mvc.Razor;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.AspNetCore.Mvc.NewtonsoftJson;
|
||||||
using vassago.Models;
|
using vassago.Models;
|
||||||
|
|
||||||
|
#pragma warning disable CA2254
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
// Add services to the container.
|
// Add services to the container.
|
||||||
builder.Services.AddControllersWithViews();
|
builder.Services.AddControllersWithViews();
|
||||||
builder.Services.AddSingleton<IHostedService, vassago.ConsoleService>();
|
builder.Services.AddSingleton<IHostedService, vassago.ConsoleService>();
|
||||||
builder.Services.AddDbContext<ChattingContext>();
|
builder.Services.AddDbContext<ChattingContext>();
|
||||||
|
builder.Services.AddControllers().AddNewtonsoftJson();
|
||||||
|
builder.Services.AddProblemDetails();
|
||||||
builder.Services.Configure<RazorViewEngineOptions>(o => {
|
builder.Services.Configure<RazorViewEngineOptions>(o => {
|
||||||
o.ViewLocationFormats.Clear();
|
o.ViewLocationFormats.Clear();
|
||||||
o.ViewLocationFormats.Add("/WebInterface/Views/{1}/{0}" + RazorViewEngine.ViewExtension);
|
o.ViewLocationFormats.Add("/WebInterface/Views/{1}/{0}" + RazorViewEngine.ViewExtension);
|
||||||
@ -37,4 +42,12 @@ app.UseSwaggerUI(c =>
|
|||||||
c.SwaggerEndpoint("/swagger/v1/swagger.json", "api");
|
c.SwaggerEndpoint("/swagger/v1/swagger.json", "api");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.UseExceptionHandler();
|
||||||
|
app.UseStatusCodePages();
|
||||||
|
|
||||||
|
if (app.Environment.IsDevelopment())
|
||||||
|
{
|
||||||
|
app.UseDeveloperExceptionPage();
|
||||||
|
}
|
||||||
|
|
||||||
app.Run();
|
app.Run();
|
||||||
|
@ -25,11 +25,20 @@ public class ChannelsController : ControllerBase
|
|||||||
return _db.Find<Channel>(id);
|
return _db.Find<Channel>(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPatch]
|
||||||
[Produces("application/json")]
|
[Produces("application/json")]
|
||||||
public Channel Post([FromBody] Channel channel)
|
public IActionResult Patch([FromBody] Channel channel)
|
||||||
{
|
{
|
||||||
// Write logic to insert employee data
|
var fromDb = _db.Channels.Find(channel.Id);
|
||||||
return new Channel();
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -17,11 +17,13 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<th scope="row">Lewdness Filter Level</th>
|
<th scope="row">Lewdness Filter Level</th>
|
||||||
<td>
|
<td>
|
||||||
<select name="LewdnessFilterLevel" id="LewdnessFilterLevel" onchange="postmodelupdate(jsonifyChannel())">
|
<select name="LewdnessFilterLevel" id="LewdnessFilterLevel" onchange="patchModel(jsonifyChannel())">
|
||||||
<!option value="" @(Model.LewdnessFilterLevel == null ? "selected" : "")>inhereted</!option>
|
<!option value="" @(Model.LewdnessFilterLevel == null ? "selected" : "")>inhereted</!option>
|
||||||
@foreach (Enumerations.LewdnessFilterLevel enumVal in Enum.GetValues(typeof(Enumerations.LewdnessFilterLevel)))
|
@foreach (Enumerations.LewdnessFilterLevel enumVal in
|
||||||
|
Enum.GetValues(typeof(Enumerations.LewdnessFilterLevel)))
|
||||||
{
|
{
|
||||||
<!option value="@((int)enumVal)" @(Model.LewdnessFilterLevel == enumVal ? "selected" : "")>@(Enumerations.GetDescription<Enumerations.LewdnessFilterLevel>(enumVal))</!option>
|
<!option value="@((int)enumVal)" @(Model.LewdnessFilterLevel == enumVal ? "selected" : "")>
|
||||||
|
@(Enumerations.GetDescription<Enumerations.LewdnessFilterLevel>(enumVal))</!option>
|
||||||
}
|
}
|
||||||
</select>
|
</select>
|
||||||
</td>
|
</td>
|
||||||
@ -44,7 +46,17 @@
|
|||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">Meanness Filter Level</th>
|
<th scope="row">Meanness Filter Level</th>
|
||||||
<td>@(Model.MeannessFilterLevel != null ? Enumerations.GetDescription<Enumerations.MeannessFilterLevel>(Model.MeannessFilterLevel.GetValueOrDefault()) : "inherited")</td>
|
<td>
|
||||||
|
<select name="MeannessFilterLevel" id="MeannessFilterLevel" onchange="patchModel(jsonifyChannel())">
|
||||||
|
<!option value="" @(Model.MeannessFilterLevel == null ? "selected" : "")>⤵ inhereted</!option>
|
||||||
|
@foreach (Enumerations.MeannessFilterLevel enumVal in
|
||||||
|
Enum.GetValues(typeof(Enumerations.MeannessFilterLevel)))
|
||||||
|
{
|
||||||
|
<!option value="@((int)enumVal)" @(Model.MeannessFilterLevel == enumVal ? "selected" : "")>
|
||||||
|
@(Enumerations.GetDescription<Enumerations.MeannessFilterLevel>(enumVal))</!option>
|
||||||
|
}
|
||||||
|
</select>
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">Messages (count)</th>
|
<th scope="row">Messages (count)</th>
|
||||||
@ -79,10 +91,15 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
const channelOnLoad = @Html.Raw(modelAsString);
|
const channelOnLoad = @Html.Raw(modelAsString);
|
||||||
function jsonifyChannel()
|
function jsonifyChannel() {
|
||||||
{
|
var channelNow = structuredClone(channelOnLoad);
|
||||||
var channelNow = channelOnLoad;
|
channelNow.SubChannels = null;
|
||||||
|
channelNow.ParentChannel = null;
|
||||||
|
channelNow.Messages = null;
|
||||||
|
channelNow.Users = null;
|
||||||
|
|
||||||
channelNow.LewdnessFilterLevel = document.querySelector("#LewdnessFilterLevel").value;
|
channelNow.LewdnessFilterLevel = document.querySelector("#LewdnessFilterLevel").value;
|
||||||
|
channelNow.MeannessFilterLevel = document.querySelector("#MeannessFilterLevel").value;
|
||||||
console.log(channelNow);
|
console.log(channelNow);
|
||||||
return channelNow;
|
return channelNow;
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="bootstrap" Version="5.3.3" />
|
<PackageReference Include="bootstrap" Version="5.3.3" />
|
||||||
<PackageReference Include="discord.net" Version="3.10.0" />
|
<PackageReference Include="discord.net" Version="3.10.0" />
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="7.0.20" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.5">
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.5">
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
@ -7,7 +7,7 @@ function testfunct(caller){
|
|||||||
console.log("[gibberish]");
|
console.log("[gibberish]");
|
||||||
console.log(caller);
|
console.log(caller);
|
||||||
}
|
}
|
||||||
function postmodelupdate(model)
|
function patchModel(model)
|
||||||
{
|
{
|
||||||
//structure the model your (dang) self into a nice object
|
//structure the model your (dang) self into a nice object
|
||||||
console.log(model);
|
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("dexter impression: I am now ready to post the following content:");
|
||||||
console.log(JSON.stringify(model));
|
console.log(JSON.stringify(model));
|
||||||
fetch(apiUrl, {
|
fetch(apiUrl, {
|
||||||
method: 'POST',
|
method: 'PATCH',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user