chore: clean up backend code, fix most inspections

This commit is contained in:
sam 2024-12-14 16:51:58 +01:00
parent 49b2902d6d
commit 11257ae069
Signed by: sam
GPG key ID: B4EF20DDE721CAA1
21 changed files with 86 additions and 27 deletions

View file

@ -12,6 +12,8 @@
// //
// You should have received a copy of the GNU Affero General Public License // You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
// ReSharper disable UnusedAutoPropertyAccessor.Global
using Serilog.Events; using Serilog.Events;
namespace Foxnouns.Backend; namespace Foxnouns.Backend;
@ -20,8 +22,8 @@ public class Config
{ {
public string Host { get; init; } = "localhost"; public string Host { get; init; } = "localhost";
public int Port { get; init; } = 3000; public int Port { get; init; } = 3000;
public string BaseUrl { get; set; } = null!; public string BaseUrl { get; init; } = null!;
public string MediaBaseUrl { get; set; } = null!; public string MediaBaseUrl { get; init; } = null!;
public string Address => $"http://{Host}:{Port}"; public string Address => $"http://{Host}:{Port}";
public string MetricsAddress => $"http://{Host}:{Logging.MetricsPort}"; public string MetricsAddress => $"http://{Host}:{Logging.MetricsPort}";

View file

@ -1,3 +1,17 @@
// Copyright (C) 2023-present sam/u1f320 (vulpine.solutions)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
using System.Net; using System.Net;
using System.Web; using System.Web;
using EntityFramework.Exceptions.Common; using EntityFramework.Exceptions.Common;

View file

@ -73,7 +73,7 @@ public class FlagsController(
await db.SaveChangesAsync(); await db.SaveChangesAsync();
queue.QueueInvocableWithPayload<CreateFlagInvocable, CreateFlagPayload>( queue.QueueInvocableWithPayload<CreateFlagInvocable, CreateFlagPayload>(
new CreateFlagPayload(flag.Id, CurrentUser!.Id, req.Name, req.Image, req.Description) new CreateFlagPayload(flag.Id, CurrentUser!.Id, req.Image)
); );
return Accepted(userRenderer.RenderPrideFlag(flag)); return Accepted(userRenderer.RenderPrideFlag(flag));

View file

@ -12,6 +12,8 @@
// //
// You should have received a copy of the GNU Affero General Public License // You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
// ReSharper disable UnusedAutoPropertyAccessor.Global
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using Foxnouns.Backend.Utils; using Foxnouns.Backend.Utils;
using Newtonsoft.Json; using Newtonsoft.Json;
@ -89,5 +91,5 @@ public enum PreferenceSize
public class UserSettings public class UserSettings
{ {
public bool? DarkMode { get; set; } = null; public bool? DarkMode { get; set; }
} }

View file

@ -14,6 +14,7 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
// ReSharper disable NotAccessedPositionalProperty.Global // ReSharper disable NotAccessedPositionalProperty.Global
// ReSharper disable UnusedAutoPropertyAccessor.Global
using Foxnouns.Backend.Database; using Foxnouns.Backend.Database;
using Foxnouns.Backend.Utils; using Foxnouns.Backend.Utils;
@ -23,8 +24,6 @@ public record PrideFlagResponse(Snowflake Id, string? ImageUrl, string Name, str
public record CreateFlagRequest(string Name, string Image, string? Description); public record CreateFlagRequest(string Name, string Image, string? Description);
public record CreateFlagResponse(Snowflake Id, string Name, string? Description);
public class UpdateFlagRequest : PatchRequest public class UpdateFlagRequest : PatchRequest
{ {
public string? Name { get; init; } public string? Name { get; init; }

View file

@ -14,6 +14,7 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
// ReSharper disable NotAccessedPositionalProperty.Global // ReSharper disable NotAccessedPositionalProperty.Global
// ReSharper disable UnusedAutoPropertyAccessor.Global
using Foxnouns.Backend.Database; using Foxnouns.Backend.Database;
using Foxnouns.Backend.Database.Models; using Foxnouns.Backend.Database.Models;
using Foxnouns.Backend.Utils; using Foxnouns.Backend.Utils;

View file

@ -15,6 +15,7 @@
// ReSharper disable NotAccessedPositionalProperty.Global // ReSharper disable NotAccessedPositionalProperty.Global
// ReSharper disable ClassNeverInstantiated.Global // ReSharper disable ClassNeverInstantiated.Global
// ReSharper disable UnusedAutoPropertyAccessor.Global
using Foxnouns.Backend.Database; using Foxnouns.Backend.Database;
using Foxnouns.Backend.Database.Models; using Foxnouns.Backend.Database.Models;
using Foxnouns.Backend.Utils; using Foxnouns.Backend.Utils;

View file

@ -57,7 +57,7 @@ public static class WebApplicationExtensions
if (config.Logging.SeqLogUrl != null) if (config.Logging.SeqLogUrl != null)
{ {
logCfg.WriteTo.Seq(config.Logging.SeqLogUrl, LogEventLevel.Verbose); logCfg.WriteTo.Seq(config.Logging.SeqLogUrl);
} }
// AddSerilog doesn't seem to add an ILogger to the service collection, so add that manually. // AddSerilog doesn't seem to add an ILogger to the service collection, so add that manually.

View file

@ -18,12 +18,6 @@ namespace Foxnouns.Backend.Jobs;
public record AvatarUpdatePayload(Snowflake Id, string? NewAvatar); public record AvatarUpdatePayload(Snowflake Id, string? NewAvatar);
public record CreateFlagPayload( public record CreateFlagPayload(Snowflake Id, Snowflake UserId, string ImageData);
Snowflake Id,
Snowflake UserId,
string Name,
string ImageData,
string? Description
);
public record CreateDataExportPayload(Snowflake UserId); public record CreateDataExportPayload(Snowflake UserId);

View file

@ -1,3 +1,17 @@
// Copyright (C) 2023-present sam/u1f320 (vulpine.solutions)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
using Coravel.Mailer.Mail; using Coravel.Mailer.Mail;
namespace Foxnouns.Backend.Mailables; namespace Foxnouns.Backend.Mailables;

View file

@ -1,3 +1,17 @@
// Copyright (C) 2023-present sam/u1f320 (vulpine.solutions)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
using Coravel.Mailer.Mail; using Coravel.Mailer.Mail;
namespace Foxnouns.Backend.Mailables; namespace Foxnouns.Backend.Mailables;

View file

@ -14,7 +14,6 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
using Foxnouns.Backend.Database.Models; using Foxnouns.Backend.Database.Models;
using Foxnouns.Backend.Utils; using Foxnouns.Backend.Utils;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
namespace Foxnouns.Backend.Middleware; namespace Foxnouns.Backend.Middleware;

View file

@ -14,10 +14,8 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
using System.Net; using System.Net;
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
using System.Web;
using Foxnouns.Backend.Database; using Foxnouns.Backend.Database;
using Foxnouns.Backend.Database.Models; using Foxnouns.Backend.Database.Models;
using Foxnouns.Backend.Extensions;
namespace Foxnouns.Backend.Services.Auth; namespace Foxnouns.Backend.Services.Auth;
@ -120,8 +118,7 @@ public partial class FediverseAuthService
private async Task<string> GenerateMisskeyAuthUrlAsync( private async Task<string> GenerateMisskeyAuthUrlAsync(
FediverseApplication app, FediverseApplication app,
bool forceRefresh, bool forceRefresh
string? state = null
) )
{ {
if (forceRefresh) if (forceRefresh)

View file

@ -131,8 +131,7 @@ public partial class FediverseAuthService
), ),
FediverseInstanceType.MisskeyApi => await GenerateMisskeyAuthUrlAsync( FediverseInstanceType.MisskeyApi => await GenerateMisskeyAuthUrlAsync(
app, app,
forceRefresh, forceRefresh
state
), ),
_ => throw new ArgumentOutOfRangeException(nameof(app), app.InstanceType, null), _ => throw new ArgumentOutOfRangeException(nameof(app), app.InstanceType, null),
}; };

View file

@ -1,3 +1,17 @@
// Copyright (C) 2023-present sam/u1f320 (vulpine.solutions)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Threading.RateLimiting; using System.Threading.RateLimiting;
using NodaTime; using NodaTime;

View file

@ -17,7 +17,6 @@ using Foxnouns.Backend.Database.Models;
using Foxnouns.Backend.Dto; using Foxnouns.Backend.Dto;
using Foxnouns.Backend.Utils; using Foxnouns.Backend.Utils;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json;
namespace Foxnouns.Backend.Services; namespace Foxnouns.Backend.Services;

View file

@ -38,7 +38,7 @@ public class MetricsCollectionService(ILogger logger, IServiceProvider services,
// ReSharper disable once SuggestVarOrType_SimpleTypes // ReSharper disable once SuggestVarOrType_SimpleTypes
await using var db = scope.ServiceProvider.GetRequiredService<DatabaseContext>(); await using var db = scope.ServiceProvider.GetRequiredService<DatabaseContext>();
List<Instant>? users = await db List<Instant> users = await db
.Users.Where(u => !u.Deleted) .Users.Where(u => !u.Deleted)
.Select(u => u.LastActive) .Select(u => u.LastActive)
.ToListAsync(ct); .ToListAsync(ct);

View file

@ -13,7 +13,6 @@
// You should have received a copy of the GNU Affero General Public License // You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
using Minio; using Minio;
using Minio.DataModel;
using Minio.DataModel.Args; using Minio.DataModel.Args;
using Minio.Exceptions; using Minio.Exceptions;

View file

@ -17,8 +17,6 @@ using Foxnouns.Backend.Database.Models;
using Foxnouns.Backend.Dto; using Foxnouns.Backend.Dto;
using Foxnouns.Backend.Utils; using Foxnouns.Backend.Utils;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json;
using NodaTime;
namespace Foxnouns.Backend.Services; namespace Foxnouns.Backend.Services;

View file

@ -1,3 +1,17 @@
// Copyright (C) 2023-present sam/u1f320 (vulpine.solutions)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
using Foxnouns.Backend.Database; using Foxnouns.Backend.Database;
using Microsoft.AspNetCore.OpenApi; using Microsoft.AspNetCore.OpenApi;
using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Any;

View file

@ -12,7 +12,6 @@
// //
// You should have received a copy of the GNU Affero General Public License // You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
using Foxnouns.Backend.Controllers;
using Foxnouns.Backend.Dto; using Foxnouns.Backend.Dto;
namespace Foxnouns.Backend.Utils; namespace Foxnouns.Backend.Utils;