mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-08-12 23:08:40 +00:00
parent
162da189d7
commit
a9380ac8e8
2 changed files with 36 additions and 14 deletions
|
@ -6,6 +6,7 @@ using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Xml.Serialization;
|
using System.Xml.Serialization;
|
||||||
using LBPUnion.ProjectLighthouse.Helpers;
|
using LBPUnion.ProjectLighthouse.Helpers;
|
||||||
|
using LBPUnion.ProjectLighthouse.Helpers.Extensions;
|
||||||
using LBPUnion.ProjectLighthouse.Serialization;
|
using LBPUnion.ProjectLighthouse.Serialization;
|
||||||
using LBPUnion.ProjectLighthouse.Types;
|
using LBPUnion.ProjectLighthouse.Types;
|
||||||
using LBPUnion.ProjectLighthouse.Types.Levels;
|
using LBPUnion.ProjectLighthouse.Types.Levels;
|
||||||
|
@ -144,7 +145,7 @@ public class ReviewController : ControllerBase
|
||||||
Slot? slot = await this.database.Slots.FirstOrDefaultAsync(s => s.SlotId == slotId);
|
Slot? slot = await this.database.Slots.FirstOrDefaultAsync(s => s.SlotId == slotId);
|
||||||
if (slot == null) return this.BadRequest();
|
if (slot == null) return this.BadRequest();
|
||||||
|
|
||||||
IQueryable<Review?> reviews = this.database.Reviews.Where(r => r.SlotId == slotId && r.Slot.GameVersion <= gameVersion)
|
IQueryable<Review?> reviews = this.database.Reviews.ByGameVersion(gameVersion, true)
|
||||||
.Include(r => r.Reviewer)
|
.Include(r => r.Reviewer)
|
||||||
.Include(r => r.Slot)
|
.Include(r => r.Slot)
|
||||||
.OrderByDescending(r => r.ThumbsUp)
|
.OrderByDescending(r => r.ThumbsUp)
|
||||||
|
@ -152,17 +153,17 @@ public class ReviewController : ControllerBase
|
||||||
.Skip(pageStart - 1)
|
.Skip(pageStart - 1)
|
||||||
.Take(pageSize);
|
.Take(pageSize);
|
||||||
|
|
||||||
|
string inner = reviews.ToList()
|
||||||
|
.Aggregate
|
||||||
|
(
|
||||||
|
string.Empty,
|
||||||
|
(current, review) =>
|
||||||
|
{
|
||||||
|
if (review == null) return current;
|
||||||
|
|
||||||
string inner = reviews.ToList().Aggregate
|
return current + review.Serialize();
|
||||||
(
|
}
|
||||||
string.Empty,
|
);
|
||||||
(current, review) =>
|
|
||||||
{
|
|
||||||
if (review == null) return current;
|
|
||||||
|
|
||||||
return current + review.Serialize();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
string response = LbpSerializer.TaggedStringElement
|
string response = LbpSerializer.TaggedStringElement
|
||||||
(
|
(
|
||||||
|
@ -194,12 +195,14 @@ public class ReviewController : ControllerBase
|
||||||
|
|
||||||
GameVersion gameVersion = gameToken.GameVersion;
|
GameVersion gameVersion = gameToken.GameVersion;
|
||||||
|
|
||||||
IEnumerable<Review> reviews = this.database.Reviews.Where(r => r.Reviewer.Username == username && r.Slot.GameVersion <= gameVersion)
|
IEnumerable<Review?> reviews = this.database.Reviews.ByGameVersion(gameVersion, true)
|
||||||
|
.Where(r => r.Reviewer.Username == username)
|
||||||
.Include(r => r.Reviewer)
|
.Include(r => r.Reviewer)
|
||||||
.Include(r => r.Slot)
|
.Include(r => r.Slot)
|
||||||
.OrderByDescending(r => r.Timestamp)
|
.OrderByDescending(r => r.Timestamp)
|
||||||
.Skip(pageStart - 1)
|
.Skip(pageStart - 1)
|
||||||
.Take(pageSize);
|
.Take(pageSize)
|
||||||
|
.AsEnumerable();
|
||||||
|
|
||||||
string inner = reviews.Aggregate
|
string inner = reviews.Aggregate
|
||||||
(
|
(
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using LBPUnion.ProjectLighthouse.Types;
|
using LBPUnion.ProjectLighthouse.Types;
|
||||||
using LBPUnion.ProjectLighthouse.Types.Levels;
|
using LBPUnion.ProjectLighthouse.Types.Levels;
|
||||||
|
using LBPUnion.ProjectLighthouse.Types.Reviews;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
namespace LBPUnion.ProjectLighthouse.Helpers.Extensions;
|
namespace LBPUnion.ProjectLighthouse.Helpers.Extensions;
|
||||||
|
|
||||||
public static class SlotsExtensions
|
public static class DatabaseExtensions
|
||||||
{
|
{
|
||||||
public static IQueryable<Slot> ByGameVersion
|
public static IQueryable<Slot> ByGameVersion
|
||||||
(this DbSet<Slot> set, GameVersion gameVersion, bool includeSublevels = false)
|
(this DbSet<Slot> set, GameVersion gameVersion, bool includeSublevels = false)
|
||||||
|
@ -28,4 +29,22 @@ public static class SlotsExtensions
|
||||||
|
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static IQueryable<Review> ByGameVersion(this IQueryable<Review> queryable, GameVersion gameVersion, bool includeSublevels = false)
|
||||||
|
{
|
||||||
|
IQueryable<Review> query = queryable.Include(r => r.Slot).Include(r => r.Slot.Creator).Include(r => r.Slot.Location);
|
||||||
|
|
||||||
|
if (gameVersion == GameVersion.LittleBigPlanetVita || gameVersion == GameVersion.LittleBigPlanetPSP || gameVersion == GameVersion.Unknown)
|
||||||
|
{
|
||||||
|
query = query.Where(r => r.Slot.GameVersion == gameVersion);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
query = query.Where(r => r.Slot.GameVersion <= gameVersion);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!includeSublevels) query = query.Where(r => !r.Slot.SubLevel);
|
||||||
|
|
||||||
|
return query;
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue