Skip to content
Open
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added .vs/InvestmentAPINuix-JBF/v17/.futdcache.v2
Binary file not shown.
Binary file added .vs/InvestmentAPINuix-JBF/v17/.suo
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"appService.preDeployTask": "publish-release",
"appService.deploySubpath": "InvestmentAPINuix-JBF\\bin\\Release\\net8.0\\publish",
"appService.defaultWebAppToDeploy": "/subscriptions/3c349cea-ce75-4173-9d91-73c0e43b9c74/resourceGroups/DB_Resources/providers/Microsoft.Web/sites/InvestmentAPINuixChallenge"
}
32 changes: 32 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "clean",
"command": "dotnet",
"type": "process",
"args": [
"clean",
"${workspaceFolder}/InvestmentAPINuix-JBF",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish-release",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"${workspaceFolder}/InvestmentAPINuix-JBF",
"--configuration",
"Release",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile",
"dependsOn": "clean"
}
]
}
10 changes: 10 additions & 0 deletions InvestmentAPINuix-JBF/Classes/APIError.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace InvestmentAPINuix_JBF.Classes
{
public class APIError
{
public int Status { get; set; }
public string Error { get; set; } = string.Empty;
public string ErrorMessage { get; set; } = string.Empty;
public DateTime Timestamp { get; set; }
}
}
74 changes: 74 additions & 0 deletions InvestmentAPINuix-JBF/Classes/InvestmentHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using InvestmentAPINuix_JBF.Models;

namespace InvestmentAPINuix_JBF.Classes
{
public static class InvestmentHelper
{
//Used to get all investments + details of those investments associated to the user
public static List<Investment> GetInvestmentByUser (InvestmentAPIDatabase ctx, int userId)
{


List<Investment> foundInvestments =
(
from
inv
in
ctx.Investments

where
inv.Investor == userId

select
inv
).ToList();

return foundInvestments;
}
//Used for finding just the investment id and name
public static List<Object> GetOnlyInvestmentById (InvestmentAPIDatabase ctx, int userId)
{


List<Object> foundInvestment =
(
from
inv
in
ctx.Investments

where
inv.Investor == userId
select
new{
inv.Id, inv.Company
}

).ToList<Object>();

return foundInvestment;
}

//Used to find details related to an investment by supplying the investment ID
public static List<Investment> GetInvestmentDetailsById (InvestmentAPIDatabase ctx, int invId)
{


List<Investment> foundInvestmentDetails =
(
from
inv
in
ctx.Investments

where
inv.Id == invId

select
inv
).ToList();

return foundInvestmentDetails;
}
}
}
25 changes: 25 additions & 0 deletions InvestmentAPINuix-JBF/Classes/UserHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using InvestmentAPINuix_JBF.Models;

namespace InvestmentAPINuix_JBF.Classes
{
public static class UserHelper
{
public static List<User> GetAllUsers(InvestmentAPIDatabase ctx)
{


List<User> users =
(
from
user
in
ctx.Users

select user

).ToList();

return users;
}
}
}
121 changes: 121 additions & 0 deletions InvestmentAPINuix-JBF/Controllers/InvestmentDataController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
using InvestmentAPINuix_JBF.Classes;
using InvestmentAPINuix_JBF.Models;
using Microsoft.AspNetCore.Mvc;

namespace InvestmentAPINuix_JBF.API
{
[ApiController]
[Route("~/api/[controller]")]
public class InvestmentDataController: Controller
{
private InvestmentAPIDatabase _dbContext;
private readonly ILogger<InvestmentDataController> _logger;

public InvestmentDataController(InvestmentAPIDatabase dbContext, ILogger<InvestmentDataController> logger)
{
_dbContext = dbContext;
_logger = logger;
}

// api/investmentdata/userId
[HttpGet("{userId}")]
public ActionResult<Investment> GetAllInvestmentsForUser(int userId)
{
try
{
List<Investment> investment = InvestmentHelper.GetInvestmentByUser(_dbContext, userId);
if (investment == null || !investment.Any())
{
_logger.LogWarning("No Investments Found for UserId: " + userId);
return NoContent();
}
else
{
return Ok(investment);
}
}

catch (Exception ex)
{
_logger.LogError(ex, "An error occured when searching for invesments for UserId: " + userId);
APIError error = new APIError{
Status = 500,
Error = "An error occured when searching for investments for UserId: " + userId,
ErrorMessage = ex.Message,
Timestamp = DateTime.Now,
};

return StatusCode(500, error);

}

}
// api/investmentdata/nameIdOnly/userId
[HttpGet("nameIdOnly/{userId}")]
public ActionResult<Investment> GetNameIdFromOfInvestment(int userId)
{
try
{
List<Object> investment = InvestmentHelper.GetOnlyInvestmentById(_dbContext, userId);
if (investment == null)
{
_logger.LogWarning("No Investments Found for UserId: " + userId);
return NoContent();
}
else
{
return Ok(investment);
}
}

catch (Exception ex)
{
_logger.LogError(ex, "An error occured when searching for invesments for UserId: " + userId);
APIError error = new APIError{
Status = 500,
Error = "An error occured when searching for investments for UserId: " + userId,
ErrorMessage = ex.Message,
Timestamp = DateTime.Now,
};

return StatusCode(500, error);

}

}
// api/investmentdata/details/invId
[HttpGet("details/{invId}")]
public ActionResult<Investment> GetDetailsForInvestment(int invId)
{
try
{
List<Investment> investment = InvestmentHelper.GetInvestmentDetailsById(_dbContext, invId);
if (investment == null)
{
_logger.LogWarning("No Investment Details Found with this id: " + invId);
return NoContent();
}
else
{
return Ok(investment);
}
}

catch (Exception ex)
{
_logger.LogError(ex, "An error occured when searching for details on investment id: " + invId);
APIError error = new APIError{
Status = 500,
Error = "An error occured when searching for details for investment id: " + invId,
ErrorMessage = ex.Message,
Timestamp = DateTime.Now,
};

return StatusCode(500, error);

}

}

}
}
60 changes: 60 additions & 0 deletions InvestmentAPINuix-JBF/Controllers/UserDataController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using InvestmentAPINuix_JBF.Classes;
using InvestmentAPINuix_JBF.Models;
using Microsoft.AspNetCore.Mvc;

namespace InvestmentAPINuix_JBF.API
{
[ApiController]
[Route("~/api/[controller]")]
public class UserDataController: Controller
{
private InvestmentAPIDatabase _dbContext;
private readonly ILogger<UserDataController> _logger;

public UserDataController(InvestmentAPIDatabase dbContext, ILogger<UserDataController> logger)
{
_dbContext = dbContext;
_logger = logger;
}

// api/userdata
[HttpGet("")]
public ActionResult<User> GetAllUsers()
{
try
{
List<User> users = UserHelper.GetAllUsers(_dbContext);
if (users == null)
{
//Log that no users were found
_logger.LogWarning("No Users Found");
return NoContent();
}
else
{

return Ok(users);
}
}

catch (Exception ex)
{
//Log The Error
_logger.LogError(ex, "An error occured while fetching the users");


APIError error = new APIError{
Status = 500,
Error = "An error occured when loading the users",
ErrorMessage = ex.Message,
Timestamp = DateTime.Now,
};

return StatusCode(500, error);

}

}

}
}
36 changes: 36 additions & 0 deletions InvestmentAPINuix-JBF/InvestmentAPINuix-JBF.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<RootNamespace>InvestmentAPINuix_JBF</RootNamespace>
<GenerateProgramFile>false</GenerateProgramFile>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCOre.Cors" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.2.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="9.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="moq" Version="4.20.72" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

</Project>
6 changes: 6 additions & 0 deletions InvestmentAPINuix-JBF/InvestmentAPINuix-JBF.csproj.user
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ActiveDebugProfile>https</ActiveDebugProfile>
</PropertyGroup>
</Project>
Loading