Commit fb8a91f1 authored by Almouhannad's avatar Almouhannad

(B) Add user repo

parent f3f4bf51
......@@ -5,4 +5,5 @@ namespace Domain.Errors;
public static class IdentityErrors
{
public static Error InvalidRole => new("Identity.InvalidRole", "Role specified for user is invalid");
public static Error NotFound => new("Identity.NotFound", "المستخدم غير مسجّل في النظام");
}
using Domain.Entities.Identity.Users;
using Domain.Repositories.Base;
using Domain.Shared;
namespace Domain.Repositories;
public interface IUserRepository : IRepository<User>
{
public Task<Result<User>> GetByUserNameFullAsync(string userName);
}
using Domain.Entities.Identity.Users;
using Persistence.Repositories.Specifications.Base;
using System.Linq.Expressions;
namespace Persistence.Repositories.Users;
public class FullUserSpecification : Specification<User>
{
public FullUserSpecification(Expression<Func<User, bool>>? criteria) : base(criteria)
{
AddInclude(user => user.Role);
}
}
using Domain.Entities.Identity.Users;
using Domain.Errors;
using Domain.Repositories;
using Domain.Shared;
using Microsoft.EntityFrameworkCore;
using Persistence.Context;
using Persistence.Repositories.Base;
namespace Persistence.Repositories.Users;
public class UserRepository : Repositroy<User>, IUserRepository
{
#region Ctor DI
public UserRepository(ClinicsDbContext context) : base(context)
{
}
#endregion
#region Create method
public override Task<Result<User>> CreateAsync(User entity)
{
_context.Entry(entity.Role).State = EntityState.Unchanged;
return base.CreateAsync(entity);
}
#endregion
#region Get by username
public async Task<Result<User>> GetByUserNameFullAsync(string userName)
{
var query = ApplySpecification(new FullUserSpecification(user => user.UserName == userName));
var result = await query.ToListAsync();
if (result.Count == 0)
{
return Result.Failure<User>(IdentityErrors.NotFound);
}
return result.First();
}
#endregion
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment