Skip to content

Commit

Permalink
Add models and basic auth test endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
ParadoxZero committed Jul 24, 2024
1 parent 758b8f0 commit 7dcc8b3
Show file tree
Hide file tree
Showing 15 changed files with 208 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Program.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();
builder.Services.AddSwaggerGen();

var app = builder.Build();

app.UseDefaultFiles();
app.UseStaticFiles();

if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}

app.MapGet("/hello-world", () => "Hello World!");
app.MapControllers();

app.Run();
14 changes: 14 additions & 0 deletions api/models/category.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace budgetbud.Models
{
public class Category
{
public int Id { get; set; }
public required string Name { get; set; }
public required string Description { get; set; }
public decimal Allocation { get; set; }
public bool IsActive { get; set; }
public DateTime LastUpdated { get; set; }
public required string Currency { get; set; }
public required List<Expense> ExpenseList { get; set; }
}
}
10 changes: 10 additions & 0 deletions api/models/expense.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace budgetbud.Models;

public class Expense
{
public int Id { get; set; }
public required string Title { get; set; }
public decimal Amount { get; set; }
public int CategoryId { get; set; }
public DateTime Timestamp { get; set; }
}
27 changes: 27 additions & 0 deletions api/models/recurring.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

namespace budgetbud.Models;
using System;

public enum RecurringType
{
Weekly = 0,
Biweekly = 1,
Monthly = 2,
Quarterly = 3, // unsupported
HalfYearly = 4, // unsupported
Yearly = 5
}

public class Recurring
{
public int Id { get; set; }
public required string Name { get; set; }
public required string Description { get; set; }
public bool IsActive { get; set; }
public DateTime LastUpdated { get; set; }
public RecurringType Frequency { get; set; }
public int FrequencyUnit { get; set; } // This has different meanings based on the frequency, if monthly, it will be day of month, if weekly, it will be day of week etc.
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
public decimal Amount { get; set; }
}
6 changes: 6 additions & 0 deletions api/models/time_unit.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace budgetbud.Models;
public class TimeUnit
{
public int Month { get; set; }
public int Year { get; set; }
}
26 changes: 26 additions & 0 deletions api/models/user_action.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
namespace budgetbud.Models;
public enum UserActionType
{
addCategory = 0,
deleteCategory = 1,
updateCategory = 2,
addExpense = 3,
deleteExpense = 4,
updateExpense = 5,
addRecurring = 6,
deleteRecurring = 7,
updateRecurring = 8,
addUnplanned = 9,
deleteUnplanned = 10,
updateUnplanned = 11
}

public class UserAction
{
public DateTime timestamp { get; set; }
public UserActionType type { get; set; }
public Category? category { get; set; }
public Expense? expense { get; set; }
public Recurring? recurring { get; set; }
public Expense? unplanned { get; set; }
}
15 changes: 15 additions & 0 deletions api/models/user_data.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace budgetbud.Models;


public class UserData
{
public required string id { get; set; }
public required string history_id { get; set; }
public required Category[] categoryList { get; set; }
public required Recurring[] recurringList { get; set; }
public required Expense[] unplannedList { get; set; }
public required TimeUnit history_unit { get; set; }
public required UserAction[] userActions { get; set; }
public DateTime last_updated { get; set; }
public required string[] authorized_users { get; set; }
}
6 changes: 6 additions & 0 deletions api/models/user_data_history.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace budgetbud.Models;
public class UserDataHistory
{
public required string id { get; set; }
public required UserData[] history { get; set; }
}
Empty file.
35 changes: 35 additions & 0 deletions api/services/db_service.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using Microsoft.AspNetCore.Routing.Template;
using Microsoft.Azure.Cosmos;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace budgetbud.Services
{
public class DbService
{
private readonly string _endpointUri;
private readonly string _primaryKey;
private readonly string _databaseName;
private readonly string _containerName;
private CosmosClient? _cosmosClient;
private Database? _database;
private Container? _container;

public DbService(string endpointUri, string primaryKey, string databaseName, string containerName)
{
_endpointUri = endpointUri;
_primaryKey = primaryKey;
_databaseName = databaseName;
_containerName = containerName;
}

public async Task InitializeAsync()
{
_cosmosClient = new CosmosClient(_endpointUri, _primaryKey);
_database = await _cosmosClient.CreateDatabaseIfNotExistsAsync(_databaseName);
_container = await _database.CreateContainerIfNotExistsAsync(_containerName, "/partitionKey");
}

}
}
Empty file.
6 changes: 6 additions & 0 deletions api/services/identity_service.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace budgetbud.Services;

public interface IIdentityService
{
string GetUserIdentity();
}
29 changes: 29 additions & 0 deletions api/user_data_controller.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Microsoft.AspNetCore.Mvc;

namespace budgetbud.Controllers;

[ApiController]
[Route("api/[controller]")]
public class UserDataController : ControllerBase
{
[HttpGet("hello-world")]
public IActionResult Get()
{
return Ok("Hello, World!");
}

[HttpGet("user-id")]
public IActionResult GetUserId()
{
if (HttpContext.Request.Headers.TryGetValue("X-MS-CLIENT-PRINCIPAL", out var clientPrincipal))
{
// Use the clientPrincipal value here
var decodedClientPrincipal = System.Text.Encoding.UTF8.GetString(Convert.FromBase64String(clientPrincipal));

Check warning on line 21 in api/user_data_controller.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 's' in 'byte[] Convert.FromBase64String(string s)'.

Check warning on line 21 in api/user_data_controller.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 's' in 'byte[] Convert.FromBase64String(string s)'.
return Ok(decodedClientPrincipal);
}
else
{
return BadRequest("X-MS-CLIENT-PRINCIPAL header not found");
}
}
}
6 changes: 6 additions & 0 deletions budgetbud.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,10 @@
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.Identity" Version="1.12.0" />
<PackageReference Include="Microsoft.Azure.Cosmos" Version="3.41.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
</ItemGroup>

</Project>
19 changes: 19 additions & 0 deletions makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
ui-install:
npm install

ui: ui-install
npm run build

run: ui
dotnet run

publish: ui
dotnet publish -c Release -o publish

run-ui:
npm run dev

clean:
rm -rf dist
rm -rf bin
rm -rf obj

0 comments on commit 7dcc8b3

Please sign in to comment.