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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions solution/CommBank-Server/CommBank.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<RootNamespace>CommBank_Server</RootNamespace>
<AssemblyName>CommBank-Server</AssemblyName>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.3.9" />
<PackageReference Include="Moq" Version="4.20.72" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="BCrypt.Net-Next" Version="4.0.3" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.1" />
<PackageReference Include="MongoDB.Driver" Version="2.18.0" />
<PackageReference Include="xunit" Version="2.9.3" />
</ItemGroup>

<ItemGroup>
<None Remove="Newtonsoft.Json" />
<None Remove="BCrypt.Net-Next" />
<None Remove="Microsoft.Extensions.DependencyInjection" />
<None Remove="MongoDB.Driver" />
<None Remove="Services\" />
<None Remove="Models\" />
<None Remove="Properties\" />
<None Remove="Data\" />
</ItemGroup>
<ItemGroup>
<Folder Include="Services\" />
<Folder Include="Models\" />
<Folder Include="Properties\" />
<Folder Include="Data\" />
</ItemGroup>
</Project>
72 changes: 72 additions & 0 deletions solution/CommBank-Server/Controllers/AccountController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using Microsoft.AspNetCore.Mvc;
using CommBank.Services;
using CommBank.Models;

namespace CommBank.Controllers;

[ApiController]
[Route("api/[controller]")]
public class AccountController : ControllerBase
{
private readonly IAccountsService _accountsService;

public AccountController(IAccountsService accountsService) =>
_accountsService = accountsService;

[HttpGet]
public async Task<List<Account>> Get() =>
await _accountsService.GetAsync();

[HttpGet("{id:length(24)}")]
public async Task<ActionResult<Account>> Get(string id)
{
var account = await _accountsService.GetAsync(id);

if (account is null)
{
return NotFound();
}

return account;
}

[HttpPost]
public async Task<IActionResult> Post(Account newAccount)
{
await _accountsService.CreateAsync(newAccount);

return CreatedAtAction(nameof(Get), new { id = newAccount.Id }, newAccount);
}

[HttpPut("{id:length(24)}")]
public async Task<IActionResult> Update(string id, Account updatedAccount)
{
var account = await _accountsService.GetAsync(id);

if (account is null)
{
return NotFound();
}

updatedAccount.Id = account.Id;

await _accountsService.UpdateAsync(id, updatedAccount);

return NoContent();
}

[HttpDelete("{id:length(24)}")]
public async Task<IActionResult> Delete(string id)
{
var account = await _accountsService.GetAsync(id);

if (account is null)
{
return NotFound();
}

await _accountsService.RemoveAsync(id);

return NoContent();
}
}
28 changes: 28 additions & 0 deletions solution/CommBank-Server/Controllers/AuthController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Microsoft.AspNetCore.Mvc;
using CommBank.Services;
using CommBank.Models;

namespace CommBank.Controllers;

[ApiController]
[Route("api/Auth")]
public class AuthController : ControllerBase
{
private readonly AuthService _authService;

public AuthController(AuthService authService) =>
_authService = authService;

[HttpPost("Login")]
public async Task<IActionResult> Post(LoginInput input)
{
var user = await _authService.Login(input.Email, input.Password);

if (user is null)
{
return NotFound();
}

return NoContent();
}
}
102 changes: 102 additions & 0 deletions solution/CommBank-Server/Controllers/GoalController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
using Microsoft.AspNetCore.Mvc;
using CommBank.Services;
using CommBank.Models;

namespace CommBank.Controllers;

[ApiController]
[Route("api/[controller]")]
public class GoalController : ControllerBase
{
private readonly IGoalsService _goalsService;
private readonly IUsersService _usersService;

public GoalController(IGoalsService goalsService, IUsersService usersService)
{
_goalsService = goalsService;
_usersService = usersService;
}

[HttpGet]
public async Task<List<Goal>> Get() =>
await _goalsService.GetAsync();

[HttpGet("{id:length(24)}")]
public async Task<ActionResult<Goal>> Get(string id)
{
var goal = await _goalsService.GetAsync(id);

if (goal is null)
{
return NotFound();
}

return goal;
}

[HttpGet("User/{id:length(24)}")]
public async Task<List<Goal>?> GetForUser(string id) =>
await _goalsService.GetForUserAsync(id);

[HttpPost]
public async Task<IActionResult> Post(Goal newGoal)
{
await _goalsService.CreateAsync(newGoal);

if (newGoal.Id is not null && newGoal.UserId is not null)
{
var user = await _usersService.GetAsync(newGoal.UserId);

if (user is not null && user.Id is not null)
{
if (user.GoalIds is not null)
{
user.GoalIds.Add(newGoal.Id);
}
else
{
user.GoalIds = new()
{
newGoal.Id
};
}

await _usersService.UpdateAsync(user.Id, user);
}
}

return CreatedAtAction(nameof(Get), new { id = newGoal.Id }, newGoal);
}

[HttpPut("{id:length(24)}")]
public async Task<IActionResult> Update(string id, Goal updatedGoal)
{
var goal = await _goalsService.GetAsync(id);

if (goal is null)
{
return NotFound();
}

updatedGoal.Id = goal.Id;

await _goalsService.UpdateAsync(id, updatedGoal);

return NoContent();
}

[HttpDelete("{id:length(24)}")]
public async Task<IActionResult> Delete(string id)
{
var goal = await _goalsService.GetAsync(id);

if (goal is null)
{
return NotFound();
}

await _goalsService.RemoveAsync(id);

return NoContent();
}
}
32 changes: 32 additions & 0 deletions solution/CommBank-Server/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System.Diagnostics;
using Microsoft.AspNetCore.Mvc;
using CommBank.Models;

namespace CommBank.Controllers;

public class HomeController : Controller
{
private readonly ILogger<HomeController> _logger;

public HomeController(ILogger<HomeController> logger)
{
_logger = logger;
}

public IActionResult Index()
{
return View();
}

public IActionResult Privacy()
{
return View();
}

[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}
}

71 changes: 71 additions & 0 deletions solution/CommBank-Server/Controllers/TagController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
using Microsoft.AspNetCore.Mvc;
using CommBank.Services;

namespace CommBank.Controllers;

[ApiController]
[Route("api/[controller]")]
public class TagController : ControllerBase
{
private readonly ITagsService _tagsService;

public TagController(ITagsService tagsService) =>
_tagsService = tagsService;

[HttpGet]
public async Task<List<CommBank.Models.Tag>> Get() =>
await _tagsService.GetAsync();

[HttpGet("{id:length(24)}")]
public async Task<ActionResult<CommBank.Models.Tag>> Get(string id)
{
var tag = await _tagsService.GetAsync(id);

if (tag is null)
{
return NotFound();
}

return tag;
}

[HttpPost]
public async Task<IActionResult> Post(CommBank.Models.Tag newTag)
{
await _tagsService.CreateAsync(newTag);

return CreatedAtAction(nameof(Get), new { id = newTag.Id }, newTag);
}

[HttpPut("{id:length(24)}")]
public async Task<IActionResult> Update(string id, CommBank.Models.Tag updatedTag)
{
var tag = await _tagsService.GetAsync(id);

if (tag is null)
{
return NotFound();
}

updatedTag.Id = tag.Id;

await _tagsService.UpdateAsync(id, updatedTag);

return NoContent();
}

[HttpDelete("{id:length(24)}")]
public async Task<IActionResult> Delete(string id)
{
var tag = await _tagsService.GetAsync(id);

if (tag is null)
{
return NotFound();
}

await _tagsService.RemoveAsync(id);

return NoContent();
}
}
Loading