36 lines
1.7 KiB
C#
36 lines
1.7 KiB
C#
namespace DocuMed.Repository.Repositories.Entities;
|
|
|
|
public class MedicalHistoryTemplateRepository(ApplicationContext dbContext, ICurrentUserService currentUserService)
|
|
: BaseRepository<MedicalHistoryTemplate>(dbContext, currentUserService), IMedicalHistoryTemplateRepository
|
|
{
|
|
public async Task<List<MedicalHistoryTemplateSDto>> GetMedicalHistoryTemplatesAsync(int page = 0, CancellationToken cancellationToken = default)
|
|
{
|
|
if (!Guid.TryParse(CurrentUserService.UserId, out Guid userId))
|
|
throw new AppException("توکن غیرمجاز", ApiResultStatusCode.UnAuthorized);
|
|
|
|
var student = await dbContext.Set<Student>()
|
|
.AsNoTracking()
|
|
.FirstOrDefaultAsync(f => f.UserId == userId, cancellationToken);
|
|
if (student == null)
|
|
throw new BaseApiException(ApiResultStatusCode.NotFound, "Student not found");
|
|
|
|
var list = await TableNoTracking
|
|
.Where(t => t.StudentId == student.Id)
|
|
.OrderByDescending(t => t.CreatedAt)
|
|
.Skip(page * 15)
|
|
.Take(15)
|
|
.Select(MedicalHistoryTemplateMapper.ProjectToSDto)
|
|
.ToListAsync(cancellationToken);
|
|
return list;
|
|
}
|
|
|
|
public async Task<MedicalHistoryTemplateLDto> GetMedicalHistoryTemplateAsync(Guid id, CancellationToken cancellationToken = default)
|
|
{
|
|
var dto = await TableNoTracking.Where(t => t.Id == id)
|
|
.Select(MedicalHistoryTemplateMapper.ProjectToLDto)
|
|
.FirstOrDefaultAsync(cancellationToken);
|
|
if (dto == null)
|
|
throw new AppException("پیش نویس پیدا نشد", ApiResultStatusCode.NotFound);
|
|
return dto;
|
|
}
|
|
} |