Skip to content

Commit

Permalink
Add API lookup for levels by their root resource (#538)
Browse files Browse the repository at this point in the history
Does not include other endpoints for editing/deleting since that would
cause a fair bit of code duplication. For now it's expected that you
just use the hash to get the ID of the level for those queries.

I don't expect this to be a common lookup either way; just adding this
because I don't see why not.
  • Loading branch information
jvyden authored Jun 19, 2024
2 parents cf2404f + 0574f15 commit d184aca
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions Refresh.GameServer/Endpoints/ApiV3/LevelApiEndpoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,19 @@ public ApiResponse<ApiGameLevelResponse> GetLevelById(RequestContext context, Ga
return ApiGameLevelResponse.FromOld(level, dataContext);
}

[ApiV3Endpoint("levels/hash/{hash}"), Authentication(false)]
[DocSummary("Gets an individual level by the level's RootResource hash")]
[DocError(typeof(ApiNotFoundError), "The level cannot be found")]
public ApiResponse<ApiGameLevelResponse> GetLevelByRootResource(RequestContext context, GameDatabaseContext database,
IDataStore dataStore,
[DocSummary("The RootResource hash of the level")] string hash, DataContext dataContext)
{
GameLevel? level = database.GetLevelByRootResource(hash);
if (level == null) return ApiNotFoundError.LevelMissingError;

return ApiGameLevelResponse.FromOld(level, dataContext);
}

[ApiV3Endpoint("levels/id/{id}", HttpMethods.Patch)]
[DocSummary("Edits a level by the level's numerical ID")]
[DocError(typeof(ApiNotFoundError), ApiNotFoundError.LevelMissingErrorWhen)]
Expand Down

0 comments on commit d184aca

Please sign in to comment.