-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add GetUser tests, add UserRepository, update GetUser method
- Loading branch information
Showing
16 changed files
with
235 additions
and
112 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
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,13 @@ | ||
using System.Linq.Expressions; | ||
using FocusAPI.Models; | ||
using FocusCore.Models; | ||
|
||
namespace FocusAPI.Repositories; | ||
public interface IUserRepository | ||
{ | ||
public Task<BaseUser?> GetBaseUserWithItemsByAuth0IdAsync( | ||
string? auth0Id, | ||
Expression<Func<User, bool>>[]? wherePredicates = null, | ||
CancellationToken cancellationToken = default | ||
); | ||
} |
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 System.Linq.Expressions; | ||
using FocusAPI.Data; | ||
using FocusAPI.Helpers; | ||
using FocusAPI.Models; | ||
using FocusCore.Models; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace FocusAPI.Repositories; | ||
public class UserRepository : IUserRepository | ||
{ | ||
private readonly FocusAPIContext _context; | ||
|
||
public UserRepository(FocusAPIContext context) | ||
{ | ||
_context = context; | ||
} | ||
|
||
public async Task<BaseUser?> GetBaseUserWithItemsByAuth0IdAsync( | ||
string? auth0Id, | ||
Expression<Func<User, bool>>[]? wherePredicates = null, | ||
CancellationToken cancellationToken = default | ||
) | ||
{ | ||
IQueryable<User> query = _context.Users.Where(u => u.Auth0Id == auth0Id); | ||
|
||
if (wherePredicates != null) | ||
{ | ||
foreach (var wherePredicate in wherePredicates) | ||
query = query.Where(wherePredicate); | ||
} | ||
|
||
query = query | ||
.Include(user => user.Islands) | ||
.Include(user => user.Pets) | ||
.Include(user => user.Decor) | ||
.Include(user => user.Badges); | ||
|
||
return await query.Select(user => ProjectionHelper.ProjectToBaseUser(user)).FirstOrDefaultAsync(cancellationToken); | ||
} | ||
} |
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,12 @@ | ||
using Bogus; | ||
using FocusCore.Models; | ||
|
||
namespace FocusAPI.Tests.Fakers; | ||
internal class BaseUserBadgeFaker : Faker<BaseUserBadge> | ||
{ | ||
internal BaseUserBadgeFaker(Guid? userId = null) | ||
{ | ||
RuleFor(userBadge => userBadge.UserId, f => userId ??= f.Random.Guid()); | ||
RuleFor(userBadge => userBadge.BadgeId, f => f.Random.Guid()); | ||
} | ||
} |
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,12 @@ | ||
using Bogus; | ||
using FocusCore.Models; | ||
|
||
namespace FocusAPI.Tests.Fakers; | ||
internal class BaseUserDecorFaker : Faker<BaseUserDecor> | ||
{ | ||
internal BaseUserDecorFaker(Guid? userId = null) | ||
{ | ||
RuleFor(userDecor => userDecor.UserId, f => userId ??= f.Random.Guid()); | ||
RuleFor(userDecor => userDecor.DecorId, f => f.Random.Guid()); | ||
} | ||
} |
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,25 @@ | ||
using Bogus; | ||
using FocusCore.Models; | ||
|
||
namespace FocusAPI.Tests.Fakers; | ||
internal class BaseUserFaker : Faker<BaseUser> | ||
{ | ||
internal BaseUserFaker() | ||
{ | ||
Guid userId = Guid.NewGuid(); | ||
RuleFor(user => user.Id, f => userId); | ||
RuleFor(user => user.Auth0Id, f => f.Random.Word()); | ||
|
||
BaseUserPetFaker userPetFaker = new(userId); | ||
RuleFor(user => user.Pets, f => userPetFaker.Generate(2)); | ||
|
||
BaseUserIslandFaker userIslandFaker = new(userId); | ||
RuleFor(user => user.Islands, f => userIslandFaker.Generate(2)); | ||
|
||
BaseUserDecorFaker userDecorFaker = new(userId); | ||
RuleFor(user => user.Decor, f => userDecorFaker.Generate(2)); | ||
|
||
BaseUserBadgeFaker userBadgeFaker = new(userId); | ||
RuleFor(user => user.Badges, f => userBadgeFaker.Generate(2)); | ||
} | ||
} |
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,13 @@ | ||
using Bogus; | ||
using FocusAPI.Models; | ||
using FocusCore.Models; | ||
|
||
namespace FocusAPI.Tests.Fakers; | ||
internal class BaseUserIslandFaker : Faker<BaseUserIsland> | ||
{ | ||
internal BaseUserIslandFaker(Guid? userId = null) | ||
{ | ||
RuleFor(userIsland => userIsland.UserId, f => userId ??= f.Random.Guid()); | ||
RuleFor(userIsland => userIsland.IslandId, f => f.Random.Guid()); | ||
} | ||
} |
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,12 @@ | ||
using Bogus; | ||
using FocusCore.Models; | ||
|
||
namespace FocusAPI.Tests.Fakers; | ||
internal class BaseUserPetFaker : Faker<BaseUserPet> | ||
{ | ||
internal BaseUserPetFaker(Guid? userId = null) | ||
{ | ||
RuleFor(userPet => userPet.UserId, f => userId ??= f.Random.Guid()); | ||
RuleFor(userPet => userPet.PetId, f => f.Random.Guid()); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.