forked from Ed-Fi-Alliance-OSS/AdminAPI-1.x
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADMINAPI-1077] Add Get/Post endpoints for healthchecks (#177)
* Add Db Contexts * Add correct injection of context * Add GenericRepository * Add tenantId * Fix program.cs * Fix db provider issue * Fix mssql action * Fix github actions * Fix single tenant pg * Fix github actions * Update System.Text.Json nugget * Add not found exception Changed the way services were registered
- Loading branch information
1 parent
e3b33cd
commit 11f8519
Showing
41 changed files
with
1,222 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
Application/EdFi.Ods.AdminApi.AdminConsole/Features/Healthcheck/AddHealthCheck.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Licensed to the Ed-Fi Alliance under one or more agreements. | ||
// The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. | ||
// See the LICENSE and NOTICES files in the project root for more information. | ||
|
||
using System.ComponentModel.DataAnnotations; | ||
using EdFi.Ods.AdminApi.AdminConsole.Infrastructure.Services.HealthChecks.Commands; | ||
using FluentValidation; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Routing; | ||
using Newtonsoft.Json; | ||
using Swashbuckle.AspNetCore.Annotations; | ||
|
||
namespace EdFi.Ods.AdminApi.AdminConsole.Features.Healthcheck; | ||
internal class AddHealthCheck : IFeature | ||
{ | ||
public void MapEndpoints(IEndpointRouteBuilder endpoints) | ||
{ | ||
AdminApiAdminConsoleEndpointBuilder.MapPost(endpoints, "/healthcheck", Execute) | ||
.WithRouteOptions(b => b.WithResponseCode(201)) | ||
.BuildForVersions(); | ||
} | ||
|
||
public async Task<IResult> Execute(Validator validator, IAddHealthCheckCommand addHealthCheckCommand, AddHealthCheckRequest request) | ||
{ | ||
await validator.GuardAsync(request); | ||
var addedHealthCheck = await addHealthCheckCommand.Execute(request); | ||
return Results.Created($"/healthcheck/{addedHealthCheck.DocId}", null); | ||
} | ||
|
||
[SwaggerSchema(Title = nameof(AddHealthCheckRequest))] | ||
public class AddHealthCheckRequest : IAddHealthCheckModel | ||
{ | ||
[Required] | ||
public int DocId { get; set; } | ||
[Required] | ||
public int InstanceId { get; set; } | ||
[Required] | ||
public int EdOrgId { get; set; } | ||
[Required] | ||
public int TenantId { get; set; } | ||
[Required] | ||
public string Document { get; set; } | ||
} | ||
|
||
public class Validator : AbstractValidator<AddHealthCheckRequest> | ||
{ | ||
public Validator() | ||
{ | ||
RuleFor(m => m.InstanceId) | ||
.NotNull(); | ||
|
||
RuleFor(m => m.EdOrgId) | ||
.NotNull(); | ||
|
||
RuleFor(m => m.TenantId) | ||
.NotNull(); | ||
|
||
RuleFor(m => m.Document) | ||
.NotNull() | ||
.Must(BeValidDocument).WithMessage("Document must be a valid JSON."); | ||
} | ||
|
||
private bool BeValidDocument(string document) | ||
{ | ||
try | ||
{ | ||
Newtonsoft.Json.Linq.JToken.Parse(document); | ||
return true; | ||
} | ||
catch (Newtonsoft.Json.JsonReaderException) | ||
{ | ||
return false; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
Application/EdFi.Ods.AdminApi.AdminConsole/Features/IFeature.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Licensed to the Ed-Fi Alliance under one or more agreements. | ||
// The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. | ||
// See the LICENSE and NOTICES files in the project root for more information. | ||
|
||
using Microsoft.AspNetCore.Routing; | ||
|
||
namespace EdFi.Ods.AdminApi.AdminConsole.Features; | ||
|
||
public interface IFeature | ||
{ | ||
void MapEndpoints(IEndpointRouteBuilder endpoints); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
...on/EdFi.Ods.AdminApi.AdminConsole/Infrastructure/AutoMapper/AdminConsoleMappingProfile.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Licensed to the Ed-Fi Alliance under one or more agreements. | ||
// The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. | ||
// See the LICENSE and NOTICES files in the project root for more information. | ||
|
||
using AutoMapper; | ||
using EdFi.Ods.AdminApi.AdminConsole.Features.Healthcheck; | ||
using EdFi.Ods.AdminApi.AdminConsole.Infrastructure.DataAccess.Models; | ||
using Newtonsoft.Json; | ||
|
||
namespace EdFi.Ods.AdminApi.AdminConsole.Infrastructure.AutoMapper; | ||
|
||
public class AdminConsoleMappingProfile : Profile | ||
{ | ||
public AdminConsoleMappingProfile() | ||
{ | ||
CreateMap<HealthCheck, HealthCheckModel>().ConvertUsing(src => JsonConvert.DeserializeObject<HealthCheckModel>(src.Document)); | ||
|
||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
...onsole/Infrastructure/DataAccess/Artifacts/MsSql/20241030014056_InitialCreate.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.