From b3c9f7239f5b0d171f0440575fe13595f6d77a7d Mon Sep 17 00:00:00 2001 From: Alexander Preibisch Date: Sun, 1 Dec 2024 09:26:35 +0100 Subject: [PATCH] Update/Fix API --- OpenBudgeteer.API/ConfigureSwaggerOptions.cs | 8 +- OpenBudgeteer.API/Program.cs | 185 +++++++++++++------ 2 files changed, 128 insertions(+), 65 deletions(-) diff --git a/OpenBudgeteer.API/ConfigureSwaggerOptions.cs b/OpenBudgeteer.API/ConfigureSwaggerOptions.cs index afb0b05..f76a338 100644 --- a/OpenBudgeteer.API/ConfigureSwaggerOptions.cs +++ b/OpenBudgeteer.API/ConfigureSwaggerOptions.cs @@ -35,13 +35,13 @@ public void Configure( SwaggerGenOptions options ) private static OpenApiInfo CreateInfoForApiVersion( ApiVersionDescription description ) { - var text = new StringBuilder( "An example application with OpenAPI, Swashbuckle, and API versioning." ); + var text = new StringBuilder( "Documention of OpenBudgeteer API mainly interacting with the Database." ); var info = new OpenApiInfo() { - Title = "Example API", + Title = "OpenBudgeteer API", Version = description.ApiVersion.ToString(), - Contact = new OpenApiContact() { Name = "Bill Mei", Email = "bill.mei@somewhere.com" }, - License = new OpenApiLicense() { Name = "MIT", Url = new Uri( "https://opensource.org/licenses/MIT" ) } + Contact = new OpenApiContact() { Name = "Alexander Preibisch", Email = "alexpreib@outlook.com" }, + License = new OpenApiLicense() { Name = "MIT", Url = new Uri( "https://github.com/TheAxelander/OpenBudgeteer/blob/master/LICENSE" ) } }; if ( description.IsDeprecated ) diff --git a/OpenBudgeteer.API/Program.cs b/OpenBudgeteer.API/Program.cs index 8678788..6757138 100644 --- a/OpenBudgeteer.API/Program.cs +++ b/OpenBudgeteer.API/Program.cs @@ -38,6 +38,7 @@ var versionSet = app.NewApiVersionSet() .HasApiVersion(1, 0) + .HasApiVersion(1, 1) // reporting api versions will return the headers // "api-supported-versions" and "api-deprecated-versions" .ReportApiVersions() @@ -52,27 +53,34 @@ // GET account.MapGet("{id:guid}", (Guid id) => accountService.Get(id)) - .MapToApiVersion(1,0); + .MapToApiVersion(1,0) + .MapToApiVersion(1,1); account.MapGet("/", () => accountService.GetAll()) - .MapToApiVersion(1,0); + .MapToApiVersion(1,0) + .MapToApiVersion(1,1); account.MapGet("/activeAccounts", () => accountService.GetActiveAccounts()) - .MapToApiVersion(1,0); + .MapToApiVersion(1,0) + .MapToApiVersion(1,1); // POST account.MapPost( "/", (Account entity) => accountService.Create(entity)) .Accepts("application/json") - .MapToApiVersion(1,0); + .MapToApiVersion(1,0) + .MapToApiVersion(1,1); // PATCH account.MapPatch( "/", (Account entity) => accountService.Update(entity)) .Accepts("application/json") - .MapToApiVersion(1,0); + .MapToApiVersion(1,0) + .MapToApiVersion(1,1); // DELETE account.MapDelete( "/{id:guid}", (Guid id) => accountService.Delete(id)) - .MapToApiVersion(1,0); + .MapToApiVersion(1,0) + .MapToApiVersion(1,1); account.MapDelete( "/close/{id:guid}", (Guid id) => accountService.CloseAccount(id)) - .MapToApiVersion(1,0); + .MapToApiVersion(1,0) + .MapToApiVersion(1,1); #endregion @@ -84,38 +92,47 @@ // GET transaction.MapGet("{id:guid}", (Guid id) => bankTransactionService.Get(id)) - .MapToApiVersion(1,0); + .MapToApiVersion(1,0) + .MapToApiVersion(1,1); transaction.MapGet("/", (DateTime? start, DateTime? end, int? limit) => bankTransactionService.GetAll(start, end, limit ?? 0)) - .MapToApiVersion(1,0); + .MapToApiVersion(1,0) + .MapToApiVersion(1,1); transaction.MapGet("/fromAccount/{id:guid}", (Guid id, DateTime? start, DateTime? end, int? limit) => bankTransactionService.GetFromAccount(id, start, end, limit ?? 0)) - .MapToApiVersion(1,0); + .MapToApiVersion(1,0) + .MapToApiVersion(1,1); transaction.MapGet( "/withEntities/{id:guid}", (Guid id) => bankTransactionService.GetWithEntities(id)) - .MapToApiVersion(1,0); + .MapToApiVersion(1,0) + .MapToApiVersion(1,1); // POST transaction.MapPost( "/", (BankTransaction entity) => bankTransactionService.Create(entity)) .Accepts("application/json") - .MapToApiVersion(1,0); + .MapToApiVersion(1,0) + .MapToApiVersion(1,1); transaction.MapPost( "/withBucket", (BankTransaction entity) => bankTransactionService.Create(entity)) .Accepts("application/json") - .MapToApiVersion(1,0); + .MapToApiVersion(1,0) + .MapToApiVersion(1,1); // PATCH transaction.MapPatch( "/", (BankTransaction entity) => bankTransactionService.Update(entity)) .Accepts("application/json") - .MapToApiVersion(1,0); + .MapToApiVersion(1,0) + .MapToApiVersion(1,1); transaction.MapPatch( "/withBucket", (BankTransaction entity) => bankTransactionService.Update(entity)) .Accepts("application/json") - .MapToApiVersion(1,0); + .MapToApiVersion(1,0) + .MapToApiVersion(1,1); // DELETE transaction.MapDelete( "/{id:guid}", (Guid id) => bankTransactionService.Delete(id)) - .MapToApiVersion(1,0); + .MapToApiVersion(1,0) + .MapToApiVersion(1,1); #endregion @@ -127,32 +144,40 @@ // GET recurring.MapGet("{id:guid}", (Guid id) => recurringTransactionService.Get(id)) - .MapToApiVersion(1,0); + .MapToApiVersion(1,0) + .MapToApiVersion(1,1); recurring.MapGet("/", () => recurringTransactionService.GetAllWithEntities()) - .MapToApiVersion(1,0); + .MapToApiVersion(1,0) + .MapToApiVersion(1,1); recurring.MapGet( "/withEntities/{id:guid}", (Guid id) => recurringTransactionService.GetWithEntities(id)) - .MapToApiVersion(1,0); + .MapToApiVersion(1,0) + .MapToApiVersion(1,1); recurring.MapGet("/pendingTransactions", async (DateTime yearMonth) => await recurringTransactionService.GetPendingBankTransactionAsync(yearMonth)) - .MapToApiVersion(1,0); + .MapToApiVersion(1,0) + .MapToApiVersion(1,1); // POST recurring.MapPost( "/", (RecurringBankTransaction entity) => recurringTransactionService.Create(entity)) .Accepts("application/json") - .MapToApiVersion(1,0); + .MapToApiVersion(1,0) + .MapToApiVersion(1,1); recurring.MapPost("/pendingTransactions", async (DateTime yearMonth) => await recurringTransactionService.CreatePendingBankTransactionAsync(yearMonth)) - .MapToApiVersion(1,0); + .MapToApiVersion(1,0) + .MapToApiVersion(1,1); // PATCH recurring.MapPatch( "/", (RecurringBankTransaction entity) => recurringTransactionService.Update(entity)) .Accepts("application/json") - .MapToApiVersion(1,0); + .MapToApiVersion(1,0) + .MapToApiVersion(1,1); // DELETE recurring.MapDelete( "/{id:guid}", (Guid id) => recurringTransactionService.Delete(id)) - .MapToApiVersion(1,0); + .MapToApiVersion(1,0) + .MapToApiVersion(1,1); #endregion @@ -164,43 +189,58 @@ await recurringTransactionService.CreatePendingBankTransactionAsync(yearMonth)) // GET bucket.MapGet("{id:guid}", (Guid id) => bucketService.Get(id)) - .MapToApiVersion(1,0); + .MapToApiVersion(1,0) + .MapToApiVersion(1,1); bucket.MapGet("/withLatestVersion/{id:guid}", (Guid id) => bucketService.GetWithLatestVersion(id)) - .MapToApiVersion(1,0); -bucket.MapGet("/", () => bucketService.GetAllWithoutSystemBuckets()) - .MapToApiVersion(1,0); + .MapToApiVersion(1,0) + .MapToApiVersion(1,1); +bucket.MapGet("/", () => bucketService.GetAll()) + .MapToApiVersion(1,0) + .MapToApiVersion(1,1); +bucket.MapGet("/withoutSystemBuckets", () => bucketService.GetAllWithoutSystemBuckets()) + .MapToApiVersion(1,1); bucket.MapGet("/systemBuckets", () => bucketService.GetSystemBuckets()) - .MapToApiVersion(1,0); + .MapToApiVersion(1,0) + .MapToApiVersion(1,1); bucket.MapGet("/activeBuckets", (DateTime? validFrom) => bucketService.GetActiveBuckets(validFrom ?? DateTime.Now)) - .MapToApiVersion(1,0); + .MapToApiVersion(1,0) + .MapToApiVersion(1,1); bucket.MapGet("/getVersion/{id:guid}", (Guid id, DateTime? yearMonth) => bucketService.GetLatestVersion(id, yearMonth ?? DateTime.Now)) - .MapToApiVersion(1,0); + .MapToApiVersion(1,0) + .MapToApiVersion(1,1); bucket.MapGet("/figures/{id:guid}", (Guid id, DateTime? yearMonth) => bucketService.GetFigures(id, yearMonth ?? new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1))) - .MapToApiVersion(1,0); + .MapToApiVersion(1,0) + .MapToApiVersion(1,1); bucket.MapGet("/balance/{id:guid}", (Guid id, DateTime? yearMonth) => bucketService.GetBalance(id, yearMonth ?? new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1))) - .MapToApiVersion(1,0); + .MapToApiVersion(1,0) + .MapToApiVersion(1,1); bucket.MapGet("/inOut/{id:guid}", (Guid id, DateTime? yearMonth) => bucketService.GetInAndOut(id, yearMonth ?? new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1))) - .MapToApiVersion(1,0); + .MapToApiVersion(1,0) + .MapToApiVersion(1,1); // POST bucket.MapPost( "/", (Bucket entity) => bucketService.Create(entity)) .Accepts("application/json") - .MapToApiVersion(1,0); + .MapToApiVersion(1,0) + .MapToApiVersion(1,1); // PATCH bucket.MapPatch( "/", (Bucket entity) => bucketService.Update(entity)) .Accepts("application/json") - .MapToApiVersion(1,0); + .MapToApiVersion(1,0) + .MapToApiVersion(1,1); // DELETE bucket.MapDelete( "/{id:guid}", (Guid id) => bucketService.Delete(id)) - .MapToApiVersion(1,0); + .MapToApiVersion(1,0) + .MapToApiVersion(1,1); bucket.MapDelete( "/close/{id:guid}", (Guid id, DateTime? yearMonth) => bucketService.Close(id, yearMonth ?? new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1))) - .MapToApiVersion(1,0); + .MapToApiVersion(1,0) + .MapToApiVersion(1,1); #endregion @@ -212,25 +252,31 @@ await recurringTransactionService.CreatePendingBankTransactionAsync(yearMonth)) // GET group.MapGet("{id:guid}", (Guid id) => groupService.GetWithBuckets(id)) - .MapToApiVersion(1,0); + .MapToApiVersion(1,0) + .MapToApiVersion(1,1); group.MapGet("/", (bool full) => full ? groupService.GetAllFull() : groupService.GetAll()) - .MapToApiVersion(1,0); + .MapToApiVersion(1,0) + .MapToApiVersion(1,1); // POST group.MapPost( "/", (BucketGroup entity) => groupService.Create(entity)) .Accepts("application/json") - .MapToApiVersion(1,0); + .MapToApiVersion(1,0) + .MapToApiVersion(1,1); // PATCH group.MapPatch( "/", (BucketGroup entity) => groupService.Update(entity)) .Accepts("application/json") - .MapToApiVersion(1,0); + .MapToApiVersion(1,0) + .MapToApiVersion(1,1); group.MapPatch( "/move/{id:guid}", (Guid id, int positions) => groupService.Move(id, positions)) - .MapToApiVersion(1,0); + .MapToApiVersion(1,0) + .MapToApiVersion(1,1); // DELETE group.MapDelete( "/{id:guid}", (Guid id) => groupService.Delete(id)) - .MapToApiVersion(1,0); + .MapToApiVersion(1,0) + .MapToApiVersion(1,1); #endregion @@ -242,25 +288,31 @@ await recurringTransactionService.CreatePendingBankTransactionAsync(yearMonth)) // GET rules.MapGet("{id:guid}", (Guid id) => ruleSetService.Get(id)) - .MapToApiVersion(1,0); + .MapToApiVersion(1,0) + .MapToApiVersion(1,1); rules.MapGet("/", () => ruleSetService.GetAll()) - .MapToApiVersion(1,0); + .MapToApiVersion(1,0) + .MapToApiVersion(1,1); rules.MapGet("/mappings/{id:guid}", (Guid id) => ruleSetService.GetMappingRules(id)) - .MapToApiVersion(1,0); + .MapToApiVersion(1,0) + .MapToApiVersion(1,1); // POST rules.MapPost( "/", (BucketRuleSet entity) => ruleSetService.Create(entity)) .Accepts("application/json") - .MapToApiVersion(1,0); + .MapToApiVersion(1,0) + .MapToApiVersion(1,1); // PATCH rules.MapPatch( "/", (BucketRuleSet entity) => ruleSetService.Update(entity)) .Accepts("application/json") - .MapToApiVersion(1,0); + .MapToApiVersion(1,0) + .MapToApiVersion(1,1); // DELETE rules.MapDelete( "/{id:guid}", (Guid id) => ruleSetService.Delete(id)) - .MapToApiVersion(1,0); + .MapToApiVersion(1,0) + .MapToApiVersion(1,1); #endregion @@ -272,27 +324,33 @@ await recurringTransactionService.CreatePendingBankTransactionAsync(yearMonth)) // GET movement.MapGet("{id:guid}", (Guid id) => movementService.Get(id)) - .MapToApiVersion(1,0); + .MapToApiVersion(1,0) + .MapToApiVersion(1,1); movement.MapGet("/", (DateTime? periodStart, DateTime? periodEnd) => movementService.GetAll(periodStart ?? DateTime.MinValue, periodEnd ?? DateTime.MaxValue)) - .MapToApiVersion(1,0); + .MapToApiVersion(1,0) + .MapToApiVersion(1,1); movement.MapGet("/fromBucket/{id:guid}", (Guid id, DateTime? periodStart, DateTime? periodEnd) => movementService.GetAllFromBucket(id, periodStart ?? DateTime.MinValue, periodEnd ?? DateTime.MaxValue)) - .MapToApiVersion(1,0); + .MapToApiVersion(1,0) + .MapToApiVersion(1,1); // POST movement.MapPost( "/", (BucketMovement entity) => movementService.Create(entity)) .Accepts("application/json") - .MapToApiVersion(1,0); + .MapToApiVersion(1,0) + .MapToApiVersion(1,1); // PATCH movement.MapPatch( "/", (BucketMovement entity) => movementService.Update(entity)) .Accepts("application/json") - .MapToApiVersion(1,0); + .MapToApiVersion(1,0) + .MapToApiVersion(1,1); // DELETE movement.MapDelete( "/{id:guid}", (Guid id) => movementService.Delete(id)) - .MapToApiVersion(1,0); + .MapToApiVersion(1,0) + .MapToApiVersion(1,1); #endregion @@ -304,23 +362,28 @@ await recurringTransactionService.CreatePendingBankTransactionAsync(yearMonth)) // GET import.MapGet("{id:guid}", (Guid id) => importProfileService.Get(id)) - .MapToApiVersion(1,0); + .MapToApiVersion(1,0) + .MapToApiVersion(1,1); import.MapGet("/", () => importProfileService.GetAll()) - .MapToApiVersion(1,0); + .MapToApiVersion(1,0) + .MapToApiVersion(1,1); // POST import.MapPost( "/", (ImportProfile entity) => importProfileService.Create(entity)) .Accepts("application/json") - .MapToApiVersion(1,0); + .MapToApiVersion(1,0) + .MapToApiVersion(1,1); // PATCH import.MapPatch( "/", (ImportProfile entity) => importProfileService.Update(entity)) .Accepts("application/json") - .MapToApiVersion(1,0); + .MapToApiVersion(1,0) + .MapToApiVersion(1,1); // DELETE import.MapDelete( "/{id:guid}", (Guid id) => importProfileService.Delete(id)) - .MapToApiVersion(1,0); + .MapToApiVersion(1,0) + .MapToApiVersion(1,1); #endregion