2
2
using System . Text . Json ;
3
3
using Microsoft . AspNetCore . Mvc ;
4
4
using Microsoft . Extensions . Logging ;
5
+ using Swashbuckle . AspNetCore . Annotations ;
5
6
using TramsDataApi . RequestModels ;
6
7
using TramsDataApi . ResponseModels ;
7
8
using TramsDataApi . UseCases ;
8
9
9
10
namespace TramsDataApi . Controllers
10
11
{
12
+ /// <summary>
13
+ /// Manages establishment-related operations.
14
+ /// </summary>
11
15
[ ApiController ]
12
16
[ ApiVersion ( "1.0" ) ]
17
+ [ SwaggerTag ( "Establishment Endpoints" ) ]
13
18
public class EstablishmentsController : ControllerBase
14
19
{
15
20
private readonly IGetEstablishmentByUkprn _getEstablishmentByUkprn ;
@@ -35,8 +40,16 @@ public EstablishmentsController(
35
40
_logger = logger ;
36
41
}
37
42
43
+ /// <summary>
44
+ /// Retrieves an establishment by its UKPRN.
45
+ /// </summary>
46
+ /// <param name="ukprn">The UKPRN of the establishment.</param>
47
+ /// <returns>An establishment or NotFound if not available.</returns>
38
48
[ HttpGet ]
39
49
[ Route ( "establishment/{ukprn}" ) ]
50
+ [ SwaggerOperation ( Summary = "Get Establishment by UKPRN" , Description = "Returns an establishment specified by UKPRN." ) ]
51
+ [ SwaggerResponse ( 200 , "Successfully found and returned the establishment." ) ]
52
+ [ SwaggerResponse ( 404 , "Establishment with specified UKPRN not found." ) ]
40
53
public ActionResult < EstablishmentResponse > GetByUkprn ( string ukprn )
41
54
{
42
55
_logger . LogInformation ( $ "Attempting to get Establishment by UKPRN { ukprn } ") ;
@@ -51,8 +64,16 @@ public ActionResult<EstablishmentResponse> GetByUkprn(string ukprn)
51
64
_logger . LogDebug ( JsonSerializer . Serialize < EstablishmentResponse > ( establishment ) ) ;
52
65
return Ok ( establishment ) ;
53
66
}
67
+ /// <summary>
68
+ /// Retrieves a list of establishment URNs by region.
69
+ /// </summary>
70
+ /// <param name="regions">Array of regions.</param>
71
+ /// <returns>List of establishment URNs or NotFound if none are available.</returns>
54
72
[ HttpGet ]
55
73
[ Route ( "establishment/regions" ) ]
74
+ [ SwaggerOperation ( Summary = "Get Establishment URNs by Region" , Description = "Returns a list of establishment URNs by specified regions." ) ]
75
+ [ SwaggerResponse ( 200 , "Successfully found and returned the establishment URNs." ) ]
76
+ [ SwaggerResponse ( 404 , "No establishments found for specified regions." ) ]
56
77
public ActionResult < IEnumerable < int > > GetURNsByRegion ( [ FromQuery ] string [ ] regions )
57
78
{
58
79
_logger . LogInformation ( $ "Attempting to get Establishment URNs by Region { regions } ") ;
@@ -68,8 +89,16 @@ public ActionResult<IEnumerable<int>> GetURNsByRegion([FromQuery] string[] regio
68
89
return Ok ( establishment ) ;
69
90
}
70
91
92
+ /// <summary>
93
+ /// Retrieves an establishment by its URN.
94
+ /// </summary>
95
+ /// <param name="urn">The URN of the establishment.</param>
96
+ /// <returns>An establishment or NotFound if not available.</returns>
71
97
[ HttpGet ]
72
98
[ Route ( "establishment/urn/{urn}" ) ]
99
+ [ SwaggerOperation ( Summary = "Get Establishment by URN" , Description = "Returns an establishment specified by URN." ) ]
100
+ [ SwaggerResponse ( 200 , "Successfully found and returned the establishment." ) ]
101
+ [ SwaggerResponse ( 404 , "Establishment with specified URN not found." ) ]
73
102
public ActionResult < EstablishmentResponse > GetByUrn ( int urn )
74
103
{
75
104
var establishment = _getEstablishmentByUrn . Execute ( new GetEstablishmentByUrnRequest { URN = urn } ) ;
@@ -85,8 +114,15 @@ public ActionResult<EstablishmentResponse> GetByUrn(int urn)
85
114
return Ok ( establishment ) ;
86
115
}
87
116
117
+ /// <summary>
118
+ /// Searches for establishments based on a query.
119
+ /// </summary>
120
+ /// <param name="request">Search criteria.</param>
121
+ /// <returns>List of establishments that meet the search criteria.</returns>
88
122
[ HttpGet ]
89
123
[ Route ( "establishments" ) ]
124
+ [ SwaggerOperation ( Summary = "Search for Establishments" , Description = "Returns a list of establishments based on search criteria." ) ]
125
+ [ SwaggerResponse ( 200 , "Successfully executed the search and returned establishments." ) ]
90
126
public ActionResult < List < EstablishmentSummaryResponse > > SearchEstablishments ( [ FromQuery ] SearchEstablishmentsRequest request )
91
127
{
92
128
_logger . LogInformation ( $ "Searching for Establishments") ;
@@ -95,8 +131,16 @@ public ActionResult<List<EstablishmentSummaryResponse>> SearchEstablishments([Fr
95
131
return Ok ( establishments ) ;
96
132
}
97
133
134
+ /// <summary>
135
+ /// Retrieves a list of establishments by their URNs.
136
+ /// </summary>
137
+ /// <param name="request">Contains URNs of the establishments.</param>
138
+ /// <returns>List of establishments or NotFound if none are available.</returns>
98
139
[ HttpGet ]
99
140
[ Route ( "establishments/bulk" ) ]
141
+ [ SwaggerOperation ( Summary = "Get Establishments by URNs" , Description = "Returns a list of establishments specified by URNs." ) ]
142
+ [ SwaggerResponse ( 200 , "Successfully found and returned the establishments." ) ]
143
+ [ SwaggerResponse ( 404 , "Establishments with specified URNs not found." ) ]
100
144
public ActionResult < List < EstablishmentResponse > > GetByUrns ( [ FromQuery ] GetEstablishmentsByUrnsRequest request )
101
145
{
102
146
var commaSeparatedRequestUrns = string . Join ( "," , request . Urns ) ;
0 commit comments