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.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<IHostedService, vassago.ConsoleService>();
|
||||
builder.Services.AddDbContext<ChattingContext>();
|
||||
builder.Services.AddControllers().AddNewtonsoftJson();
|
||||
builder.Services.AddProblemDetails();
|
||||
builder.Services.Configure<RazorViewEngineOptions>(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();
|
||||
|
@ -18,18 +18,27 @@ public class ChannelsController : ControllerBase
|
||||
_db = db;
|
||||
}
|
||||
|
||||
[HttpGet("{id}")]
|
||||
[Produces("application/json")]
|
||||
public Channel Get(Guid id)
|
||||
{
|
||||
return _db.Find<Channel>(id);
|
||||
}
|
||||
[HttpGet("{id}")]
|
||||
[Produces("application/json")]
|
||||
public Channel Get(Guid id)
|
||||
{
|
||||
return _db.Find<Channel>(id);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Produces("application/json")]
|
||||
public Channel Post([FromBody] Channel channel)
|
||||
{
|
||||
// Write logic to insert employee data
|
||||
return new Channel();
|
||||
}
|
||||
}
|
||||
[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);
|
||||
}
|
||||
}
|
||||
|
@ -17,11 +17,13 @@
|
||||
<tr>
|
||||
<th scope="row">Lewdness Filter Level</th>
|
||||
<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>
|
||||
@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>
|
||||
</td>
|
||||
@ -44,7 +46,17 @@
|
||||
</tr>
|
||||
<tr>
|
||||
<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>
|
||||
<th scope="row">Messages (count)</th>
|
||||
@ -72,19 +84,24 @@
|
||||
|
||||
@section Scripts{
|
||||
<script type="text/javascript">
|
||||
@{
|
||||
var modelAsString = JsonConvert.SerializeObject(Model, new JsonSerializerSettings
|
||||
{
|
||||
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
|
||||
});
|
||||
}
|
||||
const channelOnLoad = @Html.Raw(modelAsString);
|
||||
function jsonifyChannel()
|
||||
{
|
||||
var channelNow = channelOnLoad;
|
||||
channelNow.LewdnessFilterLevel = document.querySelector("#LewdnessFilterLevel").value;
|
||||
console.log(channelNow);
|
||||
return channelNow;
|
||||
@{
|
||||
var modelAsString = JsonConvert.SerializeObject(Model, new JsonSerializerSettings
|
||||
{
|
||||
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
|
||||
});
|
||||
}
|
||||
const channelOnLoad = @Html.Raw(modelAsString);
|
||||
function jsonifyChannel() {
|
||||
var channelNow = structuredClone(channelOnLoad);
|
||||
channelNow.SubChannels = null;
|
||||
channelNow.ParentChannel = null;
|
||||
channelNow.Messages = null;
|
||||
channelNow.Users = null;
|
||||
|
||||
channelNow.LewdnessFilterLevel = document.querySelector("#LewdnessFilterLevel").value;
|
||||
channelNow.MeannessFilterLevel = document.querySelector("#MeannessFilterLevel").value;
|
||||
console.log(channelNow);
|
||||
return channelNow;
|
||||
}
|
||||
</script>
|
||||
}
|
@ -9,6 +9,7 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="bootstrap" Version="5.3.3" />
|
||||
<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">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
|
@ -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',
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user