-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add API endpoint to purge all reviews by the given user
- Loading branch information
Showing
2 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
Refresh.GameServer/Endpoints/ApiV3/Admin/AdminReviewApiEndpoints.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using AttribDoc.Attributes; | ||
using Bunkum.Core; | ||
using Bunkum.Core.Endpoints; | ||
using Bunkum.Protocols.Http; | ||
using Refresh.GameServer.Database; | ||
using Refresh.GameServer.Endpoints.ApiV3.ApiTypes; | ||
using Refresh.GameServer.Endpoints.ApiV3.ApiTypes.Errors; | ||
using Refresh.GameServer.Types.Roles; | ||
using Refresh.GameServer.Types.UserData; | ||
|
||
namespace Refresh.GameServer.Endpoints.ApiV3.Admin; | ||
|
||
public class AdminReviewApiEndpoints : EndpointGroup | ||
{ | ||
[ApiV3Endpoint("admin/users/uuid/{uuid}/reviews", HttpMethods.Delete), MinimumRole(GameUserRole.Admin)] | ||
[DocSummary("Deletes all reviews posted by a user. Gets user by their UUID.")] | ||
[DocError(typeof(ApiNotFoundError), ApiNotFoundError.UserMissingErrorWhen)] | ||
public ApiOkResponse DeleteReviewsPostedByUuid(RequestContext context, GameDatabaseContext database, | ||
[DocSummary("The UUID of the user")] string uuid) | ||
{ | ||
GameUser? user = database.GetUserByUuid(uuid); | ||
if (user == null) return ApiNotFoundError.UserMissingError; | ||
|
||
database.DeleteReviewsPostedByUser(user); | ||
return new ApiOkResponse(); | ||
} | ||
|
||
[ApiV3Endpoint("admin/users/name/{username}/reviews", HttpMethods.Delete), MinimumRole(GameUserRole.Admin)] | ||
[DocSummary("Deletes all reviews posted by a user. Gets user by their username.")] | ||
[DocError(typeof(ApiNotFoundError), ApiNotFoundError.UserMissingErrorWhen)] | ||
public ApiOkResponse DeleteReviewsPostedByUsername(RequestContext context, GameDatabaseContext database, | ||
[DocSummary("The username of the user")] string username) | ||
{ | ||
GameUser? user = database.GetUserByUsername(username); | ||
if (user == null) return ApiNotFoundError.UserMissingError; | ||
|
||
database.DeleteReviewsPostedByUser(user); | ||
return new ApiOkResponse(); | ||
} | ||
} |