Skip to content

Commit

Permalink
Implement other comments
Browse files Browse the repository at this point in the history
  • Loading branch information
zysim committed Sep 7, 2024
1 parent 26ce390 commit 2c53611
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
2 changes: 1 addition & 1 deletion LeaderboardBackend/Services/ILeaderboardService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace LeaderboardBackend.Services;

public interface ILeaderboardService
{
ValueTask<Leaderboard?> GetLeaderboard(long id);
Task<Leaderboard?> GetLeaderboard(long id);
Task<Leaderboard?> GetLeaderboardBySlug(string slug);
Task<List<Leaderboard>> GetLeaderboards(long[]? ids = null);
Task CreateLeaderboard(Leaderboard leaderboard);
Expand Down
18 changes: 8 additions & 10 deletions LeaderboardBackend/Services/Impl/LeaderboardService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@ namespace LeaderboardBackend.Services;

public class LeaderboardService(ApplicationContext applicationContext) : ILeaderboardService
{
private readonly ApplicationContext _applicationContext = applicationContext;

public ValueTask<Leaderboard?> GetLeaderboard(long id) =>
_applicationContext.Leaderboards
.FindAsync([id]);
public async Task<Leaderboard?> GetLeaderboard(long id) =>
await applicationContext.Leaderboards
.FirstOrDefaultAsync(board => board.Id == id);

public Task<Leaderboard?> GetLeaderboardBySlug(string slug) =>
_applicationContext.Leaderboards
applicationContext.Leaderboards
.AsNoTracking()
.FirstOrDefaultAsync(x => x.Slug == slug);

Expand All @@ -21,19 +19,19 @@ public async Task<List<Leaderboard>> GetLeaderboards(long[]? ids = null)
{
if (ids is null)
{
return await _applicationContext.Leaderboards.ToListAsync();
return await applicationContext.Leaderboards.ToListAsync();
}
else
{
return await _applicationContext.Leaderboards
return await applicationContext.Leaderboards
.Where(leaderboard => ids.Contains(leaderboard.Id))
.ToListAsync();
}
}

public async Task CreateLeaderboard(Leaderboard leaderboard)
{
_applicationContext.Leaderboards.Add(leaderboard);
await _applicationContext.SaveChangesAsync();
applicationContext.Leaderboards.Add(leaderboard);
await applicationContext.SaveChangesAsync();
}
}

0 comments on commit 2c53611

Please sign in to comment.