-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathGuardiansController.cs
More file actions
57 lines (52 loc) · 2.32 KB
/
Copy pathGuardiansController.cs
File metadata and controls
57 lines (52 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// -----------------------------------------------------------------------
// Copyright (c) Signature Chess Club & MumsWhoCode. All rights reserved.
// -----------------------------------------------------------------------
using Microsoft.AspNetCore.Mvc;
using RESTFulSense.Controllers;
using SCMS.Services.Api.Models.Foundations.Guardians;
using SCMS.Services.Api.Models.Foundations.Guardians.Exceptions;
using SCMS.Services.Api.Services.Foundations.Guardians;
using System.Threading.Tasks;
namespace SCMS.Services.Api.Controllers
{
[ApiController]
[Route("api/[controller]")]
public class GuardiansController : RESTFulController
{
private readonly IGuardianService guardianService;
public GuardiansController(IGuardianService guardianService) =>
this.guardianService = guardianService;
[HttpPost]
public async ValueTask<ActionResult<Guardian>> PostGuardianAsync(Guardian guardian)
{
try
{
Guardian createdGuardian =
await this.guardianService.AddGuardianAsync(guardian);
return Created(createdGuardian);
}
catch (GuardianValidationException guardianValidationException)
{
return BadRequest(guardianValidationException.InnerException);
}
catch (GuardianDependencyException guardianDependencyException)
{
return InternalServerError(guardianDependencyException);
}
catch (GuardianDependencyValidationException guardianDependencyValidationException)
when (guardianDependencyValidationException.InnerException is AlreadyExistsGuardianException)
{
return Conflict(guardianDependencyValidationException.InnerException);
}
catch (GuardianDependencyValidationException guardianDependencyValidationException)
when (guardianDependencyValidationException.InnerException is InvalidGuardianReferenceException)
{
return FailedDependency(guardianDependencyValidationException.InnerException);
}
catch (GuardianServiceException guardianServiceException)
{
return InternalServerError(guardianServiceException);
}
}
}
}