Code cleanup, 2022 edition

This commit is contained in:
Laura Hausmann 2022-02-09 20:51:35 +01:00
parent db4a42171d
commit 1d9712294f
Signed by: zotan
GPG key ID: D044E84C5BE01605
16 changed files with 230 additions and 237 deletions

View file

@ -1,10 +1,10 @@
using LinqToDB.Mapping;
namespace c3stream.DataModels.Tables {
[Table(Name = "States")]
public class States {
namespace c3stream.DataModels.Tables;
[Table(Name = "States")]
public class States {
[Column(Name = "TalkId"), PrimaryKey, NotNull] public string TalkId { get; set; }
[Column(Name = "UserId"), PrimaryKey, NotNull] public string UserId { get; set; }
[Column(Name = "State"), NotNull] public string State { get; set; }
}
}

View file

@ -11,7 +11,7 @@ namespace c3stream;
public static class Migrations {
private const int DbVer = 0;
private static readonly List<Migration> _migrations = new() { };
private static readonly List<Migration> _migrations = new();
public static void RunMigrations() {
using var db = new Database.DbConn();

View file

@ -1,8 +1,6 @@
@page
@model ConferenceModel
@using System.Net
@using global::c3stream.DataModels
@using static ConferenceModel
@model ConferenceModel
@{
if (c3stream.Conferences.All(c => c.Acronym != Request.Query["c"])) {
Response.Redirect("/");

View file

@ -1,14 +1,13 @@
using System.Collections.Generic;
using System.Linq;
using System.Linq;
using c3stream.DataModels;
using c3stream.DataModels.Tables;
using LinqToDB;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
namespace c3stream.Pages {
public class ConferenceModel : PageModel {
namespace c3stream.Pages;
public class ConferenceModel : PageModel {
private readonly ILogger<ConferenceModel> _logger;
public ConferenceModel(ILogger<ConferenceModel> logger) => _logger = logger;
@ -23,17 +22,16 @@ namespace c3stream.Pages {
using var db = new Database.DbConn();
var existing = db.States.FirstOrDefault(p => p.TalkId == guid && p.UserId == userid);
if (existing != null)
if (state == "unwatched")
if (state == "unwatched") {
db.States.Delete(p => p == existing);
}
else {
existing.State = state;
db.Update(existing);
}
else
db.Insert(new States {
State = state, TalkId = guid, UserId = userid
});
db.Insert(new States { State = state, TalkId = guid, UserId = userid });
Response.Redirect("/");
}
}
}

View file

@ -3,9 +3,10 @@ using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.Extensions.Logging;
namespace c3stream.Pages {
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public class ErrorModel : PageModel {
namespace c3stream.Pages;
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public class ErrorModel : PageModel {
private readonly ILogger<ErrorModel> _logger;
public ErrorModel(ILogger<ErrorModel> logger) => _logger = logger;
@ -17,5 +18,4 @@ namespace c3stream.Pages {
public void OnGet() {
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
}
}
}

View file

@ -1,12 +1,12 @@
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.Extensions.Logging;
namespace c3stream.Pages {
public class IndexModel : PageModel {
namespace c3stream.Pages;
public class IndexModel : PageModel {
private readonly ILogger<IndexModel> _logger;
public IndexModel(ILogger<IndexModel> logger) => _logger = logger;
public void OnGet() { }
}
}

View file

@ -1,12 +1,12 @@
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.Extensions.Logging;
namespace c3stream.Pages {
public class InfoModel : PageModel {
namespace c3stream.Pages;
public class InfoModel : PageModel {
private readonly ILogger<InfoModel> _logger;
public InfoModel(ILogger<InfoModel> logger) => _logger = logger;
public void OnGet() { }
}
}

View file

@ -1,12 +1,12 @@
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.Extensions.Logging;
namespace c3stream.Pages {
public class PrivacyModel : PageModel {
namespace c3stream.Pages;
public class PrivacyModel : PageModel {
private readonly ILogger<PrivacyModel> _logger;
public PrivacyModel(ILogger<PrivacyModel> logger) => _logger = logger;
public void OnGet() { }
}
}

View file

@ -1,10 +1,8 @@
@page
@model WatchlistModel
@using System.Net
@using global::c3stream.DataModels
@using static WatchlistModel
@model WatchlistModel
@{
var cookie = c3stream.UpdateCookie(Request, Response, $"/Watchlist");
var cookie = c3stream.UpdateCookie(Request, Response, "/Watchlist");
ViewData["Title"] = "Watchlist";
await using var db = new Database.DbConn();
var states = db.States.ToList();

View file

@ -1,14 +1,13 @@
using System.Collections.Generic;
using System.Linq;
using System.Linq;
using c3stream.DataModels;
using c3stream.DataModels.Tables;
using LinqToDB;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
namespace c3stream.Pages {
public class WatchlistModel : PageModel {
namespace c3stream.Pages;
public class WatchlistModel : PageModel {
private readonly ILogger<ConferenceModel> _logger;
public WatchlistModel(ILogger<ConferenceModel> logger) => _logger = logger;
@ -23,17 +22,16 @@ namespace c3stream.Pages {
using var db = new Database.DbConn();
var existing = db.States.FirstOrDefault(p => p.TalkId == guid && p.UserId == userid);
if (existing != null)
if (state == "unwatched")
if (state == "unwatched") {
db.States.Delete(p => p == existing);
}
else {
existing.State = state;
db.Update(existing);
}
else
db.Insert(new States {
State = state, TalkId = guid, UserId = userid
});
db.Insert(new States { State = state, TalkId = guid, UserId = userid });
Response.Redirect("/");
}
}
}

View file

@ -1 +1,2 @@
c3stream is a small proxy site meant for saving watched status & watch-later-lists for media.ccc.de talks. Test in production at https://c3stream.de
c3stream is a small proxy site meant for saving watched status & watch-later-lists for media.ccc.de talks. Test in
production at https://c3stream.de

View file

@ -4,8 +4,9 @@ using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
namespace c3stream {
public class Startup {
namespace c3stream;
public class Startup {
public Startup(IConfiguration configuration) => Configuration = configuration;
public IConfiguration Configuration { get; }
@ -31,5 +32,4 @@ namespace c3stream {
app.UseEndpoints(endpoints => { endpoints.MapRazorPages(); });
}
}
}