Skip to content
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

Adding support for batch of assets calculated in one post resolving #18. #30

Merged
merged 1 commit into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions Controllers/CalculateController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,83 @@ public CalculateController(ILogger<CalculateController> logger)
_logger = logger;
}

/// <summary>
/// Returns an array of Assets with calculated Accounting and Tax Depreciation 'tables' along with the asset information originally submitted.
/// </summary>
/// <remarks>
/// Sample Request:
///
/// POST /Calculate/DepreciateArray?GaapMethod=SL&amp;TaxMethod=MACRSHY
/// [
/// {
/// "name": "New Asset",
/// "purchaseDate": "2011-01-01",
/// "purchasePrice": 1000,
/// "residualValue": 0,
/// "section179": 0,
/// "usefulLife": 5,
/// "taxLife": 5
/// },
/// {
/// "name": "New Asset",
/// "purchaseDate": "2011-01-01",
/// "purchasePrice": 1000,
/// "residualValue": 0,
/// "section179": 0,
/// "usefulLife": 5,
/// "taxLife": 5
/// }
/// ]
/// </remarks>
/// <param name="assets">Array of Asset JSON dictionaries in the body of the post</param>
/// <param name="GaapMethod" example="SL">GAAP Depreciation Method (SL, DB200, DB150 OR SYD)</param>
/// <param name="TaxMethod" example="MACRSHY">Tax Depreciation Method (MACRSHY or MACRSMQ)</param>
/// <returns>Array of Asset objects with both accounting and tax depreciation calculations added</returns>
/// <response code="200">Returns array of asset objects</response>
/// <response code="422">If GAAP Method, Tax Method or Tax Life are invalid</response>
/// <response code="500">Any other error</response>
[HttpPost]
[ProducesResponseType(StatusCodes.Status201Created)]
[ProducesResponseType(StatusCodes.Status422UnprocessableEntity)]
[Route("[controller]/DepreciateArray")]
public ActionResult<Asset[]> PostDepreciateArray([FromBody]Asset[] assets, [RequiredFromQuery] string GaapMethod, [RequiredFromQuery] string TaxMethod)
{
foreach(Asset asset in assets)
{
switch(GaapMethod)
{
case "SL":
asset.calcSL();
break;
case "DB200":
asset.calcDB200();
break;
case "DB150":
asset.calcDB150();
break;
case "SYD":
asset.calcSYD();
break;
default:
throw new Exception("INVALID_GAAP_METHOD");
}

switch(TaxMethod)
{
case "MACRSHY":
asset.calcMacrsHY();
break;
case "MACRSMQ":
asset.calcMacrsMQ();
break;
default:
throw new Exception("INVALID_TAX_METHOD");
}
}

return assets;
}

/// <summary>
/// Returns an Asset with calculated Accounting and Tax Depreciation 'tables' along with the asset information originally submitted.
/// </summary>
Expand Down
30 changes: 29 additions & 1 deletion test/manualTesting.http
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,32 @@ Authorization: Basic testUser:testPassword
"section179": 0,
"usefulLife": 5,
"taxLife": 7
}
}


############################################
# Full Array/Batch Calculation via JSON POST
# ==========================================
POST http://localhost:5000/Calculate/DepreciateArray?GaapMethod=SL&TaxMethod=MACRSHY
Content-Type: application/json

[
{
"name": "New Asset",
"purchaseDate": "2011-01-01",
"purchasePrice": 1000,
"residualValue": 0,
"section179": 0,
"usefulLife": 5,
"taxLife": 5
},
{
"name": "New Asset 2",
"purchaseDate": "2001-01-01",
"purchasePrice": 2000,
"residualValue": 0,
"section179": 0,
"usefulLife": 7,
"taxLife": 7
}
]
Loading