Skip to content

Commit

Permalink
Update/Fix API
Browse files Browse the repository at this point in the history
  • Loading branch information
TheAxelander committed Dec 1, 2024
1 parent a5b88ee commit b3c9f72
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 65 deletions.
8 changes: 4 additions & 4 deletions OpenBudgeteer.API/ConfigureSwaggerOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
185 changes: 124 additions & 61 deletions OpenBudgeteer.API/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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<Account>("application/json")
.MapToApiVersion(1,0);
.MapToApiVersion(1,0)
.MapToApiVersion(1,1);

// PATCH
account.MapPatch( "/", (Account entity) => accountService.Update(entity))
.Accepts<Account>("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

Expand All @@ -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<BankTransaction>("application/json")
.MapToApiVersion(1,0);
.MapToApiVersion(1,0)
.MapToApiVersion(1,1);
transaction.MapPost( "/withBucket", (BankTransaction entity) =>
bankTransactionService.Create(entity))
.Accepts<BankTransaction>("application/json")
.MapToApiVersion(1,0);
.MapToApiVersion(1,0)
.MapToApiVersion(1,1);

// PATCH
transaction.MapPatch( "/", (BankTransaction entity) => bankTransactionService.Update(entity))
.Accepts<BankTransaction>("application/json")
.MapToApiVersion(1,0);
.MapToApiVersion(1,0)
.MapToApiVersion(1,1);
transaction.MapPatch( "/withBucket", (BankTransaction entity) =>
bankTransactionService.Update(entity))
.Accepts<BankTransaction>("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

Expand All @@ -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<RecurringBankTransaction>("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<RecurringBankTransaction>("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

Expand All @@ -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<Bucket>("application/json")
.MapToApiVersion(1,0);
.MapToApiVersion(1,0)
.MapToApiVersion(1,1);

// PATCH
bucket.MapPatch( "/", (Bucket entity) => bucketService.Update(entity))
.Accepts<Bucket>("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

Expand All @@ -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<BucketGroup>("application/json")
.MapToApiVersion(1,0);
.MapToApiVersion(1,0)
.MapToApiVersion(1,1);

// PATCH
group.MapPatch( "/", (BucketGroup entity) => groupService.Update(entity))
.Accepts<BucketGroup>("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

Expand All @@ -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<BucketRuleSet>("application/json")
.MapToApiVersion(1,0);
.MapToApiVersion(1,0)
.MapToApiVersion(1,1);

// PATCH
rules.MapPatch( "/", (BucketRuleSet entity) => ruleSetService.Update(entity))
.Accepts<BucketRuleSet>("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

Expand All @@ -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<BucketMovement>("application/json")
.MapToApiVersion(1,0);
.MapToApiVersion(1,0)
.MapToApiVersion(1,1);

// PATCH
movement.MapPatch( "/", (BucketMovement entity) => movementService.Update(entity))
.Accepts<BucketMovement>("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

Expand All @@ -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<ImportProfile>("application/json")
.MapToApiVersion(1,0);
.MapToApiVersion(1,0)
.MapToApiVersion(1,1);

// PATCH
import.MapPatch( "/", (ImportProfile entity) => importProfileService.Update(entity))
.Accepts<ImportProfile>("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

Expand Down

0 comments on commit b3c9f72

Please sign in to comment.