-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathGuardianRequestsController.cs
More file actions
92 lines (87 loc) · 4.57 KB
/
GuardianRequestsController.cs
File metadata and controls
92 lines (87 loc) · 4.57 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// -----------------------------------------------------------------------
// Copyright (c) Signature Chess Club & MumsWhoCode. All rights reserved.
// -----------------------------------------------------------------------
using Microsoft.AspNetCore.Mvc;
using RESTFulSense.Controllers;
using SCMS.Services.Api.Models.Foundations.Guardians.Exceptions;
using SCMS.Services.Api.Models.Foundations.StudentGuardians.Exceptions;
using SCMS.Services.Api.Models.Foundations.Students.Exceptions;
using SCMS.Services.Api.Models.Orchestrations.StudentGuardianRequests.Exceptions;
using SCMS.Services.Api.Models.Processings.GuardianRequests;
using SCMS.Services.Api.Models.Processings.GuardianRequests.Exceptions;
using SCMS.Services.Api.Models.Processings.StudentGuardians.Exceptions;
using SCMS.Services.Api.Models.Processings.Students.Exceptions;
using SCMS.Services.Api.Services.Orchestrations.StudentGuardianRequests;
using System.Threading.Tasks;
namespace SCMS.Services.Api.Controllers
{
[ApiController]
[Route("api/[controller]")]
public class GuardianRequestsController : RESTFulController
{
private readonly IStudentGuardianRequestOrchestrationService studentGuardianRequestOrchestrationService;
public GuardianRequestsController(
IStudentGuardianRequestOrchestrationService studentGuardianRequestOrchestrationService) =>
this.studentGuardianRequestOrchestrationService = studentGuardianRequestOrchestrationService;
[HttpPost]
public async ValueTask<ActionResult<GuardianRequest>> PostGuardianRequest(GuardianRequest guardianRequest)
{
try
{
GuardianRequest addedGuardianRequest =
await this.studentGuardianRequestOrchestrationService
.AddStudentGuardianRequestAsync(guardianRequest);
return Created(addedGuardianRequest);
}
catch (StudentGuardianRequestOrchestrationValidationException validationException)
{
return BadRequest(validationException.InnerException);
}
catch (StudentGuardianRequestOrchestrationDependencyValidationException validationException)
when (validationException.InnerException
is InvalidStudentProcessingException
or InvalidStudentException
or NullGuardianRequestProcessingException
or InvalidGuardianRequestProcessingException
or NullGuardianException
or InvalidGuardianException
or NullStudentGuardianProcessingException
or InvalidStudentGuardianProcessingException
or NullStudentGuardianException
or InvalidStudentGuardianException)
{
return BadRequest(validationException.InnerException);
}
catch (StudentGuardianRequestOrchestrationDependencyValidationException validationException)
when (validationException.InnerException is NotFoundStudentProcessingException)
{
return NotFound(validationException.InnerException);
}
catch (StudentGuardianRequestOrchestrationDependencyValidationException validationException)
when (validationException.InnerException is AlreadyExistsPrimaryStudentGuardianProcessingException)
{
return Conflict(validationException.InnerException);
}
catch (StudentGuardianRequestOrchestrationDependencyValidationException validationException)
when (validationException.InnerException is AlreadyExistsGuardianException
or AlreadyExistsStudentGuardianException)
{
return Conflict(validationException.InnerException);
}
catch (StudentGuardianRequestOrchestrationDependencyValidationException validationException)
when (validationException.InnerException is InvalidGuardianReferenceException
or InvalidStudentGuardianReferenceException)
{
return FailedDependency(validationException.InnerException);
}
catch (StudentGuardianRequestOrchestrationDependencyException dependencyException)
{
return InternalServerError(dependencyException);
}
catch (StudentGuardianRequestOrchestrationServiceException serviceException)
{
return InternalServerError(serviceException);
}
}
}
}