Commit 1ac4a103 authored by Almouhannad's avatar Almouhannad

(B) Add get doctor status by user id query

parent e406e0e8
using Application.Abstractions.CQRS.Queries;
using Domain.Repositories;
using Domain.Shared;
namespace Application.Doctors.Queries.GetStatusByUserId;
public class GetDoctorStatusByUserIdHandler : IQueryHandler<GetDoctorStatusByUserIdQuery, GetDoctorStatusByUserIdResponse>
{
#region CTOR DI
private readonly IUserRepository _userRepository;
public GetDoctorStatusByUserIdHandler(IUserRepository userRepository)
{
_userRepository = userRepository;
}
#endregion
public async Task<Result<GetDoctorStatusByUserIdResponse>> Handle(GetDoctorStatusByUserIdQuery request, CancellationToken cancellationToken)
{
#region 1. Fetch user
var doctorUserFromPersistenceResult = await _userRepository.GetDoctorUserByIdAsync(request.UserId);
if (doctorUserFromPersistenceResult.IsFailure)
return Result.Failure<GetDoctorStatusByUserIdResponse>(doctorUserFromPersistenceResult.Error);
var doctorUser = doctorUserFromPersistenceResult.Value;
#endregion
return Result.Success<GetDoctorStatusByUserIdResponse>(
GetDoctorStatusByUserIdResponse.GetResponse(doctorUser.Doctor));
}
}
using Application.Abstractions.CQRS.Queries;
namespace Application.Doctors.Queries.GetStatusByUserId;
public class GetDoctorStatusByUserIdQuery : IQuery<GetDoctorStatusByUserIdResponse>
{
public int UserId { get; set; }
}
using Domain.Entities.People.Doctors;
namespace Application.Doctors.Queries.GetStatusByUserId;
public class GetDoctorStatusByUserIdResponse
{
public string Status { get; set; } = null!;
public static GetDoctorStatusByUserIdResponse GetResponse(Doctor doctor)
{
return new GetDoctorStatusByUserIdResponse
{
Status = doctor.Status.Name
};
}
}
......@@ -164,7 +164,9 @@ public class UserRepository : Repositroy<User>, IUserRepository
.Where(doctorUser => doctorUser.Id == id)
.Include(doctorUser => doctorUser.User)
.Include(doctorUser => doctorUser.Doctor)
.ThenInclude(doctor => doctor.PersonalInfo);
.ThenInclude(doctor => doctor.PersonalInfo)
.Include(doctorUser => doctorUser.Doctor)
.ThenInclude(doctor => doctor.Status);
return await query.FirstAsync();
}
......
using Application.Doctors.Queries.GetAllDoctors;
using Application.Doctors.Queries.GetStatusByUserId;
using Application.Employees.Queries.GetAvailable;
using Domain.Entities.Identity.UserRoles;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Presentation.Controllers.Base;
......@@ -37,4 +40,15 @@ public class DoctorsController : ApiController
return HandleFailure(result);
return Ok(result.Value);
}
//[Authorize(Roles = Roles.DoctorName)]
[HttpGet("Status{id:int}")]
public async Task<IActionResult> GetStatusByUserId([FromRoute(Name = "id")] int userId)
{
GetDoctorStatusByUserIdQuery query = new GetDoctorStatusByUserIdQuery { UserId = userId };
var result = await _sender.Send(query);
if (result.IsFailure)
return HandleFailure(result);
return Ok(result.Value);
}
}
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