mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-08-05 03:18:45 +00:00
Pass current gameVersion into slot, show vita play count if gameversion is vita
Closes #60
This commit is contained in:
parent
2b63952f94
commit
e1362f8597
6 changed files with 54 additions and 28 deletions
|
@ -74,8 +74,13 @@ public class CollectionController : ControllerBase
|
||||||
[HttpGet("searches/{endpointName}")]
|
[HttpGet("searches/{endpointName}")]
|
||||||
public async Task<IActionResult> GetCategorySlots(string endpointName, [FromQuery] int pageStart, [FromQuery] int pageSize)
|
public async Task<IActionResult> GetCategorySlots(string endpointName, [FromQuery] int pageStart, [FromQuery] int pageSize)
|
||||||
{
|
{
|
||||||
User? user = await this.database.UserFromGameRequest(this.Request);
|
(User, GameToken)? userAndToken = await this.database.UserAndGameTokenFromRequest(this.Request);
|
||||||
if (user == null) return this.StatusCode(403, "");
|
|
||||||
|
if (userAndToken == null) return this.StatusCode(403, "");
|
||||||
|
|
||||||
|
// ReSharper disable once PossibleInvalidOperationException
|
||||||
|
User user = userAndToken.Value.Item1;
|
||||||
|
GameToken gameToken = userAndToken.Value.Item2;
|
||||||
|
|
||||||
Category? category = CollectionHelper.Categories.FirstOrDefault(c => c.Endpoint == endpointName);
|
Category? category = CollectionHelper.Categories.FirstOrDefault(c => c.Endpoint == endpointName);
|
||||||
if (category == null) return this.NotFound();
|
if (category == null) return this.NotFound();
|
||||||
|
@ -96,7 +101,7 @@ public class CollectionController : ControllerBase
|
||||||
totalSlots = category.GetTotalSlots(this.database);
|
totalSlots = category.GetTotalSlots(this.database);
|
||||||
}
|
}
|
||||||
|
|
||||||
string slotsSerialized = slots.Aggregate(string.Empty, (current, slot) => current + slot.Serialize());
|
string slotsSerialized = slots.Aggregate(string.Empty, (current, slot) => current + slot.Serialize(gameToken.GameVersion));
|
||||||
|
|
||||||
return this.Ok
|
return this.Ok
|
||||||
(
|
(
|
||||||
|
|
|
@ -44,7 +44,7 @@ public class ListController : ControllerBase
|
||||||
.Take(Math.Min(pageSize, 30))
|
.Take(Math.Min(pageSize, 30))
|
||||||
.AsEnumerable();
|
.AsEnumerable();
|
||||||
|
|
||||||
string response = queuedLevels.Aggregate(string.Empty, (current, q) => current + q.Slot.Serialize());
|
string response = queuedLevels.Aggregate(string.Empty, (current, q) => current + q.Slot.Serialize(gameVersion));
|
||||||
|
|
||||||
return this.Ok
|
return this.Ok
|
||||||
(
|
(
|
||||||
|
@ -116,7 +116,7 @@ public class ListController : ControllerBase
|
||||||
.Take(Math.Min(pageSize, 30))
|
.Take(Math.Min(pageSize, 30))
|
||||||
.AsEnumerable();
|
.AsEnumerable();
|
||||||
|
|
||||||
string response = heartedLevels.Aggregate(string.Empty, (current, q) => current + q.Slot.Serialize());
|
string response = heartedLevels.Aggregate(string.Empty, (current, q) => current + q.Slot.Serialize(gameVersion));
|
||||||
|
|
||||||
return this.Ok
|
return this.Ok
|
||||||
(
|
(
|
||||||
|
|
|
@ -130,7 +130,7 @@ public class PublishController : ControllerBase
|
||||||
|
|
||||||
this.database.Entry(oldSlot).CurrentValues.SetValues(slot);
|
this.database.Entry(oldSlot).CurrentValues.SetValues(slot);
|
||||||
await this.database.SaveChangesAsync();
|
await this.database.SaveChangesAsync();
|
||||||
return this.Ok(oldSlot.Serialize());
|
return this.Ok(oldSlot.Serialize(gameToken.GameVersion));
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: parse location in body
|
//TODO: parse location in body
|
||||||
|
@ -162,7 +162,7 @@ public class PublishController : ControllerBase
|
||||||
$"**{user.Username}** just published a new level: [**{slot.Name}**]({ServerSettings.Instance.ExternalUrl}/slot/{slot.SlotId})\n{slot.Description}"
|
$"**{user.Username}** just published a new level: [**{slot.Name}**]({ServerSettings.Instance.ExternalUrl}/slot/{slot.SlotId})\n{slot.Description}"
|
||||||
);
|
);
|
||||||
|
|
||||||
return this.Ok(slot.Serialize());
|
return this.Ok(slot.Serialize(gameToken.GameVersion));
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost("unpublish/{id:int}")]
|
[HttpPost("unpublish/{id:int}")]
|
||||||
|
|
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using LBPUnion.ProjectLighthouse.Serialization;
|
using LBPUnion.ProjectLighthouse.Serialization;
|
||||||
|
using LBPUnion.ProjectLighthouse.Types;
|
||||||
using LBPUnion.ProjectLighthouse.Types.Levels;
|
using LBPUnion.ProjectLighthouse.Types.Levels;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
@ -23,6 +24,14 @@ public class SearchController : ControllerBase
|
||||||
[HttpGet("slots/search")]
|
[HttpGet("slots/search")]
|
||||||
public async Task<IActionResult> SearchSlots([FromQuery] string query, [FromQuery] int pageSize, [FromQuery] int pageStart)
|
public async Task<IActionResult> SearchSlots([FromQuery] string query, [FromQuery] int pageSize, [FromQuery] int pageStart)
|
||||||
{
|
{
|
||||||
|
(User, GameToken)? userAndToken = await this.database.UserAndGameTokenFromRequest(this.Request);
|
||||||
|
|
||||||
|
if (userAndToken == null) return this.StatusCode(403, "");
|
||||||
|
|
||||||
|
// ReSharper disable once PossibleInvalidOperationException
|
||||||
|
User user = userAndToken.Value.Item1;
|
||||||
|
GameToken gameToken = userAndToken.Value.Item2;
|
||||||
|
|
||||||
if (query == null) return this.BadRequest();
|
if (query == null) return this.BadRequest();
|
||||||
|
|
||||||
query = query.ToLower();
|
query = query.ToLower();
|
||||||
|
@ -46,7 +55,7 @@ public class SearchController : ControllerBase
|
||||||
|
|
||||||
List<Slot> slots = await dbQuery.Skip(pageStart - 1).Take(Math.Min(pageSize, 30)).ToListAsync();
|
List<Slot> slots = await dbQuery.Skip(pageStart - 1).Take(Math.Min(pageSize, 30)).ToListAsync();
|
||||||
|
|
||||||
string response = slots.Aggregate("", (current, slot) => current + slot.Serialize());
|
string response = slots.Aggregate("", (current, slot) => current + slot.Serialize(gameToken.GameVersion));
|
||||||
|
|
||||||
return this.Ok(LbpSerializer.TaggedStringElement("slots", response, "total", dbQuery.Count()));
|
return this.Ok(LbpSerializer.TaggedStringElement("slots", response, "total", dbQuery.Count()));
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,7 @@ public class SlotsController : ControllerBase
|
||||||
.Skip(pageStart - 1)
|
.Skip(pageStart - 1)
|
||||||
.Take(Math.Min(pageSize, ServerSettings.Instance.EntitledSlots)),
|
.Take(Math.Min(pageSize, ServerSettings.Instance.EntitledSlots)),
|
||||||
string.Empty,
|
string.Empty,
|
||||||
(current, slot) => current + slot.Serialize()
|
(current, slot) => current + slot.Serialize(token.GameVersion)
|
||||||
);
|
);
|
||||||
|
|
||||||
return this.Ok
|
return this.Ok
|
||||||
|
@ -94,7 +94,7 @@ public class SlotsController : ControllerBase
|
||||||
|
|
||||||
RatedLevel? ratedLevel = await this.database.RatedLevels.FirstOrDefaultAsync(r => r.SlotId == id && r.UserId == user.UserId);
|
RatedLevel? ratedLevel = await this.database.RatedLevels.FirstOrDefaultAsync(r => r.SlotId == id && r.UserId == user.UserId);
|
||||||
VisitedLevel? visitedLevel = await this.database.VisitedLevels.FirstOrDefaultAsync(r => r.SlotId == id && r.UserId == user.UserId);
|
VisitedLevel? visitedLevel = await this.database.VisitedLevels.FirstOrDefaultAsync(r => r.SlotId == id && r.UserId == user.UserId);
|
||||||
return this.Ok(slot.Serialize(ratedLevel, visitedLevel));
|
return this.Ok(slot.Serialize(gameVersion, ratedLevel, visitedLevel));
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("slots/cool")]
|
[HttpGet("slots/cool")]
|
||||||
|
@ -131,7 +131,7 @@ public class SlotsController : ControllerBase
|
||||||
|
|
||||||
IQueryable<Slot> slots = this.getSlots(gameVersion).OrderByDescending(s => s.FirstUploaded).Skip(pageStart - 1).Take(Math.Min(pageSize, 30));
|
IQueryable<Slot> slots = this.getSlots(gameVersion).OrderByDescending(s => s.FirstUploaded).Skip(pageStart - 1).Take(Math.Min(pageSize, 30));
|
||||||
|
|
||||||
string response = Enumerable.Aggregate(slots, string.Empty, (current, slot) => current + slot.Serialize());
|
string response = Enumerable.Aggregate(slots, string.Empty, (current, slot) => current + slot.Serialize(gameVersion));
|
||||||
|
|
||||||
return this.Ok
|
return this.Ok
|
||||||
(
|
(
|
||||||
|
@ -165,7 +165,7 @@ public class SlotsController : ControllerBase
|
||||||
.OrderByDescending(s => s.LastUpdated)
|
.OrderByDescending(s => s.LastUpdated)
|
||||||
.Skip(pageStart - 1)
|
.Skip(pageStart - 1)
|
||||||
.Take(Math.Min(pageSize, 30));
|
.Take(Math.Min(pageSize, 30));
|
||||||
string response = Enumerable.Aggregate(slots, string.Empty, (current, slot) => current + slot.Serialize());
|
string response = Enumerable.Aggregate(slots, string.Empty, (current, slot) => current + slot.Serialize(gameVersion));
|
||||||
|
|
||||||
return this.Ok
|
return this.Ok
|
||||||
(
|
(
|
||||||
|
@ -196,7 +196,7 @@ public class SlotsController : ControllerBase
|
||||||
|
|
||||||
IEnumerable<Slot> slots = this.getSlots(gameVersion).OrderBy(_ => EF.Functions.Random()).Take(Math.Min(pageSize, 30));
|
IEnumerable<Slot> slots = this.getSlots(gameVersion).OrderBy(_ => EF.Functions.Random()).Take(Math.Min(pageSize, 30));
|
||||||
|
|
||||||
string response = slots.Aggregate(string.Empty, (current, slot) => current + slot.Serialize());
|
string response = slots.Aggregate(string.Empty, (current, slot) => current + slot.Serialize(gameVersion));
|
||||||
|
|
||||||
return this.Ok
|
return this.Ok
|
||||||
(
|
(
|
||||||
|
@ -240,7 +240,7 @@ public class SlotsController : ControllerBase
|
||||||
.Skip(pageStart - 1)
|
.Skip(pageStart - 1)
|
||||||
.Take(Math.Min(pageSize, 30));
|
.Take(Math.Min(pageSize, 30));
|
||||||
|
|
||||||
string response = slots.Aggregate(string.Empty, (current, slot) => current + slot.Serialize());
|
string response = slots.Aggregate(string.Empty, (current, slot) => current + slot.Serialize(token.GameVersion));
|
||||||
|
|
||||||
return this.Ok
|
return this.Ok
|
||||||
(
|
(
|
||||||
|
@ -298,7 +298,7 @@ public class SlotsController : ControllerBase
|
||||||
.Skip(pageStart - 1)
|
.Skip(pageStart - 1)
|
||||||
.Take(Math.Min(pageSize, 30));
|
.Take(Math.Min(pageSize, 30));
|
||||||
|
|
||||||
string response = slots.Aggregate(string.Empty, (current, slot) => current + slot.Serialize());
|
string response = slots.Aggregate(string.Empty, (current, slot) => current + slot.Serialize(token.GameVersion));
|
||||||
|
|
||||||
return this.Ok
|
return this.Ok
|
||||||
(
|
(
|
||||||
|
@ -342,7 +342,7 @@ public class SlotsController : ControllerBase
|
||||||
.Skip(pageStart - 1)
|
.Skip(pageStart - 1)
|
||||||
.Take(Math.Min(pageSize, 30));
|
.Take(Math.Min(pageSize, 30));
|
||||||
|
|
||||||
string response = slots.Aggregate(string.Empty, (current, slot) => current + slot.Serialize());
|
string response = slots.Aggregate(string.Empty, (current, slot) => current + slot.Serialize(token.GameVersion));
|
||||||
|
|
||||||
return this.Ok
|
return this.Ok
|
||||||
(
|
(
|
||||||
|
|
|
@ -125,10 +125,8 @@ public class Slot
|
||||||
[XmlIgnore]
|
[XmlIgnore]
|
||||||
[NotMapped]
|
[NotMapped]
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public int Comments
|
public int Comments {
|
||||||
{
|
get {
|
||||||
get
|
|
||||||
{
|
|
||||||
using Database database = new();
|
using Database database = new();
|
||||||
|
|
||||||
return database.Comments.Count(c => c.Type == CommentType.Level && c.TargetId == this.SlotId);
|
return database.Comments.Count(c => c.Type == CommentType.Level && c.TargetId == this.SlotId);
|
||||||
|
@ -254,9 +252,14 @@ public class Slot
|
||||||
LbpSerializer.StringElement("sizeOfResources", this.Resources.Sum(FileHelper.ResourceSize));
|
LbpSerializer.StringElement("sizeOfResources", this.Resources.Sum(FileHelper.ResourceSize));
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Serialize(RatedLevel? yourRatingStats = null, VisitedLevel? yourVisitedStats = null, Review? yourReview = null)
|
public string Serialize
|
||||||
|
(
|
||||||
|
GameVersion gameVersion = GameVersion.LittleBigPlanet1,
|
||||||
|
RatedLevel? yourRatingStats = null,
|
||||||
|
VisitedLevel? yourVisitedStats = null,
|
||||||
|
Review? yourReview = null
|
||||||
|
)
|
||||||
{
|
{
|
||||||
|
|
||||||
string slotData = LbpSerializer.StringElement("name", this.Name) +
|
string slotData = LbpSerializer.StringElement("name", this.Name) +
|
||||||
LbpSerializer.StringElement("id", this.SlotId) +
|
LbpSerializer.StringElement("id", this.SlotId) +
|
||||||
LbpSerializer.StringElement("game", (int)this.GameVersion) +
|
LbpSerializer.StringElement("game", (int)this.GameVersion) +
|
||||||
|
@ -287,13 +290,9 @@ public class Slot
|
||||||
LbpSerializer.StringElement("lbp1PlayCount", this.PlaysLBP1) +
|
LbpSerializer.StringElement("lbp1PlayCount", this.PlaysLBP1) +
|
||||||
LbpSerializer.StringElement("lbp1CompletionCount", this.PlaysLBP1Complete) +
|
LbpSerializer.StringElement("lbp1CompletionCount", this.PlaysLBP1Complete) +
|
||||||
LbpSerializer.StringElement("lbp1UniquePlayCount", this.PlaysLBP1Unique) +
|
LbpSerializer.StringElement("lbp1UniquePlayCount", this.PlaysLBP1Unique) +
|
||||||
LbpSerializer.StringElement("lbp2PlayCount", this.PlaysLBP2) +
|
|
||||||
LbpSerializer.StringElement("lbp2CompletionCount", this.PlaysLBP2Complete) +
|
|
||||||
LbpSerializer.StringElement("lbp2UniquePlayCount", this.PlaysLBP2Unique) + // not actually used ingame, as per above comment
|
|
||||||
LbpSerializer.StringElement("lbp3PlayCount", this.PlaysLBP3) +
|
LbpSerializer.StringElement("lbp3PlayCount", this.PlaysLBP3) +
|
||||||
LbpSerializer.StringElement("lbp3CompletionCount", this.PlaysLBP3Complete) +
|
LbpSerializer.StringElement("lbp3CompletionCount", this.PlaysLBP3Complete) +
|
||||||
LbpSerializer.StringElement("lbp3UniquePlayCount", this.PlaysLBP3Unique) +
|
LbpSerializer.StringElement("lbp3UniquePlayCount", this.PlaysLBP3Unique) +
|
||||||
LbpSerializer.StringElement("vitaCrossControlRequired", this.CrossControllerRequired) +
|
|
||||||
LbpSerializer.StringElement("thumbsup", this.Thumbsup) +
|
LbpSerializer.StringElement("thumbsup", this.Thumbsup) +
|
||||||
LbpSerializer.StringElement("thumbsdown", this.Thumbsdown) +
|
LbpSerializer.StringElement("thumbsdown", this.Thumbsdown) +
|
||||||
LbpSerializer.StringElement("averageRating", this.RatingLBP1) +
|
LbpSerializer.StringElement("averageRating", this.RatingLBP1) +
|
||||||
|
@ -303,13 +302,26 @@ public class Slot
|
||||||
LbpSerializer.StringElement("yourLBP1PlayCount", yourVisitedStats?.PlaysLBP1) +
|
LbpSerializer.StringElement("yourLBP1PlayCount", yourVisitedStats?.PlaysLBP1) +
|
||||||
LbpSerializer.StringElement("yourLBP2PlayCount", yourVisitedStats?.PlaysLBP2) +
|
LbpSerializer.StringElement("yourLBP2PlayCount", yourVisitedStats?.PlaysLBP2) +
|
||||||
LbpSerializer.StringElement("yourLBP3PlayCount", yourVisitedStats?.PlaysLBP3) +
|
LbpSerializer.StringElement("yourLBP3PlayCount", yourVisitedStats?.PlaysLBP3) +
|
||||||
LbpSerializer.StringElement
|
|
||||||
("yourLBPVitaPlayCount", yourVisitedStats?.PlaysLBPVita) + // i doubt this is the right name but we'll go with it
|
|
||||||
yourReview?.Serialize("yourReview") +
|
yourReview?.Serialize("yourReview") +
|
||||||
LbpSerializer.StringElement("reviewsEnabled", ServerSettings.Instance.LevelReviewsEnabled) +
|
LbpSerializer.StringElement("reviewsEnabled", ServerSettings.Instance.LevelReviewsEnabled) +
|
||||||
LbpSerializer.StringElement("commentsEnabled", ServerSettings.Instance.LevelCommentsEnabled) +
|
LbpSerializer.StringElement("commentsEnabled", ServerSettings.Instance.LevelCommentsEnabled) +
|
||||||
LbpSerializer.StringElement("reviewCount", this.ReviewCount);
|
LbpSerializer.StringElement("reviewCount", this.ReviewCount);
|
||||||
|
|
||||||
|
if (gameVersion == GameVersion.LittleBigPlanetVita)
|
||||||
|
{
|
||||||
|
slotData += LbpSerializer.StringElement("yourLBP2PlayCount", yourVisitedStats?.PlaysLBPVita) +
|
||||||
|
LbpSerializer.StringElement("lbp2PlayCount", this.PlaysLBPVita) +
|
||||||
|
LbpSerializer.StringElement("lbp2CompletionCount", this.PlaysLBPVitaComplete) +
|
||||||
|
LbpSerializer.StringElement("lbp2UniquePlayCount", this.PlaysLBPVitaUnique);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
slotData += LbpSerializer.StringElement("yourLBP2PlayCount", yourVisitedStats?.PlaysLBPVita) +
|
||||||
|
LbpSerializer.StringElement("lbp2PlayCount", this.PlaysLBP2) +
|
||||||
|
LbpSerializer.StringElement("lbp2CompletionCount", this.PlaysLBP2Complete) +
|
||||||
|
LbpSerializer.StringElement("lbp2UniquePlayCount", this.PlaysLBP2Unique); // not actually used ingame, as per above comment
|
||||||
|
}
|
||||||
|
|
||||||
return LbpSerializer.TaggedStringElement("slot", slotData, "type", "user");
|
return LbpSerializer.TaggedStringElement("slot", slotData, "type", "user");
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue