diff --git a/CommBank-Server-Tasks/.env b/CommBank-Server-Tasks/.env new file mode 100644 index 0000000..baa21d4 --- /dev/null +++ b/CommBank-Server-Tasks/.env @@ -0,0 +1,3 @@ +User_name = User1 +database_pass = My_mongo123 +connection_string=mongodb+srv://User1:My_mongo123@foragecommbankmongodb.xhxgfcb.mongodb.net/?retryWrites=true&w=majority&appName=ForageCommbankMongoDB diff --git a/CommBank-Server-Tasks/.gitignore b/CommBank-Server-Tasks/.gitignore new file mode 100644 index 0000000..6769715 --- /dev/null +++ b/CommBank-Server-Tasks/.gitignore @@ -0,0 +1,407 @@ +# globs +Makefile.in +*.userprefs +*.usertasks +config.make +config.status +aclocal.m4 +install-sh +autom4te.cache/ +*.tar.gz +tarballs/ +test-results/ + +# Mac bundle stuff +*.dmg +*.app + +# content below from: https://github.com/github/gitignore/blob/main/Global/macOS.gitignore +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +# content below from: https://github.com/github/gitignore/blob/main/Global/Windows.gitignore +# Windows thumbnail cache files +Thumbs.db +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk + +# content below from: https://github.com/github/gitignore/blob/master/VisualStudio.gitignore +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# JetBrains Rider +.idea/ +*.sln.iml + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + + diff --git a/CommBank-Server/CommBank.csproj b/CommBank-Server-Tasks/CommBank.csproj similarity index 84% rename from CommBank-Server/CommBank.csproj rename to CommBank-Server-Tasks/CommBank.csproj index 983cc88..ff3916b 100644 --- a/CommBank-Server/CommBank.csproj +++ b/CommBank-Server-Tasks/CommBank.csproj @@ -9,11 +9,12 @@ + - + - + diff --git a/CommBank-Server/Controllers/AccountController.cs b/CommBank-Server-Tasks/Controllers/AccountController.cs similarity index 100% rename from CommBank-Server/Controllers/AccountController.cs rename to CommBank-Server-Tasks/Controllers/AccountController.cs diff --git a/CommBank-Server/Controllers/AuthController.cs b/CommBank-Server-Tasks/Controllers/AuthController.cs similarity index 100% rename from CommBank-Server/Controllers/AuthController.cs rename to CommBank-Server-Tasks/Controllers/AuthController.cs diff --git a/CommBank-Server/Controllers/GoalController.cs b/CommBank-Server-Tasks/Controllers/GoalController.cs similarity index 100% rename from CommBank-Server/Controllers/GoalController.cs rename to CommBank-Server-Tasks/Controllers/GoalController.cs diff --git a/CommBank-Server/Controllers/HomeController.cs b/CommBank-Server-Tasks/Controllers/HomeController.cs similarity index 100% rename from CommBank-Server/Controllers/HomeController.cs rename to CommBank-Server-Tasks/Controllers/HomeController.cs diff --git a/CommBank-Server/Controllers/TagController.cs b/CommBank-Server-Tasks/Controllers/TagController.cs similarity index 100% rename from CommBank-Server/Controllers/TagController.cs rename to CommBank-Server-Tasks/Controllers/TagController.cs diff --git a/CommBank-Server/Controllers/TransactionController.cs b/CommBank-Server-Tasks/Controllers/TransactionController.cs similarity index 100% rename from CommBank-Server/Controllers/TransactionController.cs rename to CommBank-Server-Tasks/Controllers/TransactionController.cs diff --git a/CommBank-Server/Controllers/UserController.cs b/CommBank-Server-Tasks/Controllers/UserController.cs similarity index 100% rename from CommBank-Server/Controllers/UserController.cs rename to CommBank-Server-Tasks/Controllers/UserController.cs diff --git a/CommBank-Server/Models/Account.cs b/CommBank-Server-Tasks/Models/Account.cs similarity index 100% rename from CommBank-Server/Models/Account.cs rename to CommBank-Server-Tasks/Models/Account.cs diff --git a/CommBank-Server/Models/AccountType.cs b/CommBank-Server-Tasks/Models/AccountType.cs similarity index 100% rename from CommBank-Server/Models/AccountType.cs rename to CommBank-Server-Tasks/Models/AccountType.cs diff --git a/CommBank-Server/Models/ErrorViewModel.cs b/CommBank-Server-Tasks/Models/ErrorViewModel.cs similarity index 100% rename from CommBank-Server/Models/ErrorViewModel.cs rename to CommBank-Server-Tasks/Models/ErrorViewModel.cs diff --git a/CommBank-Server/Models/Goal.cs b/CommBank-Server-Tasks/Models/Goal.cs similarity index 94% rename from CommBank-Server/Models/Goal.cs rename to CommBank-Server-Tasks/Models/Goal.cs index 77ff1ad..20b9b5d 100644 --- a/CommBank-Server/Models/Goal.cs +++ b/CommBank-Server-Tasks/Models/Goal.cs @@ -27,4 +27,6 @@ public class Goal [BsonRepresentation(BsonType.ObjectId)] public string? UserId { get; set; } + + public string? Icon { get; set; } } \ No newline at end of file diff --git a/CommBank-Server/Models/LoginInput.cs b/CommBank-Server-Tasks/Models/LoginInput.cs similarity index 100% rename from CommBank-Server/Models/LoginInput.cs rename to CommBank-Server-Tasks/Models/LoginInput.cs diff --git a/CommBank-Server/Models/ObjectIdConverter.cs b/CommBank-Server-Tasks/Models/ObjectIdConverter.cs similarity index 100% rename from CommBank-Server/Models/ObjectIdConverter.cs rename to CommBank-Server-Tasks/Models/ObjectIdConverter.cs diff --git a/CommBank-Server/Models/Tag.cs b/CommBank-Server-Tasks/Models/Tag.cs similarity index 100% rename from CommBank-Server/Models/Tag.cs rename to CommBank-Server-Tasks/Models/Tag.cs diff --git a/CommBank-Server/Models/Transaction.cs b/CommBank-Server-Tasks/Models/Transaction.cs similarity index 100% rename from CommBank-Server/Models/Transaction.cs rename to CommBank-Server-Tasks/Models/Transaction.cs diff --git a/CommBank-Server/Models/TransactionType.cs b/CommBank-Server-Tasks/Models/TransactionType.cs similarity index 100% rename from CommBank-Server/Models/TransactionType.cs rename to CommBank-Server-Tasks/Models/TransactionType.cs diff --git a/CommBank-Server/Models/UpdatedIcon.cs b/CommBank-Server-Tasks/Models/UpdatedIcon.cs similarity index 100% rename from CommBank-Server/Models/UpdatedIcon.cs rename to CommBank-Server-Tasks/Models/UpdatedIcon.cs diff --git a/CommBank-Server/Models/User.cs b/CommBank-Server-Tasks/Models/User.cs similarity index 100% rename from CommBank-Server/Models/User.cs rename to CommBank-Server-Tasks/Models/User.cs diff --git a/CommBank-Server-Tasks/Program.cs b/CommBank-Server-Tasks/Program.cs new file mode 100644 index 0000000..186b96d --- /dev/null +++ b/CommBank-Server-Tasks/Program.cs @@ -0,0 +1,137 @@ +using CommBank.Models; +using CommBank.Services; +using MongoDB.Driver; +using MongoDB.Bson; +using MongoDB.Bson.IO; +using MongoDB.Bson.Serialization; +using Newtonsoft.Json; + +var builder = WebApplication.CreateBuilder(args); + +// Load environment variables from .env file +DotNetEnv.Env.Load(); + +builder.Services.AddControllers(); + +builder.Services.AddEndpointsApiExplorer(); +builder.Services.AddSwaggerGen(); + +// Configure MongoDB client +var connectionString = Environment.GetEnvironmentVariable("connection_string"); +var mongoClient = new MongoClient(connectionString); +var mongoDatabase = mongoClient.GetDatabase("CommBank"); + +IAccountsService accountsService = new AccountsService(mongoDatabase); +IAuthService authService = new AuthService(mongoDatabase); +IGoalsService goalsService = new GoalsService(mongoDatabase); +ITagsService tagsService = new TagsService(mongoDatabase); +ITransactionsService transactionsService = new TransactionsService(mongoDatabase); +IUsersService usersService = new UsersService(mongoDatabase); + +builder.Services.AddSingleton(accountsService); +builder.Services.AddSingleton(authService); +builder.Services.AddSingleton(goalsService); +builder.Services.AddSingleton(tagsService); +builder.Services.AddSingleton(transactionsService); +builder.Services.AddSingleton(usersService); + +// Call the async seeding method +try +{ + await SeedDatabaseAsync(mongoDatabase); +} +catch (Exception ex) +{ + Console.WriteLine($"An error occurred during database seeding: {ex}"); + // Optionally rethrow or handle the exception as needed + throw; +} + +builder.Services.AddCors(); + +var app = builder.Build(); + +// --- Helper method for seeding --- +static async Task SeedDatabaseAsync(IMongoDatabase database) +{ + Console.WriteLine("Starting database seeding..."); + + var accountsCollection = database.GetCollection("Accounts"); + if (await accountsCollection.CountDocumentsAsync(Builders.Filter.Empty) == 0) + { + Console.WriteLine("Seeding Accounts..."); + var accountsJson = await System.IO.File.ReadAllTextAsync("data/Accounts.json"); + var accounts = BsonSerializer.Deserialize>(accountsJson); + await accountsCollection.InsertManyAsync(accounts); + Console.WriteLine("Accounts seeded."); + } else { + Console.WriteLine("Accounts collection already seeded."); + } + + var goalsCollection = database.GetCollection("Goals"); + if (await goalsCollection.CountDocumentsAsync(Builders.Filter.Empty) == 0) + { + Console.WriteLine("Seeding Goals..."); + var goalsJson = await System.IO.File.ReadAllTextAsync("data/Goals.json"); + var goals = BsonSerializer.Deserialize>(goalsJson); + await goalsCollection.InsertManyAsync(goals); + Console.WriteLine("Goals seeded."); + } else { + Console.WriteLine("Goals collection already seeded."); + } + + var tagsCollection = database.GetCollection("Tags"); + if (await tagsCollection.CountDocumentsAsync(Builders.Filter.Empty) == 0) + { + Console.WriteLine("Seeding Tags..."); + var tagsJson = await System.IO.File.ReadAllTextAsync("data/Tags.json"); + var tags = BsonSerializer.Deserialize>(tagsJson); + await tagsCollection.InsertManyAsync(tags); + Console.WriteLine("Tags seeded."); + } else { + Console.WriteLine("Tags collection already seeded."); + } + var transactionsCollection = database.GetCollection("Transactions"); + if (await transactionsCollection.CountDocumentsAsync(Builders.Filter.Empty) == 0) + { + Console.WriteLine("Seeding Transactions..."); + var transactionsJson = await System.IO.File.ReadAllTextAsync("data/Transactions.json"); + var transactions = BsonSerializer.Deserialize>(transactionsJson); + await transactionsCollection.InsertManyAsync(transactions); + Console.WriteLine("Transactions seeded."); + } else { + Console.WriteLine("Transactions collection already seeded."); + } + + var usersCollection = database.GetCollection("Users"); + if (await usersCollection.CountDocumentsAsync(Builders.Filter.Empty) == 0) + { + Console.WriteLine("Seeding Users..."); + var usersJson = await System.IO.File.ReadAllTextAsync("data/Users.json"); + var users = BsonSerializer.Deserialize>(usersJson); + await usersCollection.InsertManyAsync(users); + Console.WriteLine("Users seeded."); + } else { + Console.WriteLine("Users collection already seeded."); + } + + Console.WriteLine("Database seeding finished."); +} + +app.UseCors(builder => builder + .AllowAnyOrigin() + .AllowAnyMethod() + .AllowAnyHeader()); + +if (app.Environment.IsDevelopment()) +{ + app.UseSwagger(); + app.UseSwaggerUI(); +} + +app.UseHttpsRedirection(); + +app.UseAuthorization(); + +app.MapControllers(); +app.Run(); diff --git a/CommBank-Server/Properties/launchSettings.json b/CommBank-Server-Tasks/Properties/launchSettings.json similarity index 75% rename from CommBank-Server/Properties/launchSettings.json rename to CommBank-Server-Tasks/Properties/launchSettings.json index 2c9f444..2e88ca0 100644 --- a/CommBank-Server/Properties/launchSettings.json +++ b/CommBank-Server-Tasks/Properties/launchSettings.json @@ -15,7 +15,8 @@ "launchUrl": "swagger", "applicationUrl": "http://localhost:11366;http://localhost:5203", "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" + "ASPNETCORE_ENVIRONMENT": "Development", + "connection_string": "mongodb+srv://User1:New%40User_Cluster01@foragecommbankmongodb.xhxgfcb.mongodb.net/CommBank?retryWrites=true&w=majority&appName=ForageCommbankMongoDB" } }, "IIS Express": { @@ -27,4 +28,4 @@ } } } -} \ No newline at end of file +} diff --git a/CommBank-Server/Services/AccountService.cs b/CommBank-Server-Tasks/Services/AccountService.cs similarity index 100% rename from CommBank-Server/Services/AccountService.cs rename to CommBank-Server-Tasks/Services/AccountService.cs diff --git a/CommBank-Server/Services/AuthService.cs b/CommBank-Server-Tasks/Services/AuthService.cs similarity index 100% rename from CommBank-Server/Services/AuthService.cs rename to CommBank-Server-Tasks/Services/AuthService.cs diff --git a/CommBank-Server/Services/GoalService.cs b/CommBank-Server-Tasks/Services/GoalService.cs similarity index 100% rename from CommBank-Server/Services/GoalService.cs rename to CommBank-Server-Tasks/Services/GoalService.cs diff --git a/CommBank-Server/Services/IAccountService.cs b/CommBank-Server-Tasks/Services/IAccountService.cs similarity index 100% rename from CommBank-Server/Services/IAccountService.cs rename to CommBank-Server-Tasks/Services/IAccountService.cs diff --git a/CommBank-Server/Services/IAuthService.cs b/CommBank-Server-Tasks/Services/IAuthService.cs similarity index 100% rename from CommBank-Server/Services/IAuthService.cs rename to CommBank-Server-Tasks/Services/IAuthService.cs diff --git a/CommBank-Server/Services/IGoalsService.cs b/CommBank-Server-Tasks/Services/IGoalsService.cs similarity index 100% rename from CommBank-Server/Services/IGoalsService.cs rename to CommBank-Server-Tasks/Services/IGoalsService.cs diff --git a/CommBank-Server/Services/ITagsService.cs b/CommBank-Server-Tasks/Services/ITagsService.cs similarity index 100% rename from CommBank-Server/Services/ITagsService.cs rename to CommBank-Server-Tasks/Services/ITagsService.cs diff --git a/CommBank-Server/Services/ITransactionsService.cs b/CommBank-Server-Tasks/Services/ITransactionsService.cs similarity index 100% rename from CommBank-Server/Services/ITransactionsService.cs rename to CommBank-Server-Tasks/Services/ITransactionsService.cs diff --git a/CommBank-Server/Services/IUsersService.cs b/CommBank-Server-Tasks/Services/IUsersService.cs similarity index 100% rename from CommBank-Server/Services/IUsersService.cs rename to CommBank-Server-Tasks/Services/IUsersService.cs diff --git a/CommBank-Server/Services/TagsService.cs b/CommBank-Server-Tasks/Services/TagsService.cs similarity index 100% rename from CommBank-Server/Services/TagsService.cs rename to CommBank-Server-Tasks/Services/TagsService.cs diff --git a/CommBank-Server/Services/TransactionsService.cs b/CommBank-Server-Tasks/Services/TransactionsService.cs similarity index 100% rename from CommBank-Server/Services/TransactionsService.cs rename to CommBank-Server-Tasks/Services/TransactionsService.cs diff --git a/CommBank-Server/Services/UsersService.cs b/CommBank-Server-Tasks/Services/UsersService.cs similarity index 100% rename from CommBank-Server/Services/UsersService.cs rename to CommBank-Server-Tasks/Services/UsersService.cs diff --git a/CommBank-Server/appsettings.Development.json b/CommBank-Server-Tasks/appsettings.Development.json similarity index 100% rename from CommBank-Server/appsettings.Development.json rename to CommBank-Server-Tasks/appsettings.Development.json diff --git a/CommBank-Server/appsettings.json b/CommBank-Server-Tasks/appsettings.json similarity index 100% rename from CommBank-Server/appsettings.json rename to CommBank-Server-Tasks/appsettings.json diff --git a/CommBank-Server-Tasks/data/Accounts.json b/CommBank-Server-Tasks/data/Accounts.json new file mode 100644 index 0000000..c94a91d --- /dev/null +++ b/CommBank-Server-Tasks/data/Accounts.json @@ -0,0 +1,53 @@ +[{ + "_id": { + "$oid": "62a3e6aad25715026d1a2938" + }, + "Number": 123456789, + "Name": "Tag's Goal Saver", + "Balance": 6483.81, + "AccountType": "GoalSaver", + "TransactionIds": [ + { + "$oid": "62a3a284d07648900df72860" + }, + { + "$oid": "62a3a2ded07648900df72861" + }, + { + "$oid": "62a3a2ded07648900df72862" + }, + { + "$oid": "62a3a2ded07648900df72863" + }, + { + "$oid": "62a3a2ded07648900df72864" + }, + { + "$oid": "62a3a2ded07648900df72865" + }, + { + "$oid": "62a3a2ded07648900df72866" + }, + { + "$oid": "62a3a2ded07648900df72867" + }, + { + "$oid": "62a3a2ded07648900df72868" + }, + { + "$oid": "62a3a2ded07648900df72869" + }, + { + "$oid": "62a3a344d07648900df7286a" + }, + { + "$oid": "62a3a344d07648900df7286b" + }, + { + "$oid": "62a3a344d07648900df7286c" + }, + { + "$oid": "62a3a344d07648900df7286d" + } + ] +}] \ No newline at end of file diff --git a/CommBank-Server-Tasks/data/Goals.json b/CommBank-Server-Tasks/data/Goals.json new file mode 100644 index 0000000..f42d18b --- /dev/null +++ b/CommBank-Server-Tasks/data/Goals.json @@ -0,0 +1,94 @@ +[ + { + "_id": { + "$oid": "62a3f587102e921da1253d32" + }, + "Name": "House Down Payment", + "TargetAmount": 100000, + "TargetDate": { + "$date": { + "$numberLong": "1736312400000" + } + }, + "Balance": 73501.82, + "Created": { + "$date": { + "$numberLong": "1654912390857" + } + }, + "TransactionIds": null, + "TagIds": null, + "UserId": { + "$oid": "62a29c15f4605c4c9fa7f306" + } + }, + { + "_id": { + "$oid": "62a3f5e0102e921da1253d33" + }, + "Name": "Tesla Model Y", + "TargetAmount": 60000, + "TargetDate": { + "$date": { + "$numberLong": "1662004800000" + } + }, + "Balance": 43840.02, + "Created": { + "$date": { + "$numberLong": "1654912480950" + } + }, + "TransactionIds": null, + "TagIds": null, + "UserId": { + "$oid": "62a29c15f4605c4c9fa7f306" + } + }, + { + "_id": { + "$oid": "62a3f62e102e921da1253d34" + }, + "Name": "Trip to London", + "TargetAmount": 3500, + "TargetDate": { + "$date": { + "$numberLong": "1659412800000" + } + }, + "Created": { + "$date": { + "$numberLong": "1654912558236" + } + }, + "TransactionIds": null, + "TagIds": null, + "Balance": 753.89, + "UserId": { + "$oid": "62a29c15f4605c4c9fa7f306" + } + }, + { + "_id": { + "$oid": "62a61945fa15f1cd18516a5f" + }, + "Name": "Trip to NYC", + "TargetAmount": 800, + "TargetDate": { + "$date": { + "$numberLong": "1702184400000" + } + }, + "Balance": 0, + "Created": { + "$date": { + "$numberLong": "1655053065668" + } + }, + "TransactionIds": null, + "TagIds": null, + "UserId": { + "$oid": "62a29c15f4605c4c9fa7f306" + } + } +] \ No newline at end of file diff --git a/CommBank-Server-Tasks/data/Tags.json b/CommBank-Server-Tasks/data/Tags.json new file mode 100644 index 0000000..202e1ab --- /dev/null +++ b/CommBank-Server-Tasks/data/Tags.json @@ -0,0 +1,26 @@ +[{ + "_id": { + "$oid": "62a39d27025ca1ba8f1f1c1e" + }, + "Name": "Groceries" +},{ + "_id": { + "$oid": "62a39d42025ca1ba8f1f1c1f" + }, + "Name": "Restaurant" +},{ + "_id": { + "$oid": "62a39d4e025ca1ba8f1f1c20" + }, + "Name": "Income" +},{ + "_id": { + "$oid": "62a39d5a025ca1ba8f1f1c21" + }, + "Name": "Gas" +},{ + "_id": { + "$oid": "62a39d63025ca1ba8f1f1c22" + }, + "Name": "Investment" +}] \ No newline at end of file diff --git a/CommBank-Server-Tasks/data/Transactions.json b/CommBank-Server-Tasks/data/Transactions.json new file mode 100644 index 0000000..9320984 --- /dev/null +++ b/CommBank-Server-Tasks/data/Transactions.json @@ -0,0 +1,310 @@ +[ + { + "_id": { + "$oid": "62a3a284d07648900df72860" + }, + "TransactionType": "Debit", + "Amount": 135.39, + "DateTime": { + "$date": { + "$numberLong": "1654891140391" + } + }, + "GoalId": null, + "TagIds": [ + { + "$oid": "62a39d27025ca1ba8f1f1c1e" + } + ], + "Description": "Whole Foods", + "UserId": { + "$oid": "62a29c15f4605c4c9fa7f306" + } + }, + { + "_id": { + "$oid": "62a3a2ded07648900df72861" + }, + "TransactionType": "Debit", + "Amount": 139.26, + "DateTime": { + "$date": { + "$numberLong": "1654027230566" + } + }, + "GoalId": null, + "TagIds": [ + { + "$oid": "62a39d27025ca1ba8f1f1c1e" + } + ], + "Description": "Whole Foods", + "UserId": { + "$oid": "62a29c15f4605c4c9fa7f306" + } + }, + { + "_id": { + "$oid": "62a3a2ebd07648900df72862" + }, + "TransactionType": "Debit", + "Amount": 26.39, + "DateTime": { + "$date": { + "$numberLong": "1654891243091" + } + }, + "GoalId": null, + "TagIds": [ + { + "$oid": "62a39d42025ca1ba8f1f1c1f" + } + ], + "Description": "Chipotle", + "UserId": { + "$oid": "62a29c15f4605c4c9fa7f306" + } + }, + { + "_id": { + "$oid": "62a3a2ecd07648900df72863" + }, + "TransactionType": "Debit", + "Amount": 21.9, + "DateTime": { + "$date": { + "$numberLong": "1654027230566" + } + }, + "GoalId": null, + "TagIds": [ + { + "$oid": "62a39d42025ca1ba8f1f1c1f" + } + ], + "Description": "Chipotle", + "UserId": { + "$oid": "62a29c15f4605c4c9fa7f306" + } + }, + { + "_id": { + "$oid": "62a3a316d07648900df72864" + }, + "TransactionType": "Credit", + "Amount": 5622.81, + "DateTime": { + "$date": { + "$numberLong": "1654891286080" + } + }, + "GoalId": null, + "TagIds": [ + { + "$oid": "62a39d4e025ca1ba8f1f1c20" + } + ], + "Description": "Dropbox", + "UserId": { + "$oid": "62a29c15f4605c4c9fa7f306" + } + }, + { + "_id": { + "$oid": "62a3a318d07648900df72865" + }, + "TransactionType": "Credit", + "Amount": 5622.92, + "DateTime": { + "$date": { + "$numberLong": "1654027230566" + } + }, + "GoalId": null, + "TagIds": [ + { + "$oid": "62a39d4e025ca1ba8f1f1c20" + } + ], + "Description": "Dropbox", + "UserId": { + "$oid": "62a29c15f4605c4c9fa7f306" + } + }, + { + "_id": { + "$oid": "62a3a323d07648900df72866" + }, + "TransactionType": "Credit", + "Amount": 1439.18, + "DateTime": { + "$date": { + "$numberLong": "1654891299481" + } + }, + "GoalId": null, + "TagIds": [ + { + "$oid": "62a39d4e025ca1ba8f1f1c20" + } + ], + "Description": "Fencer", + "UserId": { + "$oid": "62a29c15f4605c4c9fa7f306" + } + }, + { + "_id": { + "$oid": "62a3a324d07648900df72867" + }, + "TransactionType": "Credit", + "Amount": 1439.89, + "DateTime": { + "$date": { + "$numberLong": "1654027230566" + } + }, + "GoalId": null, + "TagIds": [ + { + "$oid": "62a39d4e025ca1ba8f1f1c20" + } + ], + "Description": "Fencer", + "UserId": { + "$oid": "62a29c15f4605c4c9fa7f306" + } + }, + { + "_id": { + "$oid": "62a3a337d07648900df72868" + }, + "TransactionType": "Debit", + "Amount": 44.52, + "DateTime": { + "$date": { + "$numberLong": "1654891319411" + } + }, + "GoalId": null, + "TagIds": [ + { + "$oid": "62a39d5a025ca1ba8f1f1c21" + } + ], + "Description": "Gas", + "UserId": { + "$oid": "62a29c15f4605c4c9fa7f306" + } + }, + { + "_id": { + "$oid": "62a3a338d07648900df72869" + }, + "TransactionType": "Debit", + "Amount": 44.13, + "DateTime": { + "$date": { + "$numberLong": "1654027230566" + } + }, + "GoalId": null, + "TagIds": [ + { + "$oid": "62a39d5a025ca1ba8f1f1c21" + } + ], + "Description": "Gas", + "UserId": { + "$oid": "62a29c15f4605c4c9fa7f306" + } + }, + { + "_id": { + "$oid": "62a3a344d07648900df7286a" + }, + "TransactionType": "Debit", + "Amount": 1500, + "DateTime": { + "$date": { + "$numberLong": "1654891332111" + } + }, + "GoalId": null, + "TagIds": [ + { + "$oid": "62a39d63025ca1ba8f1f1c22" + } + ], + "Description": "Coinbase", + "UserId": { + "$oid": "62a29c15f4605c4c9fa7f306" + } + }, + { + "_id": { + "$oid": "62a3a344d07648900df7286b" + }, + "TransactionType": "Debit", + "Amount": 1500, + "DateTime": { + "$date": { + "$numberLong": "1654027230566" + } + }, + "GoalId": null, + "TagIds": [ + { + "$oid": "62a39d63025ca1ba8f1f1c22" + } + ], + "Description": "Coinbase", + "UserId": { + "$oid": "62a29c15f4605c4c9fa7f306" + } + }, + { + "_id": { + "$oid": "62a3a348d07648900df7286c" + }, + "TransactionType": "Debit", + "Amount": 1500, + "DateTime": { + "$date": { + "$numberLong": "1654891336929" + } + }, + "GoalId": null, + "TagIds": [ + { + "$oid": "62a39d63025ca1ba8f1f1c22" + } + ], + "Description": "Titan", + "UserId": { + "$oid": "62a29c15f4605c4c9fa7f306" + } + }, + { + "_id": { + "$oid": "62a3a349d07648900df7286d" + }, + "TransactionType": "Debit", + "Amount": 1500, + "DateTime": { + "$date": { + "$numberLong": "1654027230566" + } + }, + "GoalId": null, + "TagIds": [ + { + "$oid": "62a39d63025ca1ba8f1f1c22" + } + ], + "Description": "Titan", + "UserId": { + "$oid": "62a29c15f4605c4c9fa7f306" + } + } +] \ No newline at end of file diff --git a/CommBank-Server-Tasks/data/Users.json b/CommBank-Server-Tasks/data/Users.json new file mode 100644 index 0000000..aa8243c --- /dev/null +++ b/CommBank-Server-Tasks/data/Users.json @@ -0,0 +1,69 @@ +[ + { + "_id": { + "$oid": "62a29c15f4605c4c9fa7f306" + }, + "Name": "Tag Ramotar", + "Email": "tag@dropbox.com", + "Password": "$2a$11$10VhY5XIwBeWA4uLIE.sr.c34UvwLRQPD8yy7z/4iiN6ez5z2Pg1S", + "AccountIds": null, + "GoalIds": [ + { + "$oid": "62a3f587102e921da1253d32" + }, + { + "$oid": "62a3f5e0102e921da1253d33" + }, + { + "$oid": "62a3f62e102e921da1253d34" + }, + { + "$oid": "62a61945fa15f1cd18516a5f" + } + ], + "TransactionIds": [ + { + "$oid": "62a3a284d07648900df72860" + }, + { + "$oid": "62a3a2ded07648900df72861" + }, + { + "$oid": "62a3a2ebd07648900df72862" + }, + { + "$oid": "62a3a2ebd07648900df72863" + }, + { + "$oid": "62a3a2ebd07648900df72864" + }, + { + "$oid": "62a3a2ebd07648900df72865" + }, + { + "$oid": "62a3a2ebd07648900df72866" + }, + { + "$oid": "62a3a2ebd07648900df72867" + }, + { + "$oid": "62a3a2ebd07648900df72868" + }, + { + "$oid": "62a3a2ebd07648900df72869" + }, + { + "$oid": "62a3a344d07648900df7286a" + }, + { + "$oid": "62a3a344d07648900df7286b" + }, + { + "$oid": "62a3a348d07648900df7286c" + }, + { + "$oid": "62a3a349d07648900df7286d" + } + ] + } +] \ No newline at end of file diff --git a/CommBank-Server/Program.cs b/CommBank-Server/Program.cs deleted file mode 100644 index a88e560..0000000 --- a/CommBank-Server/Program.cs +++ /dev/null @@ -1,53 +0,0 @@ -using CommBank.Models; -using CommBank.Services; -using MongoDB.Driver; - -var builder = WebApplication.CreateBuilder(args); - -builder.Services.AddControllers(); - -builder.Services.AddEndpointsApiExplorer(); -builder.Services.AddSwaggerGen(); - -builder.Configuration.SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("Secrets.json"); - -var mongoClient = new MongoClient(builder.Configuration.GetConnectionString("CommBank")); -var mongoDatabase = mongoClient.GetDatabase("CommBank"); - -IAccountsService accountsService = new AccountsService(mongoDatabase); -IAuthService authService = new AuthService(mongoDatabase); -IGoalsService goalsService = new GoalsService(mongoDatabase); -ITagsService tagsService = new TagsService(mongoDatabase); -ITransactionsService transactionsService = new TransactionsService(mongoDatabase); -IUsersService usersService = new UsersService(mongoDatabase); - -builder.Services.AddSingleton(accountsService); -builder.Services.AddSingleton(authService); -builder.Services.AddSingleton(goalsService); -builder.Services.AddSingleton(tagsService); -builder.Services.AddSingleton(transactionsService); -builder.Services.AddSingleton(usersService); - -builder.Services.AddCors(); - -var app = builder.Build(); - -app.UseCors(builder => builder - .AllowAnyOrigin() - .AllowAnyMethod() - .AllowAnyHeader()); - -if (app.Environment.IsDevelopment()) -{ - app.UseSwagger(); - app.UseSwaggerUI(); -} - -app.UseHttpsRedirection(); - -app.UseAuthorization(); - -app.MapControllers(); - -app.Run(); - diff --git a/CommBank-Server/Secrets.json b/CommBank-Server/Secrets.json deleted file mode 100644 index 0e5bf94..0000000 --- a/CommBank-Server/Secrets.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "ConnectionStrings": { - "CommBank": "{CONNECTION_STRING}" - } -} \ No newline at end of file diff --git a/CommBank.Tests/GoalControllerTests.cs b/CommBank.Tests/GoalControllerTests.cs index 8380181..585712d 100644 --- a/CommBank.Tests/GoalControllerTests.cs +++ b/CommBank.Tests/GoalControllerTests.cs @@ -66,9 +66,74 @@ public async void Get() public async void GetForUser() { // Arrange + var goals = collections.GetGoals(); + var users = collections.GetUsers(); - // Act + goals[0].UserId = users[0].Id; + goals[1].UserId = users[0].Id; + goals[2].UserId = users[1].Id; - // Assert + var userGoalService = new CustomFakeGoalsService(goals); + IUsersService usersService = new FakeUsersService(users, users[0]); + GoalController controller = new(userGoalService, usersService); + + + var httpContext = new Microsoft.AspNetCore.Http.DefaultHttpContext(); + controller.ControllerContext.HttpContext = httpContext; + + var resultUser1 = await controller.GetForUser(users[0].Id!); + + var resultUser2 = await controller.GetForUser(users[1].Id!); + + var resultUser3 = await controller.GetForUser(users[2].Id!); + + Assert.NotNull(resultUser1); + Assert.Equal(2, resultUser1.Count); + Assert.Contains(resultUser1, g => g.Id == goals[0].Id); + Assert.Contains(resultUser1, g => g.Id == goals[1].Id); + Assert.DoesNotContain(resultUser1, g => g.Id == goals[2].Id); + + Assert.NotNull(resultUser2); + Assert.Equal(1, resultUser2.Count); + Assert.Contains(resultUser2, g => g.Id == goals[2].Id); + Assert.DoesNotContain(resultUser2, g => g.Id == goals[0].Id); + Assert.DoesNotContain(resultUser2, g => g.Id == goals[1].Id); + + Assert.NotNull(resultUser3); + Assert.Empty(resultUser3); } +} + +public class CustomFakeGoalsService : IGoalsService +{ + private readonly List _goals; + + public CustomFakeGoalsService(List goals) + { + _goals = goals; + } + + public async Task> GetAsync() => + await Task.FromResult(_goals); + + public async Task?> GetForUserAsync(string userId) + { + var userGoals = _goals.Where(g => g.UserId == userId).ToList(); + return await Task.FromResult(userGoals); + } + + public async Task GetAsync(string id) + { + var goal = _goals.FirstOrDefault(g => g.Id == id); + return await Task.FromResult(goal); + } + + public async Task CreateAsync(Goal newGoal) => + await Task.FromResult(true); + + public async Task UpdateAsync(string id, Goal updatedGoal) => + await Task.FromResult(true); + + public async Task RemoveAsync(string id) => + await Task.FromResult(true); } \ No newline at end of file