Skip to content

Commit

Permalink
Implement the level photos endpoint (#587)
Browse files Browse the repository at this point in the history
This was one of the last unimplemented endpoints for LBP1
  • Loading branch information
jvyden authored Jul 28, 2024
2 parents e64d914 + b9adb75 commit 812f271
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion Refresh.GameServer/Endpoints/Game/PhotoEndpoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
using Bunkum.Core.Storage;
using Bunkum.Listener.Protocol;
using Bunkum.Protocols.Http;
using Refresh.GameServer.Authentication;
using Refresh.GameServer.Database;
using Refresh.GameServer.Extensions;
using Refresh.GameServer.Types.Data;
using Refresh.GameServer.Types.Levels;
using Refresh.GameServer.Types.Lists;
using Refresh.GameServer.Types.Photos;
using Refresh.GameServer.Types.Roles;
Expand Down Expand Up @@ -83,6 +83,22 @@ public Response PhotosWithUser(RequestContext context, GameDatabaseContext datab
public Response PhotosByUser(RequestContext context, GameDatabaseContext database, DataContext dataContext)
=> GetPhotos(context, database, dataContext, database.GetPhotosByUser);

[GameEndpoint("photos/{slotType}/{levelId}", ContentType.Xml)]
public Response GetPhotosOnLevel(RequestContext context, DataContext dataContext, string slotType, int levelId)
{
GameLevel? level = dataContext.Database.GetLevelByIdAndType(slotType, levelId);
if (level == null)
return NotFound;

(int skip, int count) = context.GetPageData();

// count not used ingame
IEnumerable<SerializedPhoto> photos = dataContext.Database.GetPhotosInLevel(level, count, skip).Items
.Select(photo => SerializedPhoto.FromGamePhoto(photo, dataContext));

return new Response(new SerializedPhotoList(photos), ContentType.Xml);
}

[GameEndpoint("photo/{id}", ContentType.Xml)]
[NullStatusCode(NotFound)]
public SerializedPhoto? GetPhotoById(RequestContext context, DataContext dataContext, int id)
Expand Down

0 comments on commit 812f271

Please sign in to comment.