From be9e3edef546a0a74326361389f2ac8bec93e0ab Mon Sep 17 00:00:00 2001 From: Josh Date: Mon, 21 Feb 2022 11:03:25 -0600 Subject: [PATCH] Fix review button not showing up (#180) --- .../GameApi/Slots/ReviewController.cs | 38 ++----------------- ProjectLighthouse/Types/Levels/Slot.cs | 9 ++--- 2 files changed, 7 insertions(+), 40 deletions(-) diff --git a/ProjectLighthouse/Controllers/GameApi/Slots/ReviewController.cs b/ProjectLighthouse/Controllers/GameApi/Slots/ReviewController.cs index e7ad7d7f..71bbc3f4 100644 --- a/ProjectLighthouse/Controllers/GameApi/Slots/ReviewController.cs +++ b/ProjectLighthouse/Controllers/GameApi/Slots/ReviewController.cs @@ -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 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 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) => diff --git a/ProjectLighthouse/Types/Levels/Slot.cs b/ProjectLighthouse/Types/Levels/Slot.cs index 23a9d495..f2a35c21 100644 --- a/ProjectLighthouse/Types/Levels/Slot.cs +++ b/ProjectLighthouse/Types/Levels/Slot.cs @@ -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