Skip to content

Commit

Permalink
Add restore categories
Browse files Browse the repository at this point in the history
  • Loading branch information
zysim committed Jan 22, 2025
1 parent 7e917c7 commit c91702d
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion LeaderboardBackend/Controllers/LeaderboardsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public async Task<ActionResult<LeaderboardViewModel>> RestoreLeaderboard(
long id
)
{
RestoreLeaderboardResult r = await leaderboardService.RestoreLeaderboard(id);
RestoreResult<Leaderboard> r = await leaderboardService.RestoreLeaderboard(id);

return r.Match<ActionResult<LeaderboardViewModel>>(
board => Ok(LeaderboardViewModel.MapFrom(board)),
Expand Down
5 changes: 4 additions & 1 deletion LeaderboardBackend/Results.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace LeaderboardBackend.Result;
public record Conflict<T>(T Conflicting);
public readonly record struct EmailFailed;
public readonly record struct Expired;
public readonly record struct LeaderboardNeverDeleted;
public readonly record struct NeverDeleted;
public readonly record struct UserNotFound;
public readonly record struct UserBanned;

Expand All @@ -21,3 +21,6 @@ public partial class DeleteResult : OneOfBase<Success, NotFound, AlreadyDeleted>

[GenerateOneOf]
public partial class UpdateResult<T> : OneOfBase<Conflict<T>, NotFound, Success>;

[GenerateOneOf]
public partial class RestoreResult<T> : OneOfBase<T, NotFound, NeverDeleted, Conflict<T>>;
1 change: 1 addition & 0 deletions LeaderboardBackend/Services/ICategoryService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public interface ICategoryService
Task<CreateCategoryResult> CreateCategory(long leaderboardId, CreateCategoryRequest request);
Task<Category?> GetCategoryForRun(Run run);
Task<DeleteResult> DeleteCategory(long id);
Task<RestoreResult<Category>> RestoreCategory(long id);
}

[GenerateOneOf]
Expand Down
5 changes: 1 addition & 4 deletions LeaderboardBackend/Services/ILeaderboardService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,10 @@ public interface ILeaderboardService
Task<Leaderboard?> GetLeaderboardBySlug(string slug);
Task<List<Leaderboard>> ListLeaderboards(bool includeDeleted);
Task<CreateLeaderboardResult> CreateLeaderboard(CreateLeaderboardRequest request);
Task<RestoreLeaderboardResult> RestoreLeaderboard(long id);
Task<RestoreResult<Leaderboard>> RestoreLeaderboard(long id);
Task<DeleteResult> DeleteLeaderboard(long id);
Task<UpdateResult<Leaderboard>> UpdateLeaderboard(long id, UpdateLeaderboardRequest request);
}

[GenerateOneOf]
public partial class CreateLeaderboardResult : OneOfBase<Leaderboard, Conflict<Leaderboard>>;

[GenerateOneOf]
public partial class RestoreLeaderboardResult : OneOfBase<Leaderboard, NotFound, LeaderboardNeverDeleted, Conflict<Leaderboard>>;
7 changes: 7 additions & 0 deletions LeaderboardBackend/Services/Impl/CategoryService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,11 @@ public async Task<DeleteResult> DeleteCategory(long id)
await applicationContext.SaveChangesAsync();
return new Success();
}

public async Task<RestoreResult<Category>> RestoreCategory(long id)
{
Category? category = await applicationContext.Categories.FindAsync(id);

return new NotFound();
}
}
4 changes: 2 additions & 2 deletions LeaderboardBackend/Services/Impl/LeaderboardService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public async Task<CreateLeaderboardResult> CreateLeaderboard(CreateLeaderboardRe
return lb;
}

public async Task<RestoreLeaderboardResult> RestoreLeaderboard(long id)
public async Task<RestoreResult<Leaderboard>> RestoreLeaderboard(long id)
{
Leaderboard? lb = await applicationContext.Leaderboards.FindAsync(id);

Expand All @@ -59,7 +59,7 @@ public async Task<RestoreLeaderboardResult> RestoreLeaderboard(long id)

if (lb.DeletedAt == null)
{
return new LeaderboardNeverDeleted();
return new NeverDeleted();
}

lb.DeletedAt = null;
Expand Down

0 comments on commit c91702d

Please sign in to comment.