128 lines
5.8 KiB
C#
128 lines
5.8 KiB
C#
using AMREZ.EOP.Abstractions.Applications.UseCases.HumanResources;
|
|
using AMREZ.EOP.Contracts.DTOs.HumanResources.EmergencyContactAdd;
|
|
using AMREZ.EOP.Contracts.DTOs.HumanResources.EmployeeAddressAdd;
|
|
using AMREZ.EOP.Contracts.DTOs.HumanResources.EmployeeBankAccountAdd;
|
|
using AMREZ.EOP.Contracts.DTOs.HumanResources.EmploymentAdd;
|
|
using AMREZ.EOP.Contracts.DTOs.HumanResources.EmploymentEnd;
|
|
using AMREZ.EOP.Contracts.DTOs.HumanResources.SetPrimaryAddress;
|
|
using AMREZ.EOP.Contracts.DTOs.HumanResources.SetPrimaryBankAccount;
|
|
using AMREZ.EOP.Contracts.DTOs.HumanResources.SetPrimaryEmergencyContact;
|
|
using AMREZ.EOP.Contracts.DTOs.HumanResources.UserProfileUpsert;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace AMREZ.EOP.API.Controllers;
|
|
|
|
[ApiController]
|
|
[Route("api/[controller]")]
|
|
public class HumanResourcesController : ControllerBase
|
|
{
|
|
private readonly IUpsertUserProfileUseCase _upsertProfile;
|
|
private readonly IAddEmploymentUseCase _addEmployment;
|
|
private readonly IEndEmploymentUseCase _endEmployment;
|
|
private readonly IAddEmployeeAddressUseCase _addAddress;
|
|
private readonly ISetPrimaryAddressUseCase _setPrimaryAddress;
|
|
private readonly IAddEmergencyContactUseCase _addEmergencyContact;
|
|
private readonly ISetPrimaryEmergencyContactUseCase _setPrimaryEmergencyContact;
|
|
private readonly IAddEmployeeBankAccountUseCase _addBankAccount;
|
|
private readonly ISetPrimaryBankAccountUseCase _setPrimaryBankAccount;
|
|
|
|
public HumanResourcesController(
|
|
IUpsertUserProfileUseCase upsertProfile,
|
|
IAddEmploymentUseCase addEmployment,
|
|
IEndEmploymentUseCase endEmployment,
|
|
IAddEmployeeAddressUseCase addAddress,
|
|
ISetPrimaryAddressUseCase setPrimaryAddress,
|
|
IAddEmergencyContactUseCase addEmergencyContact,
|
|
ISetPrimaryEmergencyContactUseCase setPrimaryEmergencyContact,
|
|
IAddEmployeeBankAccountUseCase addBankAccount,
|
|
ISetPrimaryBankAccountUseCase setPrimaryBankAccount)
|
|
{
|
|
_upsertProfile = upsertProfile;
|
|
_addEmployment = addEmployment;
|
|
_endEmployment = endEmployment;
|
|
_addAddress = addAddress;
|
|
_setPrimaryAddress = setPrimaryAddress;
|
|
_addEmergencyContact = addEmergencyContact;
|
|
_setPrimaryEmergencyContact = setPrimaryEmergencyContact;
|
|
_addBankAccount = addBankAccount;
|
|
_setPrimaryBankAccount = setPrimaryBankAccount;
|
|
}
|
|
|
|
// ===== User Profile =====
|
|
[HttpPost("profiles/upsert")]
|
|
public async Task<IActionResult> UpsertProfile([FromBody] UserProfileUpsertRequest body, CancellationToken ct)
|
|
{
|
|
var res = await _upsertProfile.ExecuteAsync(body, ct);
|
|
if (res is null) return BadRequest(new { message = "Upsert failed" });
|
|
return Ok(res);
|
|
}
|
|
|
|
// ===== Employment =====
|
|
[HttpPost("employments")]
|
|
public async Task<IActionResult> AddEmployment([FromBody] EmploymentAddRequest body, CancellationToken ct)
|
|
{
|
|
var res = await _addEmployment.ExecuteAsync(body, ct);
|
|
if (res is null) return BadRequest(new { message = "Add employment failed" });
|
|
return Created($"/api/humanresources/employments/{res.Id}", res);
|
|
}
|
|
|
|
[HttpPost("employments/{id:guid}/end")]
|
|
public async Task<IActionResult> EndEmployment([FromRoute] Guid id, [FromBody] EmploymentEndRequest body, CancellationToken ct)
|
|
{
|
|
if (id != body.EmploymentId) return BadRequest(new { message = "Mismatched id" });
|
|
var ok = await _endEmployment.ExecuteAsync(body, ct);
|
|
if (!ok) return NotFound(new { message = "Employment not found" });
|
|
return NoContent();
|
|
}
|
|
|
|
// ===== Addresses =====
|
|
[HttpPost("addresses")]
|
|
public async Task<IActionResult> AddAddress([FromBody] EmployeeAddressAddRequest body, CancellationToken ct)
|
|
{
|
|
var res = await _addAddress.ExecuteAsync(body, ct);
|
|
if (res is null) return BadRequest(new { message = "Add address failed" });
|
|
return Created($"/api/humanresources/addresses/{res.Id}", res);
|
|
}
|
|
|
|
[HttpPost("addresses/set-primary")]
|
|
public async Task<IActionResult> SetPrimaryAddress([FromBody] SetPrimaryAddressRequest body, CancellationToken ct)
|
|
{
|
|
var ok = await _setPrimaryAddress.ExecuteAsync(body, ct);
|
|
if (!ok) return NotFound(new { message = "Address not found" });
|
|
return NoContent();
|
|
}
|
|
|
|
// ===== Emergency Contacts =====
|
|
[HttpPost("emergency-contacts")]
|
|
public async Task<IActionResult> AddEmergencyContact([FromBody] EmergencyContactAddRequest body, CancellationToken ct)
|
|
{
|
|
var res = await _addEmergencyContact.ExecuteAsync(body, ct);
|
|
if (res is null) return BadRequest(new { message = "Add emergency contact failed" });
|
|
return Created($"/api/humanresources/emergency-contacts/{res.Id}", res);
|
|
}
|
|
|
|
[HttpPost("emergency-contacts/set-primary")]
|
|
public async Task<IActionResult> SetPrimaryEmergencyContact([FromBody] SetPrimaryEmergencyContactRequest body, CancellationToken ct)
|
|
{
|
|
var ok = await _setPrimaryEmergencyContact.ExecuteAsync(body, ct);
|
|
if (!ok) return NotFound(new { message = "Emergency contact not found" });
|
|
return NoContent();
|
|
}
|
|
|
|
// ===== Bank Accounts =====
|
|
[HttpPost("bank-accounts")]
|
|
public async Task<IActionResult> AddBankAccount([FromBody] EmployeeBankAccountAddRequest body, CancellationToken ct)
|
|
{
|
|
var res = await _addBankAccount.ExecuteAsync(body, ct);
|
|
if (res is null) return BadRequest(new { message = "Add bank account failed" });
|
|
return Created($"/api/humanresources/bank-accounts/{res.Id}", res);
|
|
}
|
|
|
|
[HttpPost("bank-accounts/set-primary")]
|
|
public async Task<IActionResult> SetPrimaryBankAccount([FromBody] SetPrimaryBankAccountRequest body, CancellationToken ct)
|
|
{
|
|
var ok = await _setPrimaryBankAccount.ExecuteAsync(body, ct);
|
|
if (!ok) return NotFound(new { message = "Bank account not found" });
|
|
return NoContent();
|
|
}
|
|
} |