Skip to content
This repository has been archived by the owner on Jun 25, 2022. It is now read-only.

Commit

Permalink
refactor(back-end): method overloads should be adjacent
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlosPavajeau committed Apr 29, 2021
1 parent a1e87f8 commit b8c6cea
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 26 deletions.
26 changes: 13 additions & 13 deletions Kaizen/Controllers/EmployeesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,19 @@ public async Task<ActionResult<IEnumerable<EmployeeChargeViewModel>>> EmployeeCh
return Ok(_mapper.Map<IEnumerable<EmployeeChargeViewModel>>(employeeCharges));
}

[HttpPost("[action]")]
[Authorize(Roles = "Administrator")]
public async Task<ActionResult<EmployeeChargeViewModel>> EmployeeCharges(
[FromBody] EmployeeChargeInputModel employeeChargeInputModel)
{
EmployeeCharge employeeCharge = _mapper.Map<EmployeeCharge>(employeeChargeInputModel);

_employeesRepository.Insert(employeeCharge);
await _unitWork.SaveAsync();

return _mapper.Map<EmployeeChargeViewModel>(employeeCharge);
}

[HttpGet("{id}")]
public async Task<ActionResult<EmployeeViewModel>> GetEmployee(string id)
{
Expand Down Expand Up @@ -168,19 +181,6 @@ public async Task<ActionResult<EmployeeViewModel>> PostEmployee(EmployeeInputMod
return _mapper.Map<EmployeeViewModel>(employee);
}

[HttpPost("[action]")]
[Authorize(Roles = "Administrator")]
public async Task<ActionResult<EmployeeChargeViewModel>> EmployeeCharges(
[FromBody] EmployeeChargeInputModel employeeChargeInputModel)
{
EmployeeCharge employeeCharge = _mapper.Map<EmployeeCharge>(employeeChargeInputModel);

_employeesRepository.Insert(employeeCharge);
await _unitWork.SaveAsync();

return _mapper.Map<EmployeeChargeViewModel>(employeeCharge);
}

private static string GetEmployeeRole(Employee employee)
{
return employee.EmployeeCharge.Id switch
Expand Down
27 changes: 14 additions & 13 deletions Kaizen/Controllers/ServicesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,20 @@ public async Task<ActionResult<IEnumerable<ServiceTypeViewModel>>> ServiceTypes(
return Ok(_mapper.Map<IEnumerable<ServiceTypeViewModel>>(serviceTypes));
}

[Authorize(Roles = "Administrator")]
[HttpPost("[action]")]
public async Task<ActionResult<ServiceTypeViewModel>> ServiceTypes(
[FromBody] ServiceTypeInputModel serviceTypeInputModel)
{
ServiceType serviceType = _mapper.Map<ServiceType>(serviceTypeInputModel);

_servicesRepository.Insert(serviceType);

await _unitWork.SaveAsync();

return _mapper.Map<ServiceTypeViewModel>(serviceType);
}

[HttpGet("[action]/{id}")]
[AllowAnonymous]
public async Task<bool> CheckExists(string id)
Expand Down Expand Up @@ -116,19 +130,6 @@ public async Task<ActionResult<ServiceViewModel>> PostService([FromBody] Service
return _mapper.Map<ServiceViewModel>(service);
}

[Authorize(Roles = "Administrator")]
[HttpPost("[action]")]
public async Task<ActionResult<ServiceTypeViewModel>> ServiceTypes([FromBody] ServiceTypeInputModel serviceTypeInputModel)
{
ServiceType serviceType = _mapper.Map<ServiceType>(serviceTypeInputModel);

_servicesRepository.Insert(serviceType);

await _unitWork.SaveAsync();

return _mapper.Map<ServiceTypeViewModel>(serviceType);
}

[Authorize(Roles = "Administrator")]
[HttpDelete("{id}")]
public async Task<ActionResult<ServiceViewModel>> DeleteService(string id)
Expand Down

0 comments on commit b8c6cea

Please sign in to comment.