Skip to content

Commit

Permalink
Ability for admins to delete contests (#464)
Browse files Browse the repository at this point in the history
  • Loading branch information
jvyden authored May 6, 2024
2 parents c283801 + c659a6d commit 7205dca
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Refresh.GameServer/Database/GameDatabaseContext.Contests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ public void CreateContest(GameContest contest)
});
}

public void DeleteContest(GameContest contest)
{
this._realm.Write(() =>
{
this._realm.Remove(contest);
});
}

public GameContest? GetContestById(string? id)
{
if (id == null) return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,17 @@ public ApiResponse<ApiContestResponse> CreateContest(RequestContext context, Gam

return ApiContestResponse.FromOld(contest);
}

[ApiV3Endpoint("admin/contests/{id}", HttpMethods.Delete), MinimumRole(GameUserRole.Admin)]
[DocSummary("Deletes a contest.")]
[DocError(typeof(ApiNotFoundError), ApiNotFoundError.ContestMissingErrorWhen)]
public ApiOkResponse DeleteContest(RequestContext context, GameDatabaseContext database, string id)
{
GameContest? contest = database.GetContestById(id);
if (contest == null) return ApiNotFoundError.ContestMissingError;

database.DeleteContest(contest);

return new ApiOkResponse();
}
}

0 comments on commit 7205dca

Please sign in to comment.