forked from Ed-Fi-Alliance-OSS/AdminAPI-2.x
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADMINAPI-1065] Add tenants endpoints (Ed-Fi-Alliance-OSS#179)
* Add Db Contexts * Add correct injection of context * Add GenericRepository * Add tenantId * Fix program.cs * Fix db provider issue * Tenants Endpoints * Add Db Contexts * Add correct injection of context * Add GenericRepository * Add tenantId * Tenants Endpoints * Resolve conflicts * get tenant changes * clean up and pgsql migration * change tenant endpoint name to tenants * change addTenant result creation url and delete tenant model --------- Co-authored-by: Danny Fernandez A <dfernandeza@growthaccelerationpartners.com>
- Loading branch information
1 parent
f2a3d5f
commit b80950b
Showing
16 changed files
with
683 additions
and
286 deletions.
There are no files selected for viewing
80 changes: 80 additions & 0 deletions
80
Application/EdFi.Ods.AdminApi.AdminConsole/Features/Tenants/AddTenant.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,80 @@ | ||
// 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; | ||
using System.Collections.Generic; | ||
using System.ComponentModel.DataAnnotations; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using EdFi.Ods.AdminApi.AdminConsole.Infrastructure.Services.Tenants.Commands; | ||
using FluentValidation; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Routing; | ||
using Swashbuckle.AspNetCore.Annotations; | ||
|
||
namespace EdFi.Ods.AdminApi.AdminConsole.Features.Tenants; | ||
internal class AddTenant : IFeature | ||
{ | ||
public void MapEndpoints(IEndpointRouteBuilder endpoints) | ||
{ | ||
AdminApiAdminConsoleEndpointBuilder.MapPost(endpoints, "/tenants", Execute) | ||
.WithRouteOptions(b => b.WithResponseCode(201)) | ||
.BuildForVersions(); | ||
} | ||
|
||
public async Task<IResult> Execute(Validator validator, IAddTenantCommand addTenantCommand, AddTenantRequest request) | ||
{ | ||
await validator.GuardAsync(request); | ||
var addedTenant = await addTenantCommand.Execute(request); | ||
return Results.Created($"/tenants/{addedTenant.TenantId}", null); | ||
} | ||
|
||
public class AddTenantRequest : IAddTenantModel | ||
{ | ||
[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; } | ||
} | ||
internal class Validator : AbstractValidator<AddTenantRequest> | ||
{ | ||
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
230 changes: 0 additions & 230 deletions
230
Application/EdFi.Ods.AdminApi.AdminConsole/Features/Tenants/TenantModel.cs
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.