Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/nuget/JetBrains.Annotations-2024.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jvyden authored Nov 3, 2024
2 parents d363e0e + 0d3edc4 commit d7e8bfe
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
13 changes: 13 additions & 0 deletions Refresh.GameServer/Database/GameDatabaseContext.Relations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,19 @@ public void AddReviewToLevel(GameReview review, GameLevel level)

this.AddSequentialObject(review, level.Reviews);
}

public void DeleteReviewsPostedByUser(GameUser user)
{
IEnumerable<GameReview> reviews = this.GameReviews.Where(s => s.Publisher == user);

this.Write(() =>
{
foreach (GameReview review in reviews)
{
this.DeleteReview(review);
}
});
}

public DatabaseList<GameReview> GetReviewsByUser(GameUser user, int count, int skip)
{
Expand Down
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();
}
}

0 comments on commit d7e8bfe

Please sign in to comment.