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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -403,5 +403,5 @@ ASALocalRun/

# Local History for Visual Studio
.localhistory/

Secrets.json

147 changes: 127 additions & 20 deletions CommBank-Server/Controllers/TransactionController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,68 +9,175 @@ namespace CommBank.Controllers;
public class TransactionController : ControllerBase
{
private readonly ITransactionsService _transactionsService;
private readonly ITagsService _tagsService;

public TransactionController(ITransactionsService transactionsService) =>

public TransactionController(
ITransactionsService transactionsService,
ITagsService tagsService)
{
_transactionsService = transactionsService;
_tagsService = tagsService;
}



[HttpGet]
public async Task<List<Transaction>> Get() =>
await _transactionsService.GetAsync();
public async Task<List<Transaction>> Get()
{
var transactions = await _transactionsService.GetAsync();


foreach(var transaction in transactions)
{
transaction.Tags = new List<Tag>();


if(transaction.TagIds != null)
{
foreach(var tagId in transaction.TagIds)
{
var tag = await _tagsService.GetAsync(tagId);


if(tag != null)
{
transaction.Tags.Add(tag);
}
}
}
}


return transactions;
}





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



if(transactions == null)
return null;



foreach(var transaction in transactions)
{
transaction.Tags = new List<Tag>();


if(transaction.TagIds != null)
{
foreach(var tagId in transaction.TagIds)
{
var tag = await _tagsService.GetAsync(tagId);


if(tag != null)
{
transaction.Tags.Add(tag);
}
}
}
}


return transactions;
}





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

if (transaction is null)
{

if(transaction == null)
return NotFound();
}


return transaction;
}





[HttpPost]
public async Task<IActionResult> Post(Transaction newTransaction)
{
await _transactionsService.CreateAsync(newTransaction);

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





[HttpPut("{id:length(24)}")]
public async Task<IActionResult> Update(string id, Transaction updatedTransaction)
public async Task<IActionResult> Update(
string id,
Transaction updatedTransaction)
{
var transaction = await _transactionsService.GetAsync(id);
var transaction =
await _transactionsService.GetAsync(id);

if (transaction is null)
{


if(transaction == null)
return NotFound();
}



updatedTransaction.Id = transaction.Id;

await _transactionsService.UpdateAsync(id, updatedTransaction);

await _transactionsService.UpdateAsync(
id,
updatedTransaction
);


return NoContent();
}





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

if (transaction is null)
{


if(transaction == null)
return NotFound();
}



await _transactionsService.RemoveAsync(id);


return NoContent();
}
}
2 changes: 2 additions & 0 deletions CommBank-Server/Models/Goal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public class Goal

public string? Name { get; set; }

public string? Icon { get; set; }

public UInt64 TargetAmount { get; set; } = 0;

public DateTime TargetDate { get; set; }
Expand Down
15 changes: 15 additions & 0 deletions CommBank-Server/Models/Transaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,37 @@ public class Transaction
[BsonRepresentation(BsonType.ObjectId)]
public string? Id { get; set; }


[JsonConverter(typeof(JsonStringEnumConverter))]
[BsonRepresentation(BsonType.String)]
public TransactionType TransactionType { get; set; }


public double Amount { get; set; } = 0.00;


public DateTime DateTime { get; set; } = DateTime.Now;


[BsonRepresentation(BsonType.ObjectId)]
public string? GoalId { get; set; }


[BsonRepresentation(BsonType.ObjectId)]
public string? UserId { get; set; }


[BsonRepresentation(BsonType.ObjectId)]
public string[]? TagIds { get; set; }



// NEW FIELD
// This will be filled from backend
[BsonIgnore]
public List<Tag> Tags { get; set; } = new();



public string? Description { get; set; }
}
5 changes: 0 additions & 5 deletions CommBank-Server/Secrets.json

This file was deleted.

Loading