mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-07-29 00:18:39 +00:00
Fix review button not showing up (#180)
This commit is contained in:
parent
3cda95447b
commit
be9e3edef5
2 changed files with 7 additions and 40 deletions
|
@ -17,7 +17,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers.GameApi.Slots;
|
|||
|
||||
[ApiController]
|
||||
[Route("LITTLEBIGPLANETPS3_XML/")]
|
||||
[Produces("text/plain")]
|
||||
[Produces("text/xml")]
|
||||
public class ReviewController : ControllerBase
|
||||
{
|
||||
private readonly Database database;
|
||||
|
@ -141,51 +141,19 @@ public class ReviewController : ControllerBase
|
|||
|
||||
GameVersion gameVersion = gameToken.GameVersion;
|
||||
|
||||
Random rand = new();
|
||||
|
||||
Review? yourReview = await this.database.Reviews.FirstOrDefaultAsync
|
||||
(r => r.ReviewerId == user.UserId && r.SlotId == slotId && r.Slot.GameVersion <= gameVersion);
|
||||
|
||||
VisitedLevel? visitedLevel = await this.database.VisitedLevels.FirstOrDefaultAsync
|
||||
(v => v.UserId == user.UserId && v.SlotId == slotId && v.Slot.GameVersion <= gameVersion);
|
||||
|
||||
Slot? slot = await this.database.Slots.FirstOrDefaultAsync(s => s.SlotId == slotId);
|
||||
if (slot == null) return this.BadRequest();
|
||||
|
||||
bool canNowReviewLevel = slot.CreatorId != user.UserId && visitedLevel != null && yourReview == null;
|
||||
if (canNowReviewLevel)
|
||||
{
|
||||
RatedLevel? ratedLevel = await this.database.RatedLevels.FirstOrDefaultAsync
|
||||
(r => r.UserId == user.UserId && r.SlotId == slotId && r.Slot.GameVersion <= gameVersion);
|
||||
|
||||
yourReview = new Review();
|
||||
yourReview.ReviewerId = user.UserId;
|
||||
yourReview.Reviewer = user;
|
||||
yourReview.Thumb = ratedLevel?.Rating ?? 0;
|
||||
yourReview.Slot = slot;
|
||||
yourReview.SlotId = slotId;
|
||||
yourReview.Deleted = false;
|
||||
yourReview.DeletedBy = DeletedBy.None;
|
||||
yourReview.Text = "You haven't reviewed this level yet. Edit this to write one!";
|
||||
yourReview.LabelCollection = "";
|
||||
yourReview.Timestamp = TimeHelper.UnixTimeMilliseconds();
|
||||
}
|
||||
|
||||
IQueryable<Review?> reviews = this.database.Reviews.Where(r => r.SlotId == slotId && r.Slot.GameVersion <= gameVersion)
|
||||
.Include(r => r.Reviewer)
|
||||
.Include(r => r.Slot)
|
||||
.OrderByDescending(r => r.ThumbsUp)
|
||||
.ThenByDescending(_ => EF.Functions.Random())
|
||||
.ThenByDescending(r => r.Timestamp)
|
||||
.Skip(pageStart - 1)
|
||||
.Take(pageSize);
|
||||
|
||||
IEnumerable<Review?> prependedReviews;
|
||||
if (canNowReviewLevel) // this can only be true if you have not posted a review but have visited the level
|
||||
// prepend the fake review to the top of the list to be easily edited
|
||||
prependedReviews = reviews.ToList().Prepend(yourReview);
|
||||
else prependedReviews = reviews.ToList();
|
||||
|
||||
string inner = prependedReviews.Aggregate
|
||||
string inner = reviews.ToList().Aggregate
|
||||
(
|
||||
string.Empty,
|
||||
(current, review) =>
|
||||
|
|
|
@ -299,9 +299,8 @@ public class Slot
|
|||
LbpSerializer.StringElement("leveltype", this.LevelType) +
|
||||
LbpSerializer.StringElement("yourRating", yourRatingStats?.RatingLBP1) +
|
||||
LbpSerializer.StringElement("yourDPadRating", yourRatingStats?.Rating) +
|
||||
LbpSerializer.StringElement("yourLBP1PlayCount", yourVisitedStats?.PlaysLBP1) +
|
||||
LbpSerializer.StringElement("yourLBP2PlayCount", yourVisitedStats?.PlaysLBP2) +
|
||||
LbpSerializer.StringElement("yourLBP3PlayCount", yourVisitedStats?.PlaysLBP3) +
|
||||
LbpSerializer.StringElement("yourlbpPlayCount", yourVisitedStats?.PlaysLBP1) +
|
||||
LbpSerializer.StringElement("yourlbp3PlayCount", yourVisitedStats?.PlaysLBP3) +
|
||||
yourReview?.Serialize("yourReview") +
|
||||
LbpSerializer.StringElement("reviewsEnabled", ServerSettings.Instance.LevelReviewsEnabled) +
|
||||
LbpSerializer.StringElement("commentsEnabled", ServerSettings.Instance.LevelCommentsEnabled) +
|
||||
|
@ -309,14 +308,14 @@ public class Slot
|
|||
|
||||
if (gameVersion == GameVersion.LittleBigPlanetVita)
|
||||
{
|
||||
slotData += LbpSerializer.StringElement("yourLBP2PlayCount", yourVisitedStats?.PlaysLBPVita) +
|
||||
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) +
|
||||
slotData += LbpSerializer.StringElement("yourlbp2PlayCount", yourVisitedStats?.PlaysLBP2) +
|
||||
LbpSerializer.StringElement("lbp2PlayCount", this.PlaysLBP2) +
|
||||
LbpSerializer.StringElement("lbp2CompletionCount", this.PlaysLBP2Complete) +
|
||||
LbpSerializer.StringElement("lbp2UniquePlayCount", this.PlaysLBP2Unique); // not actually used ingame, as per above comment
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue