mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-08-02 10:08:39 +00:00
Merge branch 'main' into recent-activity
This commit is contained in:
commit
27cbb14a49
7 changed files with 145 additions and 3 deletions
|
@ -173,6 +173,13 @@ public class ReviewController : ControllerBase
|
|||
|
||||
List<GameReview> reviews = (await this.database.Reviews
|
||||
.Where(r => r.SlotId == slotId)
|
||||
.Select(r => new
|
||||
{
|
||||
Review = r,
|
||||
SlotVersion = r.Slot!.GameVersion,
|
||||
})
|
||||
.Where(a => a.SlotVersion <= token.GameVersion)
|
||||
.Select(a => a.Review)
|
||||
.OrderByDescending(r => r.ThumbsUp - r.ThumbsDown)
|
||||
.ThenByDescending(r => r.Timestamp)
|
||||
.ApplyPagination(pageData)
|
||||
|
@ -194,6 +201,13 @@ public class ReviewController : ControllerBase
|
|||
|
||||
List<GameReview> reviews = (await this.database.Reviews
|
||||
.Where(r => r.ReviewerId == targetUserId)
|
||||
.Select(r => new
|
||||
{
|
||||
Review = r,
|
||||
SlotVersion = r.Slot!.GameVersion,
|
||||
})
|
||||
.Where(a => a.SlotVersion <= token.GameVersion)
|
||||
.Select(a => a.Review)
|
||||
.OrderByDescending(r => r.Timestamp)
|
||||
.ApplyPagination(pageData)
|
||||
.ToListAsync()).ToSerializableList(r => GameReview.CreateFromEntity(r, token));
|
||||
|
|
|
@ -180,7 +180,7 @@ public class UserController : ControllerBase
|
|||
// Sometimes the update gets called periodically as pin progress updates via playing,
|
||||
// may not affect equipped profile pins however, so check before setting it.
|
||||
string currentPins = user.Pins;
|
||||
string newPins = string.Join(",", pinJson.ProfilePins);
|
||||
string newPins = string.Join(",", pinJson.ProfilePins.Distinct());
|
||||
|
||||
if (string.Equals(currentPins, newPins)) return this.Ok("[{\"StatusCode\":200}]");
|
||||
|
||||
|
|
|
@ -45,7 +45,8 @@ public class UserPage : BaseLayout
|
|||
if (this.ProfileUser == null) return this.NotFound();
|
||||
|
||||
string userSlug = this.ProfileUser.GenerateSlug();
|
||||
if (slug == null || userSlug != slug)
|
||||
// Only redirect if there is a valid slug for this user and the current slug doesn't match
|
||||
if (!string.IsNullOrWhiteSpace(userSlug) && (slug == null || userSlug != slug))
|
||||
{
|
||||
return this.Redirect($"~/user/{userId}/{userSlug}");
|
||||
}
|
||||
|
|
|
@ -0,0 +1,99 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using LBPUnion.ProjectLighthouse.Database;
|
||||
using LBPUnion.ProjectLighthouse.Servers.GameServer.Controllers.Slots;
|
||||
using LBPUnion.ProjectLighthouse.Tests.Helpers;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Level;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Token;
|
||||
using LBPUnion.ProjectLighthouse.Types.Serialization;
|
||||
using LBPUnion.ProjectLighthouse.Types.Users;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Xunit;
|
||||
|
||||
namespace ProjectLighthouse.Tests.GameApiTests.Unit.Controllers;
|
||||
|
||||
public class ReviewControllerTests
|
||||
{
|
||||
private static async Task InsertTestData(DatabaseContext database)
|
||||
{
|
||||
database.Slots.Add(new SlotEntity
|
||||
{
|
||||
SlotId = 1,
|
||||
CreatorId = 1,
|
||||
GameVersion = GameVersion.LittleBigPlanet3,
|
||||
});
|
||||
|
||||
database.Slots.Add(new SlotEntity
|
||||
{
|
||||
SlotId = 2,
|
||||
CreatorId = 1,
|
||||
GameVersion = GameVersion.LittleBigPlanet2,
|
||||
});
|
||||
|
||||
database.Reviews.Add(new ReviewEntity
|
||||
{
|
||||
ReviewId = 1,
|
||||
ReviewerId = 1,
|
||||
SlotId = 1,
|
||||
});
|
||||
|
||||
database.Reviews.Add(new ReviewEntity
|
||||
{
|
||||
ReviewId = 2,
|
||||
ReviewerId = 1,
|
||||
SlotId = 2,
|
||||
});
|
||||
await database.SaveChangesAsync();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(GameVersion.LittleBigPlanet2, 1)]
|
||||
[InlineData(GameVersion.LittleBigPlanet3, 2)]
|
||||
public async Task ReviewsBy_ShouldNotList_HigherGameVersions(GameVersion version, int expected)
|
||||
{
|
||||
GameTokenEntity token = MockHelper.GetUnitTestToken();
|
||||
token.GameVersion = version;
|
||||
DatabaseContext database = await MockHelper.GetTestDatabase(new List<GameTokenEntity>
|
||||
{
|
||||
token,
|
||||
});
|
||||
|
||||
await InsertTestData(database);
|
||||
|
||||
ReviewController controller = new(database);
|
||||
controller.SetupTestController(token);
|
||||
|
||||
IActionResult response = await controller.ReviewsBy("unittest");
|
||||
ReviewResponse review = response.CastTo<OkObjectResult, ReviewResponse>();
|
||||
|
||||
Assert.Equal(expected, review.Reviews.Count);
|
||||
Assert.True(review.Reviews.All(r => database.Slots.FirstOrDefault(s => s.SlotId == r.Slot.SlotId)?.GameVersion <= version));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(GameVersion.LittleBigPlanet2, 2, 1)]
|
||||
[InlineData(GameVersion.LittleBigPlanet2, 1, 0)]
|
||||
[InlineData(GameVersion.LittleBigPlanet3, 2, 1)]
|
||||
[InlineData(GameVersion.LittleBigPlanet3, 1, 1)]
|
||||
public async Task ReviewsFor_ShouldNotList_HigherGameVersions(GameVersion version, int slotId, int expected)
|
||||
{
|
||||
GameTokenEntity token = MockHelper.GetUnitTestToken();
|
||||
token.GameVersion = version;
|
||||
DatabaseContext database = await MockHelper.GetTestDatabase(new List<GameTokenEntity>
|
||||
{
|
||||
token,
|
||||
});
|
||||
|
||||
await InsertTestData(database);
|
||||
|
||||
ReviewController controller = new(database);
|
||||
controller.SetupTestController(token);
|
||||
|
||||
IActionResult response = await controller.ReviewsFor(slotId);
|
||||
ReviewResponse review = response.CastTo<OkObjectResult, ReviewResponse>();
|
||||
|
||||
Assert.Equal(expected, review.Reviews.Count);
|
||||
Assert.True(review.Reviews.All(r => database.Slots.FirstOrDefault(s => s.SlotId == r.Slot.SlotId)?.GameVersion <= version));
|
||||
}
|
||||
}
|
|
@ -177,4 +177,29 @@ public class UserControllerTests
|
|||
Assert.Equal(expectedPins, dbMock.Users.First().Pins);
|
||||
Assert.Equal(expectedResponse, pinsResponse);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task UpdateMyPins_ShouldRemove_DuplicatePins()
|
||||
{
|
||||
UserEntity entity = MockHelper.GetUnitTestUser();
|
||||
entity.Pins = "1234";
|
||||
List<UserEntity> users = new()
|
||||
{
|
||||
entity,
|
||||
};
|
||||
await using DatabaseContext dbMock = await MockHelper.GetTestDatabase(users);
|
||||
|
||||
UserController userController = new(dbMock);
|
||||
userController.SetupTestController("{\"profile_pins\": [1234, 1234]}");
|
||||
|
||||
const string expectedPins = "1234";
|
||||
const string expectedResponse = "[{\"StatusCode\":200}]";
|
||||
|
||||
IActionResult result = await userController.UpdateMyPins();
|
||||
|
||||
string pinsResponse = result.CastTo<OkObjectResult, string>();
|
||||
|
||||
Assert.Equal(expectedPins, dbMock.Users.First().Pins);
|
||||
Assert.Equal(expectedResponse, pinsResponse);
|
||||
}
|
||||
}
|
|
@ -15,7 +15,7 @@
|
|||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Pfim" Version="0.11.2" />
|
||||
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.3" />
|
||||
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.4" />
|
||||
<PackageReference Include="Discord.Net.Webhook" Version="3.14.1" />
|
||||
<PackageReference Include="JetBrains.Annotations" Version="2023.3.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="8.0.3" />
|
||||
|
|
|
@ -33,6 +33,9 @@ public struct SectionHeader
|
|||
public SectionType Type;
|
||||
public ushort Length;
|
||||
public int Position;
|
||||
|
||||
public override string ToString() =>
|
||||
$"SectionHeader(Type='{this.Type}', Length='{this.Length}', Position='{this.Position}')";
|
||||
}
|
||||
|
||||
public class TicketReader : BinaryReader
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue