-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathSchoolsController.cs
More file actions
80 lines (73 loc) · 2.93 KB
/
SchoolsController.cs
File metadata and controls
80 lines (73 loc) · 2.93 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
// -----------------------------------------------------------------------
// Copyright (c) Signature Chess Club & MumsWhoCode. All rights reserved.
// -----------------------------------------------------------------------
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.OData.Query;
using RESTFulSense.Controllers;
using SCMS.Services.Api.Models.Foundations.Schools;
using SCMS.Services.Api.Models.Foundations.Schools.Exceptions;
using SCMS.Services.Api.Services.Foundations.Schools;
using System.Linq;
using System.Threading.Tasks;
namespace SCMS.Services.Api.Controllers
{
[ApiController]
[Route("api/[controller]")]
public class SchoolsController : RESTFulController
{
private readonly ISchoolService schoolService;
public SchoolsController(ISchoolService schoolService) =>
this.schoolService = schoolService;
[HttpPost]
public async ValueTask<ActionResult<School>> PostSchoolAsync(School school)
{
try
{
School createdSchool =
await this.schoolService.AddSchoolAsync(school);
return Created(createdSchool);
}
catch (SchoolValidationException schoolValidationException)
{
return BadRequest(schoolValidationException.InnerException);
}
catch (SchoolDependencyException schoolDependencyException)
{
return InternalServerError(schoolDependencyException);
}
catch (SchoolDependencyValidationException schoolDependencyValidationException)
when (schoolDependencyValidationException.InnerException is AlreadyExistsSchoolException)
{
return Conflict(schoolDependencyValidationException.InnerException);
}
catch (SchoolDependencyValidationException schoolDependencyValidationException)
when (schoolDependencyValidationException.InnerException is InvalidSchoolReferenceException)
{
return FailedDependency(schoolDependencyValidationException.InnerException);
}
catch (SchoolServiceException schoolServiceException)
{
return InternalServerError(schoolServiceException);
}
}
[HttpGet]
[EnableQuery]
public ActionResult<IQueryable<School>> GetAllSchools()
{
try
{
IQueryable<School> schools =
this.schoolService.RetrieveAllSchools();
return Ok(schools);
}
catch (SchoolDependencyException schoolDependencyException)
{
return InternalServerError(schoolDependencyException);
}
catch (SchoolServiceException schoolServiceException)
{
return InternalServerError(schoolServiceException);
}
}
}
}