@@ -53,7 +53,7 @@ public FacilityReportingPlansController(ILogger<FacilityReportingPlansController
5353 /// Get a paged list of facility reporting plans.
5454 /// </summary>
5555 [ ProducesResponseType ( StatusCodes . Status200OK , Type = typeof ( PagedFacilityReportingPlanDto ) ) ]
56- [ ProducesResponseType ( StatusCodes . Status400BadRequest ) ]
56+ [ ProducesResponseType ( StatusCodes . Status400BadRequest , Type = typeof ( ProblemDetails ) ) ]
5757 [ ProducesResponseType ( StatusCodes . Status500InternalServerError ) ]
5858 [ HttpGet ( Name = "GetFacilityReportingPlans" ) ]
5959 public Task < IActionResult > GetFacilityReportingPlans ( string ? sortBy , SortOrder ? sortOrder ,
@@ -66,7 +66,7 @@ public Task<IActionResult> GetFacilityReportingPlans(string? sortBy, SortOrder?
6666 /// period and reporting state.
6767 /// </summary>
6868 [ ProducesResponseType ( StatusCodes . Status200OK , Type = typeof ( PagedFacilityReportingPlanDto ) ) ]
69- [ ProducesResponseType ( StatusCodes . Status400BadRequest ) ]
69+ [ ProducesResponseType ( StatusCodes . Status400BadRequest , Type = typeof ( ProblemDetails ) ) ]
7070 [ ProducesResponseType ( StatusCodes . Status500InternalServerError ) ]
7171 [ HttpGet ( "search" , Name = "SearchFacilityReportingPlans" ) ]
7272 public async Task < IActionResult > SearchFacilityReportingPlans ( [ FromQuery ] FacilityReportingPlanSearchFilters filters ,
@@ -81,18 +81,18 @@ public async Task<IActionResult> SearchFacilityReportingPlans([FromQuery] Facili
8181 var periodError = ValidatePeriodFilters ( filters . Month , filters . Year ) ;
8282 if ( periodError is not null )
8383 {
84- return BadRequest ( periodError ) ;
84+ return BadRequestProblem ( periodError ) ;
8585 }
8686
8787 if ( sortBy is not null && ! SortableColumns . Contains ( sortBy ) )
8888 {
89- return BadRequest ( $ "Cannot sort by '{ sortBy } '.") ;
89+ return BadRequestProblem ( $ "Cannot sort by '{ sortBy } '.") ;
9090 }
9191
9292 var pagingError = ValidatePaging ( pageSize , pageNumber ) ;
9393 if ( pagingError is not null )
9494 {
95- return BadRequest ( pagingError ) ;
95+ return BadRequestProblem ( pagingError ) ;
9696 }
9797
9898 using Activity ? activity = ServiceActivitySource . Instance . StartActivity ( "Search Facility Reporting Plans" ) ;
@@ -109,7 +109,7 @@ public async Task<IActionResult> SearchFacilityReportingPlans([FromQuery] Facili
109109 /// reporting state.
110110 /// </summary>
111111 [ ProducesResponseType ( StatusCodes . Status200OK , Type = typeof ( List < FacilityReportingPlanModel > ) ) ]
112- [ ProducesResponseType ( StatusCodes . Status400BadRequest ) ]
112+ [ ProducesResponseType ( StatusCodes . Status400BadRequest , Type = typeof ( ProblemDetails ) ) ]
113113 [ ProducesResponseType ( StatusCodes . Status500InternalServerError ) ]
114114 [ HttpGet ( "facilities/{facilityId}" ) ]
115115 public async Task < IActionResult > GetFacilityReportingPlansForFacility ( string facilityId , int ? month , int ? year ,
@@ -120,7 +120,7 @@ public async Task<IActionResult> GetFacilityReportingPlansForFacility(string fac
120120 var periodError = ValidatePeriodFilters ( month , year ) ;
121121 if ( periodError is not null )
122122 {
123- return BadRequest ( periodError ) ;
123+ return BadRequestProblem ( periodError ) ;
124124 }
125125
126126 using Activity ? activity = ServiceActivitySource . Instance . StartActivity ( "Get Facility Reporting Plans For Facility" ) ;
@@ -134,7 +134,7 @@ public async Task<IActionResult> GetFacilityReportingPlansForFacility(string fac
134134 /// Gets a facility reporting plan by Id.
135135 /// </summary>
136136 [ ProducesResponseType ( StatusCodes . Status200OK , Type = typeof ( FacilityReportingPlanModel ) ) ]
137- [ ProducesResponseType ( StatusCodes . Status404NotFound ) ]
137+ [ ProducesResponseType ( StatusCodes . Status404NotFound , Type = typeof ( ProblemDetails ) ) ]
138138 [ ProducesResponseType ( StatusCodes . Status500InternalServerError ) ]
139139 [ HttpGet ( "{id}" ) ]
140140 public async Task < IActionResult > GetFacilityReportingPlan ( string id , CancellationToken cancellationToken )
@@ -145,7 +145,7 @@ public async Task<IActionResult> GetFacilityReportingPlan(string id, Cancellatio
145145
146146 if ( model == null )
147147 {
148- return NotFound ( ) ;
148+ return NotFoundProblem ( $ "Facility reporting plan with Id: { id } not found." ) ;
149149 }
150150
151151 return Ok ( model ) ;
@@ -155,8 +155,8 @@ public async Task<IActionResult> GetFacilityReportingPlan(string id, Cancellatio
155155 /// Creates a facility reporting plan.
156156 /// </summary>
157157 [ ProducesResponseType ( StatusCodes . Status201Created , Type = typeof ( FacilityReportingPlanModel ) ) ]
158- [ ProducesResponseType ( StatusCodes . Status400BadRequest ) ]
159- [ ProducesResponseType ( StatusCodes . Status409Conflict ) ]
158+ [ ProducesResponseType ( StatusCodes . Status400BadRequest , Type = typeof ( ProblemDetails ) ) ]
159+ [ ProducesResponseType ( StatusCodes . Status409Conflict , Type = typeof ( ProblemDetails ) ) ]
160160 [ ProducesResponseType ( StatusCodes . Status500InternalServerError ) ]
161161 [ HttpPost ]
162162 public async Task < IActionResult > CreateFacilityReportingPlan ( FacilityReportingPlanRequest request , CancellationToken cancellationToken )
@@ -169,11 +169,11 @@ public async Task<IActionResult> CreateFacilityReportingPlan(FacilityReportingPl
169169 }
170170 catch ( DuplicateReportingPlanException ex )
171171 {
172- return Conflict ( ex . Message ) ;
172+ return Problem ( ex . Message , statusCode : StatusCodes . Status409Conflict , title : "Conflict" ) ;
173173 }
174174 catch ( ReportingPlanValidationException ex )
175175 {
176- return BadRequest ( ex . Message ) ;
176+ return BadRequestProblem ( ex . Message ) ;
177177 }
178178 catch ( Exception ex )
179179 {
@@ -190,9 +190,9 @@ public async Task<IActionResult> CreateFacilityReportingPlan(FacilityReportingPl
190190 /// Updates a facility reporting plan.
191191 /// </summary>
192192 [ ProducesResponseType ( StatusCodes . Status202Accepted , Type = typeof ( FacilityReportingPlanModel ) ) ]
193- [ ProducesResponseType ( StatusCodes . Status400BadRequest ) ]
194- [ ProducesResponseType ( StatusCodes . Status404NotFound ) ]
195- [ ProducesResponseType ( StatusCodes . Status409Conflict ) ]
193+ [ ProducesResponseType ( StatusCodes . Status400BadRequest , Type = typeof ( ProblemDetails ) ) ]
194+ [ ProducesResponseType ( StatusCodes . Status404NotFound , Type = typeof ( ProblemDetails ) ) ]
195+ [ ProducesResponseType ( StatusCodes . Status409Conflict , Type = typeof ( ProblemDetails ) ) ]
196196 [ ProducesResponseType ( StatusCodes . Status500InternalServerError ) ]
197197 [ HttpPut ( "{id}" ) ]
198198 public async Task < IActionResult > UpdateFacilityReportingPlan ( string id , FacilityReportingPlanUpdateRequest request , CancellationToken cancellationToken )
@@ -203,12 +203,12 @@ public async Task<IActionResult> UpdateFacilityReportingPlan(string id, Facility
203203
204204 if ( string . IsNullOrWhiteSpace ( requestId ) )
205205 {
206- return BadRequest ( "Id is required in the request body." ) ;
206+ return BadRequestProblem ( "Id is required in the request body." ) ;
207207 }
208208
209209 if ( requestId != id )
210210 {
211- return BadRequest ( "Id in the URL must match the Id in the request body." ) ;
211+ return BadRequestProblem ( "Id in the URL must match the Id in the request body." ) ;
212212 }
213213
214214 try
@@ -217,15 +217,15 @@ public async Task<IActionResult> UpdateFacilityReportingPlan(string id, Facility
217217 }
218218 catch ( KeyNotFoundException ex )
219219 {
220- return NotFound ( ex . Message ) ;
220+ return NotFoundProblem ( ex . Message ) ;
221221 }
222222 catch ( DuplicateReportingPlanException ex )
223223 {
224- return Conflict ( ex . Message ) ;
224+ return Problem ( ex . Message , statusCode : StatusCodes . Status409Conflict , title : "Conflict" ) ;
225225 }
226226 catch ( ReportingPlanValidationException ex )
227227 {
228- return BadRequest ( ex . Message ) ;
228+ return BadRequestProblem ( ex . Message ) ;
229229 }
230230 catch ( Exception ex )
231231 {
@@ -265,7 +265,7 @@ public async Task<IActionResult> DeleteFacilityReportingPlans(CancellationToken
265265 /// Deletes a facility reporting plan.
266266 /// </summary>
267267 [ ProducesResponseType ( StatusCodes . Status204NoContent ) ]
268- [ ProducesResponseType ( StatusCodes . Status404NotFound ) ]
268+ [ ProducesResponseType ( StatusCodes . Status404NotFound , Type = typeof ( ProblemDetails ) ) ]
269269 [ ProducesResponseType ( StatusCodes . Status500InternalServerError ) ]
270270 [ HttpDelete ( "{id}" ) ]
271271 public async Task < IActionResult > DeleteFacilityReportingPlan ( string id , CancellationToken cancellationToken )
@@ -278,7 +278,7 @@ public async Task<IActionResult> DeleteFacilityReportingPlan(string id, Cancella
278278 }
279279 catch ( KeyNotFoundException ex )
280280 {
281- return NotFound ( ex . Message ) ;
281+ return NotFoundProblem ( ex . Message ) ;
282282 }
283283 catch ( Exception ex )
284284 {
@@ -293,7 +293,7 @@ public async Task<IActionResult> DeleteFacilityReportingPlan(string id, Cancella
293293 /// Deletes every reporting plan belonging to a facility.
294294 /// </summary>
295295 [ ProducesResponseType ( StatusCodes . Status204NoContent ) ]
296- [ ProducesResponseType ( StatusCodes . Status400BadRequest ) ]
296+ [ ProducesResponseType ( StatusCodes . Status400BadRequest , Type = typeof ( ProblemDetails ) ) ]
297297 [ ProducesResponseType ( StatusCodes . Status500InternalServerError ) ]
298298 [ HttpDelete ( "facilities/{facilityId}" ) ]
299299 public async Task < IActionResult > DeleteFacilityReportingPlansForFacility ( string facilityId , CancellationToken cancellationToken )
@@ -302,7 +302,7 @@ public async Task<IActionResult> DeleteFacilityReportingPlansForFacility(string
302302
303303 if ( facilityId is null )
304304 {
305- return BadRequest ( "FacilityId is required." ) ;
305+ return BadRequestProblem ( "FacilityId is required." ) ;
306306 }
307307
308308 try
@@ -357,6 +357,12 @@ public async Task<IActionResult> DeleteFacilityReportingPlansForFacility(string
357357 return null ;
358358 }
359359
360+ private ObjectResult BadRequestProblem ( string detail ) =>
361+ Problem ( detail , statusCode : StatusCodes . Status400BadRequest , title : "Bad Request" ) ;
362+
363+ private ObjectResult NotFoundProblem ( string detail ) =>
364+ Problem ( detail , statusCode : StatusCodes . Status404NotFound , title : "Not Found" ) ;
365+
360366 private static string ? NullIfBlank ( string ? value ) => string . IsNullOrWhiteSpace ( value ) ? null : value ;
361367
362368 private static FacilityReportingPlan ToEntity ( FacilityReportingPlanRequest request ) =>
0 commit comments