Skip to content
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using NMoneys;
using NMoneys;
using NVs.Budget.Domain.Entities.Operations;
using NVs.Budget.Domain.ValueObjects;

Expand All @@ -9,10 +9,11 @@ public class TrackedOperation(
DateTime timestamp,
Money amount,
string description,
string notes,
Domain.Entities.Budgets.Budget budget,
IEnumerable<Tag> tags,
IReadOnlyDictionary<string, object>? attributes)
: Operation(id, timestamp, amount, description, budget, tags, attributes), ITrackableEntity<Guid>
: Operation(id, timestamp, amount, description, notes, budget, tags, attributes), ITrackableEntity<Guid>
{
public string? Version { get; set; }
public bool IsRegistered => !string.IsNullOrEmpty(Version);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using NMoneys;
using NMoneys;

namespace NVs.Budget.Application.Contracts.Entities.Accounting;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using AutoFixture;
using AutoFixture;
using FluentAssertions;
using NVs.Budget.Application.Contracts.Entities.Accounting;
using NVs.Budget.Application.Contracts.Options;
Expand Down Expand Up @@ -34,6 +34,7 @@ private List<TrackedOperation> GenerateDuplicates(TrackedOperation operation, pa
operation.Timestamp + offset,
operation.Amount,
operation.Description,
operation.Notes,
operation.Budget,
operation.Tags,
operation.Attributes.AsReadOnly()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Linq.Expressions;
using System.Linq.Expressions;
using System.Runtime.CompilerServices;
using FluentResults;
using NVs.Budget.Application.Contracts.Entities.Accounting;
Expand All @@ -18,6 +18,7 @@ public Task<Result<TrackedOperation>> Register(UnregisteredOperation operation,
operation.Timestamp,
operation.Amount,
operation.Description,
string.Empty,
budget,
Enumerable.Empty<Tag>(),
operation.Attributes)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public async Task<Result> Handle(MergeBudgetsRequest request, CancellationToken
var source = orderedBudgets[i];

var operations = reckoner.GetOperations(new(o => o.Budget.Id == source.Id), cancellationToken)
.Select(o => new TrackedOperation(o.Id, o.Timestamp, o.Amount, o.Description, sink, o.Tags, o.Attributes.AsReadOnly()){ Version = o.Version });
.Select(o => new TrackedOperation(o.Id, o.Timestamp, o.Amount, o.Description, o.Notes, sink, o.Tags, o.Attributes.AsReadOnly()){ Version = o.Version });

var updateRes = await accountant.Update(operations, sink, new(null, TaggingMode.Skip), cancellationToken);
result.Reasons.AddRange(updateRes.Reasons);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using NMoneys;
using NMoneys;
using NVs.Budget.Application.Contracts.Entities;
using NVs.Budget.Domain.Entities.Operations;
using NVs.Budget.Infrastructure.ExchangeRates.Contracts;
Expand Down Expand Up @@ -28,6 +28,7 @@ public async Task<Operation> Convert(Operation operation, Currency targetCurrenc
operation.Timestamp,
new Money(operation.Amount.Amount * rate.Rate, targetCurrency),
operation.Description,
operation.Notes,
operation.Budget,
operation.Tags.ToList(),
new Dictionary<string, object>(operation.Attributes)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Linq.Expressions;
using System.Linq.Expressions;
using System.Runtime.CompilerServices;
using NVs.Budget.Application.Contracts.Criteria;
using NVs.Budget.Application.Contracts.Entities.Accounting;
Expand Down Expand Up @@ -113,7 +113,7 @@ public async Task<IReadOnlyCollection<IReadOnlyCollection<TrackedOperation>>> Ge
private TrackedOperation AsTrackedOperation(Operation operation)
{
var result = new TrackedOperation(
operation.Id, operation.Timestamp, operation.Amount, operation.Description,
operation.Id, operation.Timestamp, operation.Amount, operation.Description, operation.Notes,
AsTrackedBudget(operation.Budget), operation.Tags, operation.Attributes.AsReadOnly()
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public record OperationResponse(
DateTime Timestamp,
MoneyResponse Amount,
string Description,
string Notes,
Guid BudgetId,
IReadOnlyCollection<string> Tags,
Dictionary<string, object>? Attributes
Expand All @@ -22,6 +23,7 @@ public record UnregisteredOperationRequest(
DateTime Timestamp,
MoneyResponse Amount,
string Description,
string? Notes,
Dictionary<string, object>? Attributes
);

Expand All @@ -31,6 +33,7 @@ public record UpdateOperationRequest(
DateTime Timestamp,
MoneyResponse Amount,
string Description,
string? Notes,
IReadOnlyCollection<string> Tags,
Dictionary<string, object>? Attributes
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public OperationResponse ToResponse(TrackedOperation operation)
operation.Timestamp,
new MoneyResponse(operation.Amount.Amount, operation.Amount.CurrencyCode.ToString()),
operation.Description,
operation.Notes,
operation.Budget.Id,
operation.Tags.Select(t => t.Value).ToList(),
operation.Attributes.Count > 0 ? new Dictionary<string, object>(operation.Attributes) : null
Expand All @@ -38,6 +39,7 @@ public OperationResponse ToResponse(Operation operation)
operation.Timestamp,
new MoneyResponse(operation.Amount.Amount, operation.Amount.CurrencyCode.ToString()),
operation.Description,
operation.Notes,
operation.Budget.Id,
operation.Tags.Select(t => t.Value).ToList(),
operation.Attributes.Count > 0 ? new Dictionary<string, object>(operation.Attributes) : null
Expand Down Expand Up @@ -82,6 +84,7 @@ public Result<TrackedOperation> FromRequest(UpdateOperationRequest request, Trac
request.Timestamp,
moneyResult.Value,
request.Description,
request.Notes ?? string.Empty,
budget,
tags,
attributes
Expand Down
6 changes: 4 additions & 2 deletions src/Domain/NVs.Budget.Domain/Entities/Operations/Operation.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Diagnostics;
using System.Diagnostics;
using NMoneys;
using NVs.Budget.Domain.ValueObjects;

Expand All @@ -12,17 +12,19 @@ public class Operation : EntityBase<Guid>
public DateTime Timestamp { get; }
public Money Amount { get; }
public string Description { get; }
public string Notes { get; }
public Budgets.Budget Budget { get; }

public IReadOnlyCollection<Tag> Tags => _tags.AsReadOnly();

public IDictionary<string, object> Attributes { get; } = new AttributesDictionary(new Dictionary<string, object>());

public Operation(Guid id, DateTime timestamp, Money amount, string description, Budgets.Budget budget, IEnumerable<Tag> tags, IReadOnlyDictionary<string, object>? attributes) : base(id)
public Operation(Guid id, DateTime timestamp, Money amount, string description, string notes, Budgets.Budget budget, IEnumerable<Tag> tags, IReadOnlyDictionary<string, object>? attributes) : base(id)
{
Timestamp = timestamp;
Amount = amount;
Description = description;
Notes = notes;
Budget = budget;

if (attributes != null)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections;
using System.Collections;
using System.Diagnostics;
using NMoneys;
using NVs.Budget.Domain.Entities.Operations;
Expand Down Expand Up @@ -110,7 +110,7 @@ public Operation AsTransaction()
{ nameof(Sink), Sink.Id }
};

return new Operation(Guid.Empty, timestamp, amount, description, budget, tags, attributes);
return new Operation(Guid.Empty, timestamp, amount, description, string.Empty, budget, tags, attributes);
}

public IEnumerator<Operation> GetEnumerator() => new Enumerator(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export interface OperationResponse {
timestamp: string;
amount: MoneyResponse;
description: string;
notes: string;
budgetId: string;
tags: string[];
attributes?: Record<string, any>;
Expand All @@ -102,6 +103,7 @@ export interface UpdateOperationRequest {
timestamp: string;
amount: MoneyResponse;
description: string;
notes: string;
tags: string[];
attributes?: Record<string, any>;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ <h4>Duplicate Group {{ groupIdx + 1 }} ({{ group.length }} operations)</h4>
[operations]="group"
[showActions]="true"
(operationDeleted)="onDeleteOperation($event)"
(operationUpdated)="onUpdateOperation($event)">
(operationUpdated)="onUpdateOperation($event)"
(operationNoteUpdated)="onUpdateOperationNote($event)">
</app-operations-table>
</div>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,5 +147,43 @@ export class DuplicatesListComponent implements OnInit {
}
});
}

onUpdateOperationNote(operation: OperationResponse): void {
const current = this.findOperation(operation.id);
const previousNotes = current?.notes ?? '';

this.operationsHelper.updateOperation(this.budgetId, operation).subscribe({
next: (result) => {
if (result.errors && result.errors.length > 0) {
const errorMessage = result.errors.map(e => e.message || 'Unknown error').join('; ');
this.notificationService.showError(`Failed to update notes: ${errorMessage}`).subscribe();
if (current) {
current.notes = previousNotes;
}
return;
}

const updatedOperation = result.updatedOperations?.[0] ?? operation;
this.replaceOperation(updatedOperation);
},
error: (error) => {
const errorMessage = this.notificationService.handleError(error, 'Failed to update notes');
this.notificationService.showError(errorMessage).subscribe();
if (current) {
current.notes = previousNotes;
}
}
});
}

private replaceOperation(updated: OperationResponse): void {
this.duplicateGroups = this.duplicateGroups.map(group =>
group.map(item => item.id === updated.id ? updated : item)
);
}

private findOperation(operationId: string): OperationResponse | undefined {
return this.duplicateGroups.flat().find(operation => operation.id === operationId);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ <h2 tuiTitle size="l">{{ groupTitle }}</h2>
[operations]="operations"
[showActions]="true"
(operationDeleted)="onDeleteOperation($event)"
(operationUpdated)="onUpdateOperation($event)">
(operationUpdated)="onUpdateOperation($event)"
(operationNoteUpdated)="onUpdateOperationNote($event)">
</app-operations-table>
</div>
} @else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,5 +182,35 @@ export class LogbookGroupComponent implements OnInit {
}
});
}

onUpdateOperationNote(operation: OperationResponse): void {
const current = this.operations.find(o => o.id === operation.id);
const previousNotes = current?.notes ?? '';

this.operationsHelper.updateOperation(this.budgetId, operation).subscribe({
next: (result) => {
if (result.errors && result.errors.length > 0) {
const errorMessage = result.errors.map(e => e.message || 'Unknown error').join('; ');
this.notificationService.showError(`Failed to update notes: ${errorMessage}`).subscribe();
if (current) {
current.notes = previousNotes;
}
return;
}

const updatedOperation = result.updatedOperations?.[0] ?? operation;
this.operations = this.operations.map(item =>
item.id === updatedOperation.id ? updatedOperation : item
);
},
error: (error) => {
const errorMessage = this.notificationService.handleError(error, 'Failed to update notes');
this.notificationService.showError(errorMessage).subscribe();
if (current) {
current.notes = previousNotes;
}
}
});
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ <h2 tuiTitle size="l">Operations</h2>
[operations]="operations"
[showActions]="true"
(operationDeleted)="onDeleteOperation($event)"
(operationUpdated)="onUpdateOperation($event)">
(operationUpdated)="onUpdateOperation($event)"
(operationNoteUpdated)="onUpdateOperationNote($event)">
</app-operations-table>

<div class="operations-count">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,34 @@ export class OperationsListComponent implements OnInit {
}
});
}

onUpdateOperationNote(operation: OperationResponse): void {
const current = this.operations.find(o => o.id === operation.id);
const previousNotes = current?.notes ?? '';

this.operationsHelper.updateOperation(this.budgetId, operation).subscribe({
next: (result) => {
if (result.errors && result.errors.length > 0) {
const errorMessage = result.errors.map(e => e.message || 'Unknown error').join('; ');
this.notificationService.showError(`Failed to update notes: ${errorMessage}`).subscribe();
if (current) {
current.notes = previousNotes;
}
return;
}

const updatedOperation = result.updatedOperations?.[0] ?? operation;
this.operations = this.operations.map(item =>
item.id === updatedOperation.id ? updatedOperation : item
);
},
error: (error) => {
const errorMessage = this.notificationService.handleError(error, 'Failed to update notes');
this.notificationService.showError(errorMessage).subscribe();
if (current) {
current.notes = previousNotes;
}
}
});
}
}
Loading