-
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.
Add models and basic auth test endpoint
- Loading branch information
1 parent
758b8f0
commit 7dcc8b3
Showing
15 changed files
with
208 additions
and
0 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
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(); |
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,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; } | ||
} | ||
} |
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,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; } | ||
} |
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,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; } | ||
} |
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,6 @@ | ||
namespace budgetbud.Models; | ||
public class TimeUnit | ||
{ | ||
public int Month { get; set; } | ||
public int Year { get; set; } | ||
} |
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,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; } | ||
} |
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,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; } | ||
} |
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,6 @@ | ||
namespace budgetbud.Models; | ||
public class UserDataHistory | ||
{ | ||
public required string id { get; set; } | ||
public required UserData[] history { get; set; } | ||
} |
Empty file.
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,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.
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,6 @@ | ||
namespace budgetbud.Services; | ||
|
||
public interface IIdentityService | ||
{ | ||
string GetUserIdentity(); | ||
} |
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,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 GitHub Actions / build
|
||
return Ok(decodedClientPrincipal); | ||
} | ||
else | ||
{ | ||
return BadRequest("X-MS-CLIENT-PRINCIPAL header not found"); | ||
} | ||
} | ||
} |
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
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 |