Skip to content

Commit

Permalink
Fix that test, sort playlists and playlist levels
Browse files Browse the repository at this point in the history
  • Loading branch information
Toastbrot236 committed Jan 11, 2025
1 parent a1328af commit dbdc2a9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
12 changes: 9 additions & 3 deletions Refresh.GameServer/Database/GameDatabaseContext.Playlists.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@ public void CreatePlaylist(GamePlaylist createInfo)
{
DateTimeOffset now = this._time.Now;

this.Write(() =>
this.AddSequentialObject(createInfo, () =>
{
createInfo.CreationDate = now;
createInfo.LastUpdateDate = now;
this.AddSequentialObject(createInfo);
});
}

Expand Down Expand Up @@ -173,12 +172,14 @@ public void SetPlaylistLevelIndex(GamePlaylist playlist, GameLevel level, int ne
public IEnumerable<GamePlaylist> GetPlaylistsContainingPlaylist(GamePlaylist playlist)
// TODO: with postgres this can be IQueryable
=> this.SubPlaylistRelations.Where(p => p.SubPlaylist == playlist).AsEnumerable()
.Reverse()
.Select(r => this.GamePlaylists.First(p => p.PlaylistId == r.Playlist.PlaylistId))
.Where(p => !p.IsRoot);

public IEnumerable<GamePlaylist> GetPlaylistsByAuthorContainingPlaylist(GameUser user, GamePlaylist playlist)
// TODO: with postgres this can be IQueryable
=> this.SubPlaylistRelations.Where(p => p.SubPlaylist == playlist).AsEnumerable()
.Reverse()
.Select(r => this.GamePlaylists.First(p => p.PlaylistId == r.Playlist.PlaylistId))
.Where(p => p.Publisher.UserId == user.UserId)
.Where(p => !p.IsRoot);
Expand Down Expand Up @@ -206,22 +207,26 @@ public int GetTotalLevelsInPlaylistCount(GamePlaylist playlist) =>
public IEnumerable<GamePlaylist> GetPlaylistsInPlaylist(GamePlaylist playlist)
// TODO: When we have postgres, remove the `AsEnumerable` call for performance.
=> this.SubPlaylistRelations.Where(p => p.Playlist == playlist).AsEnumerable()
.Reverse()
.Select(l => l.SubPlaylist);

public IEnumerable<GamePlaylist> GetPlaylistsByAuthor(GameUser author)
// TODO: When we have postgres, remove the `AsEnumerable` call for performance.
=> this.GamePlaylists.Where(p => p.Publisher == author).AsEnumerable()
.Where(p => !p.IsRoot);
.Where(p => !p.IsRoot)
.OrderByDescending(p => p.LastUpdateDate);

public IEnumerable<GamePlaylist> GetPlaylistsByAuthorContainingLevel(GameUser author, GameLevel level)
// TODO: When we have postgres, remove the `AsEnumerable` call for performance.
=> this.LevelPlaylistRelations.Where(p => p.Level == level).AsEnumerable()
.Reverse()
.Select(r => this.GamePlaylists.First(p => p.PlaylistId == r.Playlist.PlaylistId))
.Where(p => p.Publisher.UserId == author.UserId);

public IEnumerable<GamePlaylist> GetPlaylistsContainingLevel(GameLevel level)
// TODO: When we have postgres, remove the `AsEnumerable` call for performance.
=> this.LevelPlaylistRelations.Where(p => p.Level == level).AsEnumerable()
.Reverse()
.Select(r => this.GamePlaylists.First(p => p.PlaylistId == r.Playlist.PlaylistId));

public int GetFavouriteCountForPlaylist(GamePlaylist playlist)
Expand All @@ -234,6 +239,7 @@ public bool IsPlaylistFavouritedByUser(GamePlaylist playlist, GameUser user)
public IEnumerable<GamePlaylist> GetPlaylistsFavouritedByUser(GameUser user)
// TODO: When we have postgres, remove the `AsEnumerable` call for performance.
=> this.FavouritePlaylistRelations.Where(r => r.User == user).AsEnumerable()
.Reverse()
.Select(r => r.Playlist);

public bool FavouritePlaylist(GamePlaylist playlist, GameUser user)
Expand Down
6 changes: 4 additions & 2 deletions RefreshTests.GameServer/Tests/Levels/LevelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -487,15 +487,17 @@ public void DoesntGetSlotListWhenNoQuery()
}

[Test]
public void DoesntGetSlotListWhenInvalidQuery()
public void GetSlotListWhenInvalidQuery()
{
using TestContext context = this.GetServer();
GameUser publisher = context.CreateUser();

using HttpClient client = context.GetAuthenticatedClient(TokenType.Game, publisher);

HttpResponseMessage message = client.GetAsync($"/lbp/slotList?s=NOT_A_NUMBER").Result;
Assert.That(message.StatusCode, Is.EqualTo(BadRequest));
Assert.That(message.StatusCode, Is.EqualTo(OK));
SerializedLevelList result = message.Content.ReadAsXML<SerializedLevelList>();
Assert.That(result.Items, Has.Count.EqualTo(0));
}

[Test]
Expand Down

0 comments on commit dbdc2a9

Please sign in to comment.