You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
1.8 KiB
60 lines
1.8 KiB
2 years ago
|
using System.Threading.Tasks;
|
||
|
using Microsoft.AspNetCore.Authorization;
|
||
|
using Microsoft.AspNetCore.Mvc;
|
||
|
using Volo.Abp.Identity;
|
||
|
using Win_in.Sfs.Auth.Application.Contracts;
|
||
|
using Win_in.Sfs.Auth.Domain;
|
||
|
|
||
|
namespace Win_in.Sfs.Auth.Application;
|
||
|
|
||
|
[Authorize]
|
||
|
[Route($"{AuthConsts.RootPath}department")]
|
||
|
|
||
|
public class DepartmentAppService
|
||
|
: SfsBaseDataWithCodeAppServiceBase<Department, DepartmentDTO, SfsAuthRequestInputBase, DepartmentCreateInput>
|
||
|
, IDepartmentAppService
|
||
|
{
|
||
|
|
||
|
private readonly IdentityUserManager _identityUserManager;
|
||
|
private new readonly IDepartmentRepository _repository;
|
||
|
|
||
|
public DepartmentAppService(
|
||
|
IDepartmentRepository repository, IdentityUserManager identityUserManager
|
||
|
) : base(repository)
|
||
|
{
|
||
|
|
||
|
_repository = repository;
|
||
|
base.CreatePolicyName = DepartmentPermissions.Create;
|
||
|
base.UpdatePolicyName = DepartmentPermissions.Update;
|
||
|
base.DeletePolicyName = DepartmentPermissions.Delete;
|
||
|
_identityUserManager = identityUserManager;
|
||
|
}
|
||
|
|
||
|
[AllowAnonymous]
|
||
|
[HttpGet("by-username")]
|
||
|
public virtual async Task<DepartmentDTO> GetByUsernameAsync(string username)
|
||
|
{
|
||
|
var user = await _identityUserManager.FindByNameAsync(username).ConfigureAwait(false);
|
||
|
if (user == null)
|
||
|
{
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
var departmentCode = user.GetDepartmentCode();
|
||
|
if (string.IsNullOrEmpty(departmentCode))
|
||
|
{
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
var deptDto = await GetByCodeAsync(departmentCode).ConfigureAwait(false);
|
||
|
return deptDto;
|
||
|
}
|
||
|
[AllowAnonymous]
|
||
|
[HttpPost("update")]
|
||
|
public virtual async Task UpdateAsync(DepartmentCreateInput input)
|
||
|
{
|
||
|
var entity = ObjectMapper.Map<DepartmentCreateInput, Department>(input);
|
||
|
await _repository.UpdateAsync(entity).ConfigureAwait(false);
|
||
|
}
|
||
|
}
|