mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-07-29 16:38:37 +00:00
Refactor Database class (#616)
Refactor Database into DatabaseContext Moved into separate folder so it actually has a namespace instead sitting in the root
This commit is contained in:
parent
2aff26f83d
commit
64b95e807d
246 changed files with 1211 additions and 965 deletions
|
@ -1,6 +1,7 @@
|
|||
#nullable enable
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using LBPUnion.ProjectLighthouse.Configuration;
|
||||
using LBPUnion.ProjectLighthouse.Database;
|
||||
using LBPUnion.ProjectLighthouse.Extensions;
|
||||
using LBPUnion.ProjectLighthouse.Servers.GameServer.Types;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Profile;
|
||||
|
@ -17,9 +18,9 @@ namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Controllers;
|
|||
[Produces("text/plain")]
|
||||
public class ClientConfigurationController : ControllerBase
|
||||
{
|
||||
private readonly Database database;
|
||||
private readonly DatabaseContext database;
|
||||
|
||||
public ClientConfigurationController(Database database)
|
||||
public ClientConfigurationController(DatabaseContext database)
|
||||
{
|
||||
this.database = database;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#nullable enable
|
||||
using LBPUnion.ProjectLighthouse.Database;
|
||||
using LBPUnion.ProjectLighthouse.Extensions;
|
||||
using LBPUnion.ProjectLighthouse.Helpers;
|
||||
using LBPUnion.ProjectLighthouse.Serialization;
|
||||
|
@ -18,8 +19,8 @@ namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Controllers;
|
|||
[Produces("text/xml")]
|
||||
public class CommentController : ControllerBase
|
||||
{
|
||||
private readonly Database database;
|
||||
public CommentController(Database database)
|
||||
private readonly DatabaseContext database;
|
||||
public CommentController(DatabaseContext database)
|
||||
{
|
||||
this.database = database;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#nullable enable
|
||||
using LBPUnion.ProjectLighthouse.Database;
|
||||
using LBPUnion.ProjectLighthouse.Extensions;
|
||||
using LBPUnion.ProjectLighthouse.Helpers;
|
||||
using LBPUnion.ProjectLighthouse.Serialization;
|
||||
|
@ -18,9 +19,9 @@ namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Controllers;
|
|||
[Route("LITTLEBIGPLANETPS3_XML/")]
|
||||
public class FriendsController : ControllerBase
|
||||
{
|
||||
private readonly Database database;
|
||||
private readonly DatabaseContext database;
|
||||
|
||||
public FriendsController(Database database)
|
||||
public FriendsController(DatabaseContext database)
|
||||
{
|
||||
this.database = database;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#nullable enable
|
||||
using System.Net;
|
||||
using LBPUnion.ProjectLighthouse.Configuration;
|
||||
using LBPUnion.ProjectLighthouse.Database;
|
||||
using LBPUnion.ProjectLighthouse.Extensions;
|
||||
using LBPUnion.ProjectLighthouse.Helpers;
|
||||
using LBPUnion.ProjectLighthouse.Logging;
|
||||
|
@ -19,9 +20,9 @@ namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Controllers;
|
|||
[Produces("text/xml")]
|
||||
public class LoginController : ControllerBase
|
||||
{
|
||||
private readonly Database database;
|
||||
private readonly DatabaseContext database;
|
||||
|
||||
public LoginController(Database database)
|
||||
public LoginController(DatabaseContext database)
|
||||
{
|
||||
this.database = database;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using LBPUnion.ProjectLighthouse.Extensions;
|
||||
using LBPUnion.ProjectLighthouse.Database;
|
||||
using LBPUnion.ProjectLighthouse.Extensions;
|
||||
using LBPUnion.ProjectLighthouse.Helpers;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Profile;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Token;
|
||||
|
@ -14,9 +15,9 @@ namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Controllers;
|
|||
public class LogoutController : ControllerBase
|
||||
{
|
||||
|
||||
private readonly Database database;
|
||||
private readonly DatabaseContext database;
|
||||
|
||||
public LogoutController(Database database)
|
||||
public LogoutController(DatabaseContext database)
|
||||
{
|
||||
this.database = database;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#nullable enable
|
||||
using LBPUnion.ProjectLighthouse.Database;
|
||||
using LBPUnion.ProjectLighthouse.Extensions;
|
||||
using LBPUnion.ProjectLighthouse.Helpers;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Interaction;
|
||||
|
@ -17,9 +18,9 @@ namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Controllers.Matching;
|
|||
[Produces("text/xml")]
|
||||
public class EnterLevelController : ControllerBase
|
||||
{
|
||||
private readonly Database database;
|
||||
private readonly DatabaseContext database;
|
||||
|
||||
public EnterLevelController(Database database)
|
||||
public EnterLevelController(DatabaseContext database)
|
||||
{
|
||||
this.database = database;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#nullable enable
|
||||
using System.Text.Json;
|
||||
using LBPUnion.ProjectLighthouse.Database;
|
||||
using LBPUnion.ProjectLighthouse.Extensions;
|
||||
using LBPUnion.ProjectLighthouse.Helpers;
|
||||
using LBPUnion.ProjectLighthouse.Logging;
|
||||
|
@ -21,9 +22,9 @@ namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Controllers.Matching;
|
|||
[Produces("text/xml")]
|
||||
public class MatchController : ControllerBase
|
||||
{
|
||||
private readonly Database database;
|
||||
private readonly DatabaseContext database;
|
||||
|
||||
public MatchController(Database database)
|
||||
public MatchController(DatabaseContext database)
|
||||
{
|
||||
this.database = database;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#nullable enable
|
||||
using LBPUnion.ProjectLighthouse.Configuration;
|
||||
using LBPUnion.ProjectLighthouse.Database;
|
||||
using LBPUnion.ProjectLighthouse.Extensions;
|
||||
using LBPUnion.ProjectLighthouse.Helpers;
|
||||
using LBPUnion.ProjectLighthouse.Logging;
|
||||
|
@ -18,7 +19,7 @@ namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Controllers;
|
|||
[Produces("text/plain")]
|
||||
public class MessageController : ControllerBase
|
||||
{
|
||||
private readonly Database database;
|
||||
private readonly DatabaseContext database;
|
||||
|
||||
private const string license = @"
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
|
@ -34,7 +35,7 @@ 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/>.";
|
||||
|
||||
public MessageController(Database database)
|
||||
public MessageController(DatabaseContext database)
|
||||
{
|
||||
this.database = database;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#nullable enable
|
||||
using System.Text.Json;
|
||||
using LBPUnion.ProjectLighthouse.Configuration;
|
||||
using LBPUnion.ProjectLighthouse.Database;
|
||||
using LBPUnion.ProjectLighthouse.Extensions;
|
||||
using LBPUnion.ProjectLighthouse.Helpers;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Moderation;
|
||||
|
@ -17,9 +18,9 @@ namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Controllers;
|
|||
[Produces("text/xml")]
|
||||
public class ReportController : ControllerBase
|
||||
{
|
||||
private readonly Database database;
|
||||
private readonly DatabaseContext database;
|
||||
|
||||
public ReportController(Database database)
|
||||
public ReportController(DatabaseContext database)
|
||||
{
|
||||
this.database = database;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#nullable enable
|
||||
using Discord;
|
||||
using LBPUnion.ProjectLighthouse.Configuration;
|
||||
using LBPUnion.ProjectLighthouse.Database;
|
||||
using LBPUnion.ProjectLighthouse.Extensions;
|
||||
using LBPUnion.ProjectLighthouse.Files;
|
||||
using LBPUnion.ProjectLighthouse.Helpers;
|
||||
|
@ -23,9 +24,9 @@ namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Controllers.Resources;
|
|||
[Produces("text/xml")]
|
||||
public class PhotosController : ControllerBase
|
||||
{
|
||||
private readonly Database database;
|
||||
private readonly DatabaseContext database;
|
||||
|
||||
public PhotosController(Database database)
|
||||
public PhotosController(DatabaseContext database)
|
||||
{
|
||||
this.database = database;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#nullable enable
|
||||
using LBPUnion.ProjectLighthouse.Configuration;
|
||||
using LBPUnion.ProjectLighthouse.Database;
|
||||
using LBPUnion.ProjectLighthouse.Extensions;
|
||||
using LBPUnion.ProjectLighthouse.Logging;
|
||||
using LBPUnion.ProjectLighthouse.Serialization;
|
||||
|
@ -21,9 +22,9 @@ namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Controllers.Slots;
|
|||
[Produces("text/xml")]
|
||||
public class CollectionController : ControllerBase
|
||||
{
|
||||
private readonly Database database;
|
||||
private readonly DatabaseContext database;
|
||||
|
||||
public CollectionController(Database database)
|
||||
public CollectionController(DatabaseContext database)
|
||||
{
|
||||
this.database = database;
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
using LBPUnion.ProjectLighthouse.Database;
|
||||
using LBPUnion.ProjectLighthouse.Extensions;
|
||||
using LBPUnion.ProjectLighthouse.Helpers;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Interaction;
|
||||
|
@ -17,9 +18,9 @@ namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Controllers.Slots;
|
|||
[Produces("text/plain")]
|
||||
public class LevelTagsController : ControllerBase
|
||||
{
|
||||
private readonly Database database;
|
||||
private readonly DatabaseContext database;
|
||||
|
||||
public LevelTagsController(Database database)
|
||||
public LevelTagsController(DatabaseContext database)
|
||||
{
|
||||
this.database = database;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#nullable enable
|
||||
using LBPUnion.ProjectLighthouse.Database;
|
||||
using LBPUnion.ProjectLighthouse.Extensions;
|
||||
using LBPUnion.ProjectLighthouse.Helpers;
|
||||
using LBPUnion.ProjectLighthouse.Serialization;
|
||||
|
@ -20,8 +21,8 @@ namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Controllers.Slots;
|
|||
[Produces("text/xml")]
|
||||
public class ListController : ControllerBase
|
||||
{
|
||||
private readonly Database database;
|
||||
public ListController(Database database)
|
||||
private readonly DatabaseContext database;
|
||||
public ListController(DatabaseContext database)
|
||||
{
|
||||
this.database = database;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#nullable enable
|
||||
using LBPUnion.ProjectLighthouse.Configuration;
|
||||
using LBPUnion.ProjectLighthouse.Database;
|
||||
using LBPUnion.ProjectLighthouse.Extensions;
|
||||
using LBPUnion.ProjectLighthouse.Files;
|
||||
using LBPUnion.ProjectLighthouse.Helpers;
|
||||
|
@ -24,9 +25,9 @@ namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Controllers.Slots;
|
|||
[Produces("text/xml")]
|
||||
public class PublishController : ControllerBase
|
||||
{
|
||||
private readonly Database database;
|
||||
private readonly DatabaseContext database;
|
||||
|
||||
public PublishController(Database database)
|
||||
public PublishController(DatabaseContext database)
|
||||
{
|
||||
this.database = database;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#nullable enable
|
||||
using LBPUnion.ProjectLighthouse.Database;
|
||||
using LBPUnion.ProjectLighthouse.Extensions;
|
||||
using LBPUnion.ProjectLighthouse.Helpers;
|
||||
using LBPUnion.ProjectLighthouse.Serialization;
|
||||
|
@ -18,9 +19,9 @@ namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Controllers.Slots;
|
|||
[Produces("text/xml")]
|
||||
public class ReviewController : ControllerBase
|
||||
{
|
||||
private readonly Database database;
|
||||
private readonly DatabaseContext database;
|
||||
|
||||
public ReviewController(Database database)
|
||||
public ReviewController(DatabaseContext database)
|
||||
{
|
||||
this.database = database;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#nullable enable
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using LBPUnion.ProjectLighthouse.Database;
|
||||
using LBPUnion.ProjectLighthouse.Extensions;
|
||||
using LBPUnion.ProjectLighthouse.Helpers;
|
||||
using LBPUnion.ProjectLighthouse.Logging;
|
||||
|
@ -22,9 +23,9 @@ namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Controllers.Slots;
|
|||
[Produces("text/xml")]
|
||||
public class ScoreController : ControllerBase
|
||||
{
|
||||
private readonly Database database;
|
||||
private readonly DatabaseContext database;
|
||||
|
||||
public ScoreController(Database database)
|
||||
public ScoreController(DatabaseContext database)
|
||||
{
|
||||
this.database = database;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#nullable enable
|
||||
using LBPUnion.ProjectLighthouse.Database;
|
||||
using LBPUnion.ProjectLighthouse.Extensions;
|
||||
using LBPUnion.ProjectLighthouse.Serialization;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Level;
|
||||
|
@ -16,8 +17,8 @@ namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Controllers.Slots;
|
|||
[Produces("text/xml")]
|
||||
public class SearchController : ControllerBase
|
||||
{
|
||||
private readonly Database database;
|
||||
public SearchController(Database database)
|
||||
private readonly DatabaseContext database;
|
||||
public SearchController(DatabaseContext database)
|
||||
{
|
||||
this.database = database;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#nullable enable
|
||||
using LBPUnion.ProjectLighthouse.Configuration;
|
||||
using LBPUnion.ProjectLighthouse.Database;
|
||||
using LBPUnion.ProjectLighthouse.Extensions;
|
||||
using LBPUnion.ProjectLighthouse.Helpers;
|
||||
using LBPUnion.ProjectLighthouse.Serialization;
|
||||
|
@ -21,8 +22,8 @@ namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Controllers.Slots;
|
|||
[Produces("text/xml")]
|
||||
public class SlotsController : ControllerBase
|
||||
{
|
||||
private readonly Database database;
|
||||
public SlotsController(Database database)
|
||||
private readonly DatabaseContext database;
|
||||
public SlotsController(DatabaseContext database)
|
||||
{
|
||||
this.database = database;
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
using LBPUnion.ProjectLighthouse.Database;
|
||||
using LBPUnion.ProjectLighthouse.Helpers;
|
||||
using LBPUnion.ProjectLighthouse.Serialization;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
|
@ -13,9 +14,9 @@ namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Controllers;
|
|||
public class StatisticsController : ControllerBase
|
||||
{
|
||||
|
||||
private readonly Database database;
|
||||
private readonly DatabaseContext database;
|
||||
|
||||
public StatisticsController(Database database)
|
||||
public StatisticsController(DatabaseContext database)
|
||||
{
|
||||
this.database = database;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#nullable enable
|
||||
using System.Text.Json;
|
||||
using LBPUnion.ProjectLighthouse.Database;
|
||||
using LBPUnion.ProjectLighthouse.Extensions;
|
||||
using LBPUnion.ProjectLighthouse.Files;
|
||||
using LBPUnion.ProjectLighthouse.Helpers;
|
||||
|
@ -23,9 +24,9 @@ namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Controllers;
|
|||
[Produces("text/xml")]
|
||||
public class UserController : ControllerBase
|
||||
{
|
||||
private readonly Database database;
|
||||
private readonly DatabaseContext database;
|
||||
|
||||
public UserController(Database database)
|
||||
public UserController(DatabaseContext database)
|
||||
{
|
||||
this.database = database;
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
using LBPUnion.ProjectLighthouse.Database;
|
||||
using LBPUnion.ProjectLighthouse.Helpers;
|
||||
using LBPUnion.ProjectLighthouse.Middlewares;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Token;
|
||||
|
@ -10,7 +11,7 @@ public class SetLastContactMiddleware : MiddlewareDBContext
|
|||
public SetLastContactMiddleware(RequestDelegate next) : base(next)
|
||||
{ }
|
||||
|
||||
public override async Task InvokeAsync(HttpContext context, Database database)
|
||||
public override async Task InvokeAsync(HttpContext context, DatabaseContext database)
|
||||
{
|
||||
#nullable enable
|
||||
// Log LastContact for LBP1. This is done on LBP2/3/V on a Match request.
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using LBPUnion.ProjectLighthouse.Configuration;
|
||||
using LBPUnion.ProjectLighthouse.Database;
|
||||
using LBPUnion.ProjectLighthouse.Logging;
|
||||
using LBPUnion.ProjectLighthouse.Middlewares;
|
||||
using LBPUnion.ProjectLighthouse.Serialization;
|
||||
|
@ -45,7 +46,7 @@ public class GameServerStartup
|
|||
}
|
||||
);
|
||||
|
||||
services.AddDbContext<Database>();
|
||||
services.AddDbContext<DatabaseContext>();
|
||||
|
||||
services.Configure<ForwardedHeadersOptions>
|
||||
(
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using System.Security.Claims;
|
||||
using System.Text.Encodings.Web;
|
||||
using LBPUnion.ProjectLighthouse.Database;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Token;
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
|
@ -9,7 +10,7 @@ namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Startup;
|
|||
|
||||
public class TokenAuthHandler : AuthenticationHandler<AuthenticationSchemeOptions>
|
||||
{
|
||||
private readonly Database database;
|
||||
private readonly DatabaseContext database;
|
||||
private const string cookie = "MM_AUTH";
|
||||
|
||||
public TokenAuthHandler
|
||||
|
@ -17,7 +18,7 @@ public class TokenAuthHandler : AuthenticationHandler<AuthenticationSchemeOption
|
|||
IOptionsMonitor<AuthenticationSchemeOptions> options,
|
||||
UrlEncoder encoder,
|
||||
ISystemClock clock,
|
||||
Database database
|
||||
DatabaseContext database
|
||||
// I said I don't want any damn vegetables (logs)
|
||||
) : base(options, new NullLoggerFactory(), encoder, clock)
|
||||
{
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
using LBPUnion.ProjectLighthouse.Database;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Level;
|
||||
using LBPUnion.ProjectLighthouse.Types.Levels;
|
||||
|
||||
|
@ -18,7 +19,7 @@ public static class CategoryHelper
|
|||
Categories.Add(new HeartedCategory());
|
||||
Categories.Add(new LuckyDipCategory());
|
||||
|
||||
using Database database = new();
|
||||
using DatabaseContext database = new();
|
||||
foreach (DatabaseCategory category in database.CustomCategories) Categories.Add(new CustomCategory(category));
|
||||
}
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
#nullable enable
|
||||
using System.Diagnostics;
|
||||
using LBPUnion.ProjectLighthouse.Database;
|
||||
using LBPUnion.ProjectLighthouse.Logging;
|
||||
using LBPUnion.ProjectLighthouse.Serialization;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Level;
|
||||
|
@ -11,8 +12,8 @@ namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Types.Categories;
|
|||
|
||||
public abstract class CategoryWithUser : Category
|
||||
{
|
||||
public abstract Slot? GetPreviewSlot(Database database, User user);
|
||||
public override Slot? GetPreviewSlot(Database database)
|
||||
public abstract Slot? GetPreviewSlot(DatabaseContext database, User user);
|
||||
public override Slot? GetPreviewSlot(DatabaseContext database)
|
||||
{
|
||||
#if DEBUG
|
||||
Logger.Error("tried to get preview slot without user on CategoryWithUser", LogArea.Category);
|
||||
|
@ -21,8 +22,8 @@ public abstract class CategoryWithUser : Category
|
|||
return null;
|
||||
}
|
||||
|
||||
public abstract int GetTotalSlots(Database database, User user);
|
||||
public override int GetTotalSlots(Database database)
|
||||
public abstract int GetTotalSlots(DatabaseContext database, User user);
|
||||
public override int GetTotalSlots(DatabaseContext database)
|
||||
{
|
||||
#if DEBUG
|
||||
Logger.Error("tried to get total slots without user on CategoryWithUser", LogArea.Category);
|
||||
|
@ -31,8 +32,8 @@ public abstract class CategoryWithUser : Category
|
|||
return -1;
|
||||
}
|
||||
|
||||
public abstract IEnumerable<Slot> GetSlots(Database database, User user, int pageStart, int pageSize);
|
||||
public override IEnumerable<Slot> GetSlots(Database database, int pageStart, int pageSize)
|
||||
public abstract IEnumerable<Slot> GetSlots(DatabaseContext database, User user, int pageStart, int pageSize);
|
||||
public override IEnumerable<Slot> GetSlots(DatabaseContext database, int pageStart, int pageSize)
|
||||
{
|
||||
#if DEBUG
|
||||
Logger.Error("tried to get slots without user on CategoryWithUser", LogArea.Category);
|
||||
|
@ -41,13 +42,13 @@ public abstract class CategoryWithUser : Category
|
|||
return new List<Slot>();
|
||||
}
|
||||
|
||||
public new string Serialize(Database database)
|
||||
public new string Serialize(DatabaseContext database)
|
||||
{
|
||||
Logger.Error("tried to serialize without user on CategoryWithUser", LogArea.Category);
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
public string Serialize(Database database, User user)
|
||||
public string Serialize(DatabaseContext database, User user)
|
||||
{
|
||||
Slot? previewSlot = this.GetPreviewSlot(database, user);
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#nullable enable
|
||||
using LBPUnion.ProjectLighthouse.Database;
|
||||
using LBPUnion.ProjectLighthouse.Extensions;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Level;
|
||||
using LBPUnion.ProjectLighthouse.Types.Levels;
|
||||
|
@ -34,9 +35,9 @@ public class CustomCategory : Category
|
|||
public sealed override string Description { get; set; }
|
||||
public sealed override string IconHash { get; set; }
|
||||
public sealed override string Endpoint { get; set; }
|
||||
public override Slot? GetPreviewSlot(Database database) => database.Slots.FirstOrDefault(s => s.SlotId == this.SlotIds[0]);
|
||||
public override Slot? GetPreviewSlot(DatabaseContext database) => database.Slots.FirstOrDefault(s => s.SlotId == this.SlotIds[0]);
|
||||
public override IEnumerable<Slot> GetSlots
|
||||
(Database database, int pageStart, int pageSize)
|
||||
(DatabaseContext database, int pageStart, int pageSize)
|
||||
=> database.Slots.ByGameVersion(GameVersion.LittleBigPlanet3).Where(s => this.SlotIds.Contains(s.SlotId));
|
||||
public override int GetTotalSlots(Database database) => this.SlotIds.Count;
|
||||
public override int GetTotalSlots(DatabaseContext database) => this.SlotIds.Count;
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
#nullable enable
|
||||
using LBPUnion.ProjectLighthouse.Database;
|
||||
using LBPUnion.ProjectLighthouse.Extensions;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Level;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Profile;
|
||||
|
@ -14,7 +15,7 @@ public class HeartedCategory : CategoryWithUser
|
|||
public override string Description { get; set; } = "Content you've hearted";
|
||||
public override string IconHash { get; set; } = "g820611";
|
||||
public override string Endpoint { get; set; } = "hearted";
|
||||
public override Slot? GetPreviewSlot(Database database, User user) // note: developer slots act up in LBP3 when listed here, so I omitted it
|
||||
public override Slot? GetPreviewSlot(DatabaseContext database, User user) // note: developer slots act up in LBP3 when listed here, so I omitted it
|
||||
=> database.HeartedLevels.Where(h => h.UserId == user.UserId)
|
||||
.Where(h => h.Slot.Type == SlotType.User && !h.Slot.Hidden && h.Slot.GameVersion <= GameVersion.LittleBigPlanet3)
|
||||
.OrderByDescending(h => h.HeartedLevelId)
|
||||
|
@ -24,7 +25,7 @@ public class HeartedCategory : CategoryWithUser
|
|||
.ByGameVersion(GameVersion.LittleBigPlanet3, false, false, true)
|
||||
.FirstOrDefault();
|
||||
|
||||
public override IEnumerable<Slot> GetSlots(Database database, User user, int pageStart, int pageSize)
|
||||
public override IEnumerable<Slot> GetSlots(DatabaseContext database, User user, int pageStart, int pageSize)
|
||||
=> database.HeartedLevels.Where(h => h.UserId == user.UserId)
|
||||
.Where(h => h.Slot.Type == SlotType.User && !h.Slot.Hidden && h.Slot.GameVersion <= GameVersion.LittleBigPlanet3)
|
||||
.OrderByDescending(h => h.HeartedLevelId)
|
||||
|
@ -35,5 +36,5 @@ public class HeartedCategory : CategoryWithUser
|
|||
.Skip(Math.Max(0, pageStart))
|
||||
.Take(Math.Min(pageSize, 20));
|
||||
|
||||
public override int GetTotalSlots(Database database, User user) => database.HeartedLevels.Count(h => h.UserId == user.UserId);
|
||||
public override int GetTotalSlots(DatabaseContext database, User user) => database.HeartedLevels.Count(h => h.UserId == user.UserId);
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
#nullable enable
|
||||
using System.Security.Cryptography;
|
||||
using LBPUnion.ProjectLighthouse.Database;
|
||||
using LBPUnion.ProjectLighthouse.Extensions;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Level;
|
||||
using LBPUnion.ProjectLighthouse.Types.Levels;
|
||||
|
@ -13,14 +14,14 @@ public class HighestRatedCategory : Category
|
|||
public override string Description { get; set; } = "Community Highest Rated content";
|
||||
public override string IconHash { get; set; } = "g820603";
|
||||
public override string Endpoint { get; set; } = "thumbs";
|
||||
public override Slot? GetPreviewSlot(Database database) => database.Slots.Where(s => s.Type == SlotType.User).AsEnumerable().MaxBy(s => s.Thumbsup);
|
||||
public override Slot? GetPreviewSlot(DatabaseContext database) => database.Slots.Where(s => s.Type == SlotType.User).AsEnumerable().MaxBy(s => s.Thumbsup);
|
||||
public override IEnumerable<Slot> GetSlots
|
||||
(Database database, int pageStart, int pageSize)
|
||||
(DatabaseContext database, int pageStart, int pageSize)
|
||||
=> database.Slots.ByGameVersion(GameVersion.LittleBigPlanet3, false, true)
|
||||
.AsEnumerable()
|
||||
.OrderByDescending(s => s.Thumbsup)
|
||||
.ThenBy(_ => RandomNumberGenerator.GetInt32(int.MaxValue))
|
||||
.Skip(Math.Max(0, pageStart - 1))
|
||||
.Take(Math.Min(pageSize, 20));
|
||||
public override int GetTotalSlots(Database database) => database.Slots.Count(s => s.Type == SlotType.User);
|
||||
public override int GetTotalSlots(DatabaseContext database) => database.Slots.Count(s => s.Type == SlotType.User);
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
#nullable enable
|
||||
using LBPUnion.ProjectLighthouse.Database;
|
||||
using LBPUnion.ProjectLighthouse.Extensions;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Level;
|
||||
using LBPUnion.ProjectLighthouse.Types.Levels;
|
||||
|
@ -13,12 +14,12 @@ public class LuckyDipCategory : Category
|
|||
public override string Description { get; set; } = "Randomized uploaded content";
|
||||
public override string IconHash { get; set; } = "g820605";
|
||||
public override string Endpoint { get; set; } = "lbp2luckydip";
|
||||
public override Slot? GetPreviewSlot(Database database) => database.Slots.Where(s => s.Type == SlotType.User).OrderByDescending(_ => EF.Functions.Random()).FirstOrDefault();
|
||||
public override Slot? GetPreviewSlot(DatabaseContext database) => database.Slots.Where(s => s.Type == SlotType.User).OrderByDescending(_ => EF.Functions.Random()).FirstOrDefault();
|
||||
public override IEnumerable<Slot> GetSlots
|
||||
(Database database, int pageStart, int pageSize)
|
||||
(DatabaseContext database, int pageStart, int pageSize)
|
||||
=> database.Slots.ByGameVersion(GameVersion.LittleBigPlanet3, false, true)
|
||||
.OrderByDescending(_ => EF.Functions.Random())
|
||||
.Skip(Math.Max(0, pageStart - 1))
|
||||
.Take(Math.Min(pageSize, 20));
|
||||
public override int GetTotalSlots(Database database) => database.Slots.Count(s => s.Type == SlotType.User);
|
||||
public override int GetTotalSlots(DatabaseContext database) => database.Slots.Count(s => s.Type == SlotType.User);
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
#nullable enable
|
||||
using System.Security.Cryptography;
|
||||
using LBPUnion.ProjectLighthouse.Database;
|
||||
using LBPUnion.ProjectLighthouse.Extensions;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Level;
|
||||
using LBPUnion.ProjectLighthouse.Types.Levels;
|
||||
|
@ -13,14 +14,14 @@ public class MostHeartedCategory : Category
|
|||
public override string Description { get; set; } = "The Most Hearted Content";
|
||||
public override string IconHash { get; set; } = "g820607";
|
||||
public override string Endpoint { get; set; } = "mostHearted";
|
||||
public override Slot? GetPreviewSlot(Database database) => database.Slots.Where(s => s.Type == SlotType.User).AsEnumerable().MaxBy(s => s.Hearts);
|
||||
public override Slot? GetPreviewSlot(DatabaseContext database) => database.Slots.Where(s => s.Type == SlotType.User).AsEnumerable().MaxBy(s => s.Hearts);
|
||||
public override IEnumerable<Slot> GetSlots
|
||||
(Database database, int pageStart, int pageSize)
|
||||
(DatabaseContext database, int pageStart, int pageSize)
|
||||
=> database.Slots.ByGameVersion(GameVersion.LittleBigPlanet3, false, true)
|
||||
.AsEnumerable()
|
||||
.OrderByDescending(s => s.Hearts)
|
||||
.ThenBy(_ => RandomNumberGenerator.GetInt32(int.MaxValue))
|
||||
.Skip(Math.Max(0, pageStart - 1))
|
||||
.Take(Math.Min(pageSize, 20));
|
||||
public override int GetTotalSlots(Database database) => database.Slots.Count(s => s.Type == SlotType.User);
|
||||
public override int GetTotalSlots(DatabaseContext database) => database.Slots.Count(s => s.Type == SlotType.User);
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
#nullable enable
|
||||
using LBPUnion.ProjectLighthouse.Database;
|
||||
using LBPUnion.ProjectLighthouse.Extensions;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Level;
|
||||
using LBPUnion.ProjectLighthouse.Types.Levels;
|
||||
|
@ -12,17 +13,17 @@ public class MostPlayedCategory : Category
|
|||
public override string Description { get; set; } = "The most played content";
|
||||
public override string IconHash { get; set; } = "g820608";
|
||||
public override string Endpoint { get; set; } = "mostUniquePlays";
|
||||
public override Slot? GetPreviewSlot(Database database) => database.Slots
|
||||
public override Slot? GetPreviewSlot(DatabaseContext database) => database.Slots
|
||||
.Where(s => s.Type == SlotType.User)
|
||||
.OrderByDescending(s => s.PlaysLBP1Unique + s.PlaysLBP2Unique + s.PlaysLBP3Unique)
|
||||
.ThenByDescending(s => s.PlaysLBP1 + s.PlaysLBP2 + s.PlaysLBP3)
|
||||
.FirstOrDefault();
|
||||
public override IEnumerable<Slot> GetSlots
|
||||
(Database database, int pageStart, int pageSize)
|
||||
(DatabaseContext database, int pageStart, int pageSize)
|
||||
=> database.Slots.ByGameVersion(GameVersion.LittleBigPlanet3, false, true)
|
||||
.OrderByDescending(s => s.PlaysLBP1Unique + s.PlaysLBP2Unique + s.PlaysLBP3Unique)
|
||||
.ThenByDescending(s => s.PlaysLBP1 + s.PlaysLBP2 + s.PlaysLBP3)
|
||||
.Skip(Math.Max(0, pageStart - 1))
|
||||
.Take(Math.Min(pageSize, 20));
|
||||
public override int GetTotalSlots(Database database) => database.Slots.Count(s => s.Type == SlotType.User);
|
||||
public override int GetTotalSlots(DatabaseContext database) => database.Slots.Count(s => s.Type == SlotType.User);
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
#nullable enable
|
||||
using LBPUnion.ProjectLighthouse.Database;
|
||||
using LBPUnion.ProjectLighthouse.Extensions;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Level;
|
||||
using LBPUnion.ProjectLighthouse.Types.Levels;
|
||||
|
@ -12,12 +13,12 @@ public class NewestLevelsCategory : Category
|
|||
public override string Description { get; set; } = "The most recently published content";
|
||||
public override string IconHash { get; set; } = "g820623";
|
||||
public override string Endpoint { get; set; } = "newest";
|
||||
public override Slot? GetPreviewSlot(Database database) => database.Slots.Where(s => s.Type == SlotType.User).OrderByDescending(s => s.FirstUploaded).FirstOrDefault();
|
||||
public override Slot? GetPreviewSlot(DatabaseContext database) => database.Slots.Where(s => s.Type == SlotType.User).OrderByDescending(s => s.FirstUploaded).FirstOrDefault();
|
||||
public override IEnumerable<Slot> GetSlots
|
||||
(Database database, int pageStart, int pageSize)
|
||||
(DatabaseContext database, int pageStart, int pageSize)
|
||||
=> database.Slots.ByGameVersion(GameVersion.LittleBigPlanet3, false, true)
|
||||
.OrderByDescending(s => s.FirstUploaded)
|
||||
.Skip(Math.Max(0, pageStart - 1))
|
||||
.Take(Math.Min(pageSize, 20));
|
||||
public override int GetTotalSlots(Database database) => database.Slots.Count(s => s.Type == SlotType.User);
|
||||
public override int GetTotalSlots(DatabaseContext database) => database.Slots.Count(s => s.Type == SlotType.User);
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
#nullable enable
|
||||
using LBPUnion.ProjectLighthouse.Database;
|
||||
using LBPUnion.ProjectLighthouse.Extensions;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Level;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Profile;
|
||||
|
@ -14,7 +15,7 @@ public class QueueCategory : CategoryWithUser
|
|||
public override string Description { get; set; } = "Your queued content";
|
||||
public override string IconHash { get; set; } = "g820614";
|
||||
public override string Endpoint { get; set; } = "queue";
|
||||
public override Slot? GetPreviewSlot(Database database, User user)
|
||||
public override Slot? GetPreviewSlot(DatabaseContext database, User user)
|
||||
=> database.QueuedLevels.Where(q => q.UserId == user.UserId)
|
||||
.Where(q => q.Slot.Type == SlotType.User && !q.Slot.Hidden && q.Slot.GameVersion <= GameVersion.LittleBigPlanet3)
|
||||
.OrderByDescending(q => q.QueuedLevelId)
|
||||
|
@ -24,7 +25,7 @@ public class QueueCategory : CategoryWithUser
|
|||
.ByGameVersion(GameVersion.LittleBigPlanet3, false, false, true)
|
||||
.FirstOrDefault();
|
||||
|
||||
public override IEnumerable<Slot> GetSlots(Database database, User user, int pageStart, int pageSize)
|
||||
public override IEnumerable<Slot> GetSlots(DatabaseContext database, User user, int pageStart, int pageSize)
|
||||
=> database.QueuedLevels.Where(q => q.UserId == user.UserId)
|
||||
.Where(q => q.Slot.Type == SlotType.User && !q.Slot.Hidden && q.Slot.GameVersion <= GameVersion.LittleBigPlanet3)
|
||||
.OrderByDescending(q => q.QueuedLevelId)
|
||||
|
@ -35,5 +36,5 @@ public class QueueCategory : CategoryWithUser
|
|||
.Skip(Math.Max(0, pageStart - 1))
|
||||
.Take(Math.Min(pageSize, 20));
|
||||
|
||||
public override int GetTotalSlots(Database database, User user) => database.QueuedLevels.Count(q => q.UserId == user.UserId);
|
||||
public override int GetTotalSlots(DatabaseContext database, User user) => database.QueuedLevels.Count(q => q.UserId == user.UserId);
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
#nullable enable
|
||||
using LBPUnion.ProjectLighthouse.Database;
|
||||
using LBPUnion.ProjectLighthouse.Extensions;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Level;
|
||||
using LBPUnion.ProjectLighthouse.Types.Levels;
|
||||
|
@ -12,13 +13,13 @@ public class TeamPicksCategory : Category
|
|||
public override string Description { get; set; } = "Community Team Picks";
|
||||
public override string IconHash { get; set; } = "g820626";
|
||||
public override string Endpoint { get; set; } = "team_picks";
|
||||
public override Slot? GetPreviewSlot(Database database) => database.Slots.OrderByDescending(s => s.FirstUploaded).FirstOrDefault(s => s.TeamPick);
|
||||
public override Slot? GetPreviewSlot(DatabaseContext database) => database.Slots.OrderByDescending(s => s.FirstUploaded).FirstOrDefault(s => s.TeamPick);
|
||||
public override IEnumerable<Slot> GetSlots
|
||||
(Database database, int pageStart, int pageSize)
|
||||
(DatabaseContext database, int pageStart, int pageSize)
|
||||
=> database.Slots.ByGameVersion(GameVersion.LittleBigPlanet3, false, true)
|
||||
.OrderByDescending(s => s.FirstUploaded)
|
||||
.Where(s => s.TeamPick)
|
||||
.Skip(Math.Max(0, pageStart - 1))
|
||||
.Take(Math.Min(pageSize, 20));
|
||||
public override int GetTotalSlots(Database database) => database.Slots.Count(s => s.TeamPick);
|
||||
public override int GetTotalSlots(DatabaseContext database) => database.Slots.Count(s => s.TeamPick);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue