-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGetSiteFunction.cs
More file actions
58 lines (54 loc) · 2.74 KB
/
GetSiteFunction.cs
File metadata and controls
58 lines (54 loc) · 2.74 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
using System.Collections.Generic;
using System.Net;
using System.Threading.Tasks;
using FluentValidation;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Attributes;
using Microsoft.Extensions.Logging;
using Microsoft.OpenApi.Models;
using Nhs.Appointments.Api.Auth;
using Nhs.Appointments.Api.Models;
using Nhs.Appointments.Core.Inspectors;
using Nhs.Appointments.Core.Sites;
using Nhs.Appointments.Core.Users;
namespace Nhs.Appointments.Api.Functions.HttpFunctions;
public class GetSiteFunction(
ISiteService siteService,
IValidator<SiteBasedResourceRequest> validator,
IUserContextProvider userContextProvider,
ILogger<GetSiteFunction> logger,
IMetricsRecorder metricsRecorder)
: SiteBasedResourceFunction<Site>(validator, userContextProvider, logger, metricsRecorder)
{
[OpenApiOperation(operationId: "GetSite", tags: ["Sites"], Summary = "Get single site by Id")]
[OpenApiParameter("site", In = ParameterLocation.Path, Required = true, Type = typeof(string),
Description = "The id of the site to retrieve")]
[OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, "application/json", typeof(Site),
Description = "Information for a single site")]
[OpenApiResponseWithBody(statusCode: HttpStatusCode.BadRequest, "application/json",
typeof(IEnumerable<ErrorMessageResponseItem>), Description = "The body of the request is invalid")]
[OpenApiResponseWithBody(statusCode: HttpStatusCode.NotFound, "application/json", typeof(ApiResult<object>),
Description = "Site not found or site has been soft deleted")]
[OpenApiResponseWithBody(statusCode: HttpStatusCode.Unauthorized, "application/json",
typeof(ErrorMessageResponseItem), Description = "Unauthorized request to a protected API")]
[OpenApiResponseWithBody(statusCode: HttpStatusCode.Forbidden, "application/json", typeof(ErrorMessageResponseItem),
Description = "Request failed due to insufficient permissions")]
[RequiresPermission(Permissions.ViewSite, typeof(SiteFromPathInspector))]
[Function("GetSiteFunction")]
public override Task<IActionResult> RunAsync(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "sites/{site}")] HttpRequest req)
{
return base.RunAsync(req);
}
protected override async Task<ApiResult<Site>> HandleRequest(SiteBasedResourceRequest request, ILogger logger)
{
var site = await siteService.GetSiteByIdAsync(request.Site, request.IgnoreCache, request.Scope);
if (site != null)
{
return ApiResult<Site>.Success(site);
}
return Failed(HttpStatusCode.NotFound, "The specified site was not found.");
}
}