-
Notifications
You must be signed in to change notification settings - Fork 1
Reset funds endpoint #100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Reset funds endpoint #100
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -97,7 +97,7 @@ public async Task<ActionResult<ApiResponse<string>>> BobsYourUncle() | |
| try | ||
| { | ||
| this.logger.LogInformation($"{this.User.Identity?.Name} | POST Financial/bobsYourUncle"); | ||
|
|
||
| // ReSharper disable AssignNullToNotNullAttribute | ||
| var user = await this.userManager.FindByNameAsync(this.User.Identity?.Name); | ||
| if (user == null) | ||
|
|
@@ -133,6 +133,57 @@ public async Task<ActionResult<ApiResponse<string>>> BobsYourUncle() | |
| } | ||
| } | ||
|
|
||
| /// ------------------------------------------------------------------------------------------------- | ||
| /// <summary> | ||
| /// Resets user balance | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// Damir, 29/11/2023 | ||
| /// </remarks> | ||
| /// <returns> | ||
| /// An asynchronous result that yields the account balances. | ||
| /// </returns> | ||
| /// ------------------------------------------------------------------------------------------------- | ||
| [HttpPost("resetFunds", Name = "ResetFunds")] | ||
| public async Task<ActionResult<ApiResponse<string>>> ResetFunds() | ||
| { | ||
| try | ||
| { | ||
| this.logger.LogInformation($"{this.User.Identity?.Name} | POST Financial/resetFunds"); | ||
|
|
||
| // ReSharper disable AssignNullToNotNullAttribute | ||
| var user = await this.userManager.FindByNameAsync(this.User.Identity?.Name); | ||
| if (user == null) | ||
| { | ||
| return new ApiResponse<string> { Message = "Unable to find user record!", IsError = true }; | ||
| } | ||
|
|
||
| var resetRecord = new FinancialRecord | ||
| { | ||
| ID = Guid.NewGuid(), | ||
| Timestamp = DateTime.UtcNow, | ||
| UserID = user.Id, | ||
| Category = FinancialCategory.None, | ||
| Expense = user.PersonalAccountBalance - user.PersonalAccountBalance, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That will just set the Expense to 0, just set user.PersonalAccountBalance here |
||
| Description = "Funds have been reset" | ||
| }; | ||
| await this.db.FinancialRecords.AddAsync(resetRecord); | ||
|
|
||
| var saveEx = await this.db.SaveDatabaseChangesAsync(this.logger, "Failed to reset funds"); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Before saving the changes you also need to actually adjust the user's balance. The financial record above is just the trace record of what happened. user.PersonalAccountBalance = 0; |
||
| if (saveEx != null) | ||
| { | ||
| throw saveEx; | ||
| } | ||
|
|
||
| return new ApiResponse<string>("Funds have been successfully reset!"); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| this.logger.LogError(ex, $"{this.User.Identity?.Name} | POST Financial/resetFunds"); | ||
| return new ApiResponse<string>(ex); | ||
| } | ||
| } | ||
|
|
||
| /// ------------------------------------------------------------------------------------------------- | ||
| /// <summary> | ||
| /// Get the current account balances. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it yields a status string