Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ZOXEXIVO committed May 7, 2024
1 parent 8cf2f4d commit 816621a
Show file tree
Hide file tree
Showing 9 changed files with 8,197 additions and 6,956 deletions.
25 changes: 9 additions & 16 deletions src/Backend/Geen.Data/Repositories/ClubRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,11 @@

namespace Geen.Data.Repositories;

public class ClubRepository : IClubRepository
public class ClubRepository(MongoContext context) : IClubRepository
{
private readonly MongoContext _context;

public ClubRepository(MongoContext context)
{
_context = context;
}

public async Task<ClubModel> GetById(int id)
{
var result = await _context.For<ClubEntity>()
var result = await context.For<ClubEntity>()
.Find(x => x.Id == id)
.FirstOrDefaultAsync();

Expand All @@ -30,7 +23,7 @@ public async Task<ClubModel> GetById(int id)

public async Task<ClubModel> GetByUrlName(string urlName)
{
var result = await _context.For<ClubEntity>()
var result = await context.For<ClubEntity>()
.Find(x => x.UrlName == urlName)
.FirstOrDefaultAsync();

Expand All @@ -39,7 +32,7 @@ public async Task<ClubModel> GetByUrlName(string urlName)

public async Task<List<ClubModel>> GetAll()
{
var result = await _context.For<ClubEntity>()
var result = await context.For<ClubEntity>()
.Find(x => true)
.ToListAsync();

Expand All @@ -53,7 +46,7 @@ public async Task<List<ClubModel>> GetAllUrls()
.Include(x => x.UrlName)
.Include(x => x.IsNational);

var result = await _context.For<ClubEntity>()
var result = await context.For<ClubEntity>()
.Find(x => true)
.Project<ClubEntity>(projection)
.ToListAsync();
Expand All @@ -67,7 +60,7 @@ public async Task<long> GetNextId()
.Projection
.Expression(x => (int?)x.Id);

var lastId = await _context.For<ClubEntity>()
var lastId = await context.For<ClubEntity>()
.Find(x => true)
.SortByDescending(x => x.Id)
.Project(projection)
Expand All @@ -85,7 +78,7 @@ public Task<List<DateTime>> GetBirthdays(string urlName)
.Projection
.Expression(x => x.BirthDate);

return _context.For<PlayerEntity>()
return context.For<PlayerEntity>()
.Find(x => x.Club.UrlName == urlName && x.Position != 4) //no coach
.Project(projection)
.ToListAsync();
Expand All @@ -95,7 +88,7 @@ public Task Save(ClubModel model)
{
var entity = model.Map<ClubEntity>();

return _context.For<ClubEntity>()
return context.For<ClubEntity>()
.ReplaceOneAsync(x => x.Id == model.Id, entity,
new ReplaceOptions { IsUpsert = true });
}
Expand All @@ -107,7 +100,7 @@ public async Task<List<ClubModel>> GetCached()
.Include(x => x.Name)
.Include(x => x.UrlName);

var result = await _context.For<ClubEntity>()
var result = await context.For<ClubEntity>()
.Find(x => true)
.Project<ClubEntity>(projection)
.ToListAsync();
Expand Down
19 changes: 6 additions & 13 deletions src/Backend/Geen.Data/Repositories/CountryRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,11 @@

namespace Geen.Data.Repositories;

public class CountryRepository : ICountryRepository
public class CountryRepository(MongoContext context) : ICountryRepository
{
private readonly MongoContext _context;

public CountryRepository(MongoContext context)
{
_context = context;
}

public async Task<CountryModel> GetById(int id)
{
var result = await _context.For<CountryEntity>()
var result = await context.For<CountryEntity>()
.Find(x => x.Id == id)
.FirstOrDefaultAsync();

Expand All @@ -29,7 +22,7 @@ public async Task<CountryModel> GetById(int id)

public async Task<CountryModel> GetByUrlName(string urlName)
{
var result = await _context.For<CountryEntity>()
var result = await context.For<CountryEntity>()
.Find(x => x.UrlName == urlName)
.FirstOrDefaultAsync();

Expand All @@ -38,7 +31,7 @@ public async Task<CountryModel> GetByUrlName(string urlName)

public async Task<List<CountryModel>> GetAll()
{
var result = await _context.For<CountryEntity>()
var result = await context.For<CountryEntity>()
.Find(x => true)
.ToListAsync();

Expand All @@ -49,7 +42,7 @@ public async Task<long> GetNextId()
{
var projection = Builders<CountryEntity>.Projection.Expression(x => (int?)x.Id);

var lastId = await _context.For<CountryEntity>()
var lastId = await context.For<CountryEntity>()
.Find(x => true)
.SortByDescending(x => x.Id)
.Project(projection)
Expand All @@ -65,7 +58,7 @@ public Task Save(CountryModel model)
{
var entity = model.Map<CountryEntity>();

return _context.For<CountryEntity>()
return context.For<CountryEntity>()
.ReplaceOneAsync(x => x.Id == model.Id, entity,
new ReplaceOptions { IsUpsert = true });
}
Expand Down
19 changes: 6 additions & 13 deletions src/Backend/Geen.Data/Repositories/LeagueRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,11 @@

namespace Geen.Data.Repositories;

public class LeagueRepository : ILeagueRepository
public class LeagueRepository(MongoContext context) : ILeagueRepository
{
private readonly MongoContext _context;

public LeagueRepository(MongoContext context)
{
_context = context;
}

public async Task<LeagueModel> GetById(int id)
{
var result = await _context.For<LeagueEntity>()
var result = await context.For<LeagueEntity>()
.Find(x => x.Id == id)
.FirstOrDefaultAsync();

Expand All @@ -29,7 +22,7 @@ public async Task<LeagueModel> GetById(int id)

public async Task<LeagueModel> GetByUrlName(string urlName)
{
var result = await _context.For<LeagueEntity>()
var result = await context.For<LeagueEntity>()
.Find(x => x.UrlName == urlName)
.FirstOrDefaultAsync();

Expand All @@ -38,7 +31,7 @@ public async Task<LeagueModel> GetByUrlName(string urlName)

public async Task<List<LeagueModel>> GetAll()
{
var result = await _context.For<LeagueEntity>()
var result = await context.For<LeagueEntity>()
.Find(x => true)
.ToListAsync();

Expand All @@ -49,7 +42,7 @@ public async Task<long> GetNextId()
{
var projection = Builders<LeagueEntity>.Projection.Expression(x => (int?)x.Id);

var lastId = await _context.For<LeagueEntity>()
var lastId = await context.For<LeagueEntity>()
.Find(x => true)
.SortByDescending(x => x.Id)
.Project(projection)
Expand All @@ -65,7 +58,7 @@ public Task Save(LeagueModel model)
{
var entity = model.Map<LeagueEntity>();

return _context.For<LeagueEntity>()
return context.For<LeagueEntity>()
.ReplaceOneAsync(x => x.Id == model.Id, entity,
new ReplaceOptions { IsUpsert = true });
}
Expand Down
Loading

0 comments on commit 816621a

Please sign in to comment.