fix api
This commit is contained in:
parent
6c09c68c5c
commit
1ae6f5e8d1
23 changed files with 304 additions and 123 deletions
|
|
@ -45,7 +45,7 @@ namespace BMA.EHR.Application.Repositories.Commands
|
|||
get
|
||||
{
|
||||
if (UserId != null || UserId != "")
|
||||
return _userProfileRepository.GetUserOCId(Guid.Parse(UserId!));
|
||||
return _userProfileRepository.GetUserOCId(Guid.Parse(UserId!), AccessToken);
|
||||
else
|
||||
return Guid.Empty;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ namespace BMA.EHR.Application.Repositories.Commands
|
|||
get
|
||||
{
|
||||
if (UserId != null || UserId != "")
|
||||
return _userProfileRepository.GetUserOCId(Guid.Parse(UserId!));
|
||||
return _userProfileRepository.GetUserOCId(Guid.Parse(UserId!), AccessToken);
|
||||
else
|
||||
return Guid.Empty;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -101,6 +101,27 @@ namespace BMA.EHR.Application.Repositories
|
|||
}
|
||||
}
|
||||
|
||||
protected async Task<bool> PostExternalAPIBooleanAsync(string apiPath, string accessToken, object? body)
|
||||
{
|
||||
try
|
||||
{
|
||||
var json = JsonConvert.SerializeObject(body);
|
||||
var stringContent = new StringContent(json, UnicodeEncoding.UTF8, "application/json");
|
||||
stringContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
|
||||
|
||||
using (var client = new HttpClient())
|
||||
{
|
||||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken.Replace("Bearer ", ""));
|
||||
var _res = await client.PostAsync(apiPath, stringContent);
|
||||
return _res.IsSuccessStatusCode;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public async Task<Guid> GetProfileOrganizationAsync(string citizenId)
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
|||
get
|
||||
{
|
||||
if (UserId != null || UserId != "")
|
||||
return _userProfileRepository.GetUserOCId(Guid.Parse(UserId!));
|
||||
return _userProfileRepository.GetUserOCId(Guid.Parse(UserId!), AccessToken);
|
||||
else
|
||||
return Guid.Empty;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
|||
get
|
||||
{
|
||||
if (UserId != null || UserId != "")
|
||||
return _userProfileRepository.GetUserOCId(Guid.Parse(UserId!));
|
||||
return _userProfileRepository.GetUserOCId(Guid.Parse(UserId!), AccessToken);
|
||||
else
|
||||
return Guid.Empty;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.TimeAttendants
|
|||
get
|
||||
{
|
||||
if (UserId != null || UserId != "")
|
||||
return _userProfileRepository.GetUserOCId(Guid.Parse(UserId!));
|
||||
return _userProfileRepository.GetUserOCId(Guid.Parse(UserId!), AccessToken);
|
||||
else
|
||||
return Guid.Empty;
|
||||
}
|
||||
|
|
@ -75,7 +75,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.TimeAttendants
|
|||
var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(userId, AccessToken ?? "");
|
||||
var profile_id = profile == null ? Guid.Empty : profile.Id;
|
||||
|
||||
var rootOc = _userProfileRepository.GetRootOcId(profile_id);
|
||||
var rootOc = _userProfileRepository.GetRootOcId(profile_id, AccessToken);
|
||||
var approver = string.Empty;
|
||||
var list = new List<OrganizationApproverResponse>();
|
||||
if (rootOc != null)
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.TimeAttendants
|
|||
get
|
||||
{
|
||||
if (UserId != null || UserId != "")
|
||||
return _userProfileRepository.GetUserOCId(Guid.Parse(UserId!));
|
||||
return _userProfileRepository.GetUserOCId(Guid.Parse(UserId!), AccessToken);
|
||||
else
|
||||
return Guid.Empty;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.TimeAttendants
|
|||
get
|
||||
{
|
||||
if (UserId != null || UserId != "")
|
||||
return _userProfileRepository.GetUserOCId(Guid.Parse(UserId!));
|
||||
return _userProfileRepository.GetUserOCId(Guid.Parse(UserId!), AccessToken);
|
||||
else
|
||||
return Guid.Empty;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.TimeAttendants
|
|||
get
|
||||
{
|
||||
if (UserId != null || UserId != "")
|
||||
return _userProfileRepository.GetUserOCId(Guid.Parse(UserId!));
|
||||
return _userProfileRepository.GetUserOCId(Guid.Parse(UserId!), AccessToken);
|
||||
else
|
||||
return Guid.Empty;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.TimeAttendants
|
|||
get
|
||||
{
|
||||
if (UserId != null || UserId != "")
|
||||
return _userProfileRepository.GetUserOCId(Guid.Parse(UserId!));
|
||||
return _userProfileRepository.GetUserOCId(Guid.Parse(UserId!), AccessToken);
|
||||
else
|
||||
return Guid.Empty;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.TimeAttendants
|
|||
get
|
||||
{
|
||||
if (UserId != null || UserId != "")
|
||||
return _userProfileRepository.GetUserOCId(Guid.Parse(UserId!));
|
||||
return _userProfileRepository.GetUserOCId(Guid.Parse(UserId!), AccessToken);
|
||||
else
|
||||
return Guid.Empty;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -92,31 +92,43 @@ namespace BMA.EHR.Application.Repositories
|
|||
}
|
||||
}
|
||||
|
||||
public async Task<bool> UpdateDutyTimeAsync(Guid profileId, Guid roundId, DateTime effectiveDate)
|
||||
public async Task<bool> UpdateDutyTimeAsync(Guid profileId, Guid roundId, DateTime effectiveDate, string? accessToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
var profile = await _dbContext.Set<Profile>()
|
||||
.AsQueryable()
|
||||
.Include(x => x.Prefix)
|
||||
.FirstOrDefaultAsync(x => x.Id == profileId);
|
||||
var apiPath = $"{_configuration["API"]}/org/dotnet/update-dutytime";
|
||||
|
||||
if (profile == null)
|
||||
var body = new
|
||||
{
|
||||
throw new Exception(GlobalMessages.DataNotFound);
|
||||
}
|
||||
else
|
||||
{
|
||||
var fullName = $"{profile.Prefix.Name}{profile.FirstName} {profile.LastName}";
|
||||
Console.WriteLine(fullName);
|
||||
EffevtiveDate = effectiveDate,
|
||||
RoundId = roundId,
|
||||
ProfileId = profileId
|
||||
};
|
||||
|
||||
profile.DutyTimeId = roundId;
|
||||
profile.DutyTimeEffectiveDate = effectiveDate;
|
||||
var apiResult = await PostExternalAPIBooleanAsync(apiPath, accessToken ?? "", body);
|
||||
|
||||
await UpdateAsync(profile);
|
||||
return apiResult;
|
||||
//var profile = await _dbContext.Set<Profile>()
|
||||
// .AsQueryable()
|
||||
// .Include(x => x.Prefix)
|
||||
// .FirstOrDefaultAsync(x => x.Id == profileId);
|
||||
|
||||
return true;
|
||||
}
|
||||
//if (profile == null)
|
||||
//{
|
||||
// throw new Exception(GlobalMessages.DataNotFound);
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// var fullName = $"{profile.Prefix.Name}{profile.FirstName} {profile.LastName}";
|
||||
// Console.WriteLine(fullName);
|
||||
|
||||
// profile.DutyTimeId = roundId;
|
||||
// profile.DutyTimeEffectiveDate = effectiveDate;
|
||||
|
||||
// await UpdateAsync(profile);
|
||||
|
||||
// return true;
|
||||
//}
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
|
@ -124,16 +136,21 @@ namespace BMA.EHR.Application.Repositories
|
|||
}
|
||||
}
|
||||
|
||||
public async Task<List<Profile>> GetProfileWithKeycloak()
|
||||
public async Task<List<GetProfileByKeycloakIdDto>> GetProfileWithKeycloak(string? accessToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
var data = await _dbContext.Set<Profile>().AsQueryable()
|
||||
.Where(x => x.ProfileType == "officer")
|
||||
.Where(x => x.KeycloakId != null)
|
||||
.ToListAsync();
|
||||
var apiPath = $"{_configuration["API"]}/org/dotnet/keycloak";
|
||||
|
||||
return data;
|
||||
var apiResult = await GetExternalAPIAsync(apiPath, accessToken ?? "");
|
||||
if (apiResult != null)
|
||||
{
|
||||
var raw = JsonConvert.DeserializeObject<GetListProfileByKeycloakIdResultDto>(apiResult);
|
||||
if (raw != null)
|
||||
return raw.Result;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
|
@ -193,28 +210,51 @@ namespace BMA.EHR.Application.Repositories
|
|||
}
|
||||
}
|
||||
|
||||
public async Task<List<Profile>> SearchProfileEmployee(string? citizenId, string? firstName, string? lastName)
|
||||
public async Task<List<SearchProfileDto>> SearchProfileEmployee(string? citizenId, string? firstName, string? lastName, string accessToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
var data = _dbContext.Set<Profile>().AsQueryable()
|
||||
.Where(x => x.ProfileType == "employee");
|
||||
var apiPath = $"{_configuration["API"]}/org/dotnet/search-employee";
|
||||
var body = new
|
||||
{
|
||||
citizenId = citizenId,
|
||||
firstName = firstName,
|
||||
lastName = lastName
|
||||
};
|
||||
|
||||
var profiles = new List<SearchProfileDto>();
|
||||
|
||||
var apiResult = await PostExternalAPIAsync(apiPath, accessToken, body);
|
||||
if (apiResult != null)
|
||||
{
|
||||
var raw = JsonConvert.DeserializeObject<SearchProfileResultDto>(apiResult);
|
||||
if (raw != null && raw.Result != null)
|
||||
{
|
||||
profiles.AddRange(raw.Result);
|
||||
}
|
||||
}
|
||||
|
||||
return profiles;
|
||||
|
||||
|
||||
if (citizenId != null)
|
||||
data = data.Where(x => x.CitizenId!.Contains(citizenId));
|
||||
|
||||
if (firstName != null)
|
||||
data = data.Where(x => x.FirstName!.Contains(firstName));
|
||||
|
||||
if (lastName != null)
|
||||
data = data.Where(x => x.LastName!.Contains(lastName));
|
||||
|
||||
data = data.Include(x => x.Prefix);
|
||||
//.Include(x => x.PosNoEmployee);
|
||||
//var data = _dbContext.Set<Profile>().AsQueryable()
|
||||
// .Where(x => x.ProfileType == "employee");
|
||||
|
||||
|
||||
return await data.ToListAsync();
|
||||
//if (citizenId != null)
|
||||
// data = data.Where(x => x.CitizenId!.Contains(citizenId));
|
||||
|
||||
//if (firstName != null)
|
||||
// data = data.Where(x => x.FirstName!.Contains(firstName));
|
||||
|
||||
//if (lastName != null)
|
||||
// data = data.Where(x => x.LastName!.Contains(lastName));
|
||||
|
||||
//data = data.Include(x => x.Prefix);
|
||||
////.Include(x => x.PosNoEmployee);
|
||||
|
||||
|
||||
//return await data.ToListAsync();
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
|
@ -222,17 +262,22 @@ namespace BMA.EHR.Application.Repositories
|
|||
}
|
||||
}
|
||||
|
||||
public string GetUserFullName(Guid keycloakId)
|
||||
public string GetUserFullName(Guid keycloakId, string? accessToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
var data = _dbContext.Set<Profile>().AsQueryable()
|
||||
.Include(x => x.Prefix)
|
||||
.Where(x => x.KeycloakId == keycloakId)
|
||||
.Select(x => $"{x.Prefix!.Name}{x.FirstName} {x.LastName}")
|
||||
.FirstOrDefault();
|
||||
var apiPath = $"{_configuration["API"]}/org/dotnet/keycloak";
|
||||
|
||||
var apiResult = GetExternalAPIAsync(apiPath, accessToken ?? "");
|
||||
if (apiResult.Result != null)
|
||||
{
|
||||
var raw = JsonConvert.DeserializeObject<GetUserFullNameResultDto>(apiResult.Result);
|
||||
if (raw != null)
|
||||
return raw.Result;
|
||||
}
|
||||
|
||||
return string.Empty;
|
||||
|
||||
return data ?? "-";
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
|
@ -240,21 +285,34 @@ namespace BMA.EHR.Application.Repositories
|
|||
}
|
||||
}
|
||||
|
||||
public Guid GetUserOCId(Guid keycloakId)
|
||||
public Guid GetUserOCId(Guid keycloakId, string? accessToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
var data = _dbContext.Set<ProfilePosition>()
|
||||
.Include(x => x.Profile)
|
||||
.Include(x => x.OrganizationPosition)
|
||||
.ThenInclude(x => x.Organization)
|
||||
.Where(x => x.Profile!.KeycloakId == keycloakId)
|
||||
.FirstOrDefault();
|
||||
|
||||
if (data == null)
|
||||
throw new Exception(GlobalMessages.DataNotFound);
|
||||
var apiPath = $"{_configuration["API"]}/org/dotnet/user-oc/{keycloakId}";
|
||||
|
||||
return data.OrganizationPosition!.Organization!.Id;
|
||||
var apiResult = GetExternalAPIAsync(apiPath, accessToken ?? "");
|
||||
if (apiResult.Result != null)
|
||||
{
|
||||
var raw = JsonConvert.DeserializeObject<GetUserOCIdResultDto>(apiResult.Result);
|
||||
if (raw != null)
|
||||
return raw.Result!.RootId;
|
||||
}
|
||||
|
||||
return Guid.Empty;
|
||||
|
||||
//var data = _dbContext.Set<ProfilePosition>()
|
||||
// .Include(x => x.Profile)
|
||||
// .Include(x => x.OrganizationPosition)
|
||||
// .ThenInclude(x => x.Organization)
|
||||
// .Where(x => x.Profile!.KeycloakId == keycloakId)
|
||||
// .FirstOrDefault();
|
||||
|
||||
//if (data == null)
|
||||
// throw new Exception(GlobalMessages.DataNotFound);
|
||||
|
||||
//return data.OrganizationPosition!.Organization!.Id;
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
|
@ -262,14 +320,26 @@ namespace BMA.EHR.Application.Repositories
|
|||
}
|
||||
}
|
||||
|
||||
public Guid? GetRootOcId(Guid ocId)
|
||||
public Guid? GetRootOcId(Guid ocId, string? accessToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
var data = _dbContext.Set<OrganizationEntity>()
|
||||
.FirstOrDefault(o => o.Id == ocId);
|
||||
var apiPath = $"{_configuration["API"]}/org/dotnet/root-oc/{ocId}";
|
||||
|
||||
return data == null ? Guid.Empty : data.OrganizationAgencyId;
|
||||
var apiResult = GetExternalAPIAsync(apiPath, accessToken ?? "");
|
||||
if (apiResult.Result != null)
|
||||
{
|
||||
var raw = JsonConvert.DeserializeObject<GetRootOCIdResultDto>(apiResult.Result);
|
||||
if (raw != null)
|
||||
return raw.Result;
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
//var data = _dbContext.Set<OrganizationEntity>()
|
||||
// .FirstOrDefault(o => o.Id == ocId);
|
||||
|
||||
//return data == null ? Guid.Empty : data.OrganizationAgencyId;
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,11 @@
|
|||
namespace BMA.EHR.Application.Responses.Profiles
|
||||
{
|
||||
public class GetListProfileByKeycloakIdResultDto
|
||||
{
|
||||
public string Message { get; set; } = string.Empty;
|
||||
|
||||
public int Status { get; set; } = -1;
|
||||
|
||||
public List<GetProfileByKeycloakIdDto> Result { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
|
@ -29,6 +29,12 @@ namespace BMA.EHR.Application.Responses.Profiles
|
|||
|
||||
public List<ProfileSalary> Salaries { get; set; } = new();
|
||||
|
||||
public Guid? Keycloak { get; set; }
|
||||
|
||||
public string? PosNo { get; set; }
|
||||
|
||||
public string? PosNoEmployee { get; set; }
|
||||
|
||||
}
|
||||
|
||||
public class PosLevel
|
||||
|
|
|
|||
|
|
@ -0,0 +1,11 @@
|
|||
namespace BMA.EHR.Application.Responses.Profiles
|
||||
{
|
||||
public class GetRootOCIdResultDto
|
||||
{
|
||||
public string Message { get; set; } = string.Empty;
|
||||
|
||||
public int Status { get; set; } = -1;
|
||||
|
||||
public Guid Result { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
namespace BMA.EHR.Application.Responses.Profiles
|
||||
{
|
||||
public class GetUserFullNameResultDto
|
||||
{
|
||||
public string Message { get; set; } = string.Empty;
|
||||
|
||||
public int Status { get; set; } = -1;
|
||||
|
||||
public string Result { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
29
BMA.EHR.Application/Responses/Profiles/GetUserOCIdDto.cs
Normal file
29
BMA.EHR.Application/Responses/Profiles/GetUserOCIdDto.cs
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
namespace BMA.EHR.Application.Responses.Profiles
|
||||
{
|
||||
public class GetUserOCIdDto
|
||||
{
|
||||
public Guid ProfileId { get; set; }
|
||||
|
||||
public string Prefix { get; set; } = string.Empty;
|
||||
|
||||
public string Rank { get; set; } = string.Empty;
|
||||
|
||||
public string Avatar { get; set; } = string.Empty;
|
||||
|
||||
public string FirstName { get; set; } = string.Empty;
|
||||
|
||||
public string LastName { get; set; } = string.Empty;
|
||||
|
||||
public string CitizenId { get; set; } = string.Empty;
|
||||
|
||||
public DateTime BirthDate { get; set; } = DateTime.MinValue;
|
||||
|
||||
public string Position { get; set; } = string.Empty;
|
||||
|
||||
public Guid RootId { get; set; }
|
||||
|
||||
public string Root { get; set; } = string.Empty;
|
||||
|
||||
public string RootShortName { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
namespace BMA.EHR.Application.Responses.Profiles
|
||||
{
|
||||
public class GetUserOCIdResultDto
|
||||
{
|
||||
public string Message { get; set; } = string.Empty;
|
||||
|
||||
public int Status { get; set; } = -1;
|
||||
|
||||
public GetUserOCIdDto? Result { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -8,5 +8,13 @@
|
|||
public string? FirstName { get; set; }
|
||||
public string? LastName { get; set; }
|
||||
public string? CitizenId { get; set; }
|
||||
|
||||
public Guid? Keycloak { get; set; }
|
||||
|
||||
public string? PosNoEmployee { get; set; }
|
||||
|
||||
public string? Oc { get; set; }
|
||||
|
||||
public string? PosNo { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue