-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#397 - Write side for expense templates.
- Loading branch information
Showing
13 changed files
with
382 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using Neptuo; | ||
using Neptuo.Commands; | ||
using Neptuo.Models.Keys; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Money.Commands | ||
{ | ||
/// <summary> | ||
/// Creates a new expense template. | ||
/// </summary> | ||
public class CreateExpenseTemplate : Command | ||
{ | ||
/// <summary> | ||
/// Gets an amount of the expense template. | ||
/// </summary> | ||
public Price Amount { get; private set; } | ||
|
||
/// <summary> | ||
/// Gets a description of the expense template. | ||
/// </summary> | ||
public string Description { get; private set; } | ||
|
||
/// <summary> | ||
/// Gets a category of the expense template. | ||
/// </summary> | ||
public IKey CategoryKey { get; private set; } | ||
|
||
/// <summary> | ||
/// Creates a new command for adding an expense template. | ||
/// </summary> | ||
/// <param name="amount">An amount of the expense template.</param> | ||
/// <param name="description">A description of the expense template.</param> | ||
/// <param name="when">A category of the expense template.</param> | ||
public CreateExpenseTemplate(Price amount, string description, IKey categoryKey) | ||
{ | ||
Ensure.NotNull(categoryKey, "categoryKey"); | ||
Amount = amount; | ||
Description = description; | ||
CategoryKey = categoryKey; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using Neptuo; | ||
using Neptuo.Commands; | ||
using Neptuo.Models.Keys; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Money.Commands | ||
{ | ||
/// <summary> | ||
/// Deletes an expense template. | ||
/// </summary> | ||
public class DeleteExpenseTemplate : Command | ||
{ | ||
/// <summary> | ||
/// Gets a key of the expense template to delete. | ||
/// </summary> | ||
public IKey ExpenseTemplateKey { get; private set; } | ||
|
||
/// <summary> | ||
/// Deletes an outcome with <paramref name="expenseTemplateKey"/>. | ||
/// </summary> | ||
/// <param name="expenseTemplateKey">A key of the expense template to delete.</param> | ||
public DeleteExpenseTemplate(IKey expenseTemplateKey) | ||
{ | ||
Ensure.Condition.NotEmptyKey(expenseTemplateKey); | ||
ExpenseTemplateKey = expenseTemplateKey; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using Neptuo; | ||
using Neptuo.Activators; | ||
using Neptuo.Commands.Handlers; | ||
using Neptuo.Models.Keys; | ||
using Neptuo.Models.Repositories; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Money.Commands.Handlers | ||
{ | ||
public class ExpenseTemplateHandler : AggregateRootCommandHandler<ExpenseTemplate>, | ||
ICommandHandler<Envelope<CreateExpenseTemplate>>, | ||
ICommandHandler<Envelope<DeleteExpenseTemplate>> | ||
{ | ||
public ExpenseTemplateHandler(IFactory<IRepository<ExpenseTemplate, IKey>> repositoryFactory) | ||
: base(repositoryFactory) | ||
{ } | ||
|
||
public Task HandleAsync(Envelope<CreateExpenseTemplate> envelope) => WithCommand(envelope.Body.Key).Execute(envelope, () => new ExpenseTemplate(envelope.Body.Amount, envelope.Body.Description, envelope.Body.CategoryKey)); | ||
public Task HandleAsync(Envelope<DeleteExpenseTemplate> envelope) => WithCommand(envelope.Body.Key).Execute(envelope.Body.ExpenseTemplateKey, envelope, model => model.Delete()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using Neptuo; | ||
using Neptuo.Models.Keys; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Money.Events | ||
{ | ||
/// <summary> | ||
/// An event raised when new a expense template is created. | ||
/// </summary> | ||
public class ExpenseTemplateCreated : UserEvent | ||
{ | ||
/// <summary> | ||
/// Gets a amount of the expense template. | ||
/// </summary> | ||
public Price Amount { get; private set; } | ||
|
||
/// <summary> | ||
/// Gets a description of the expense template. | ||
/// </summary> | ||
public string Description { get; private set; } | ||
|
||
/// <summary> | ||
/// Gets a category of the expense template. | ||
/// </summary> | ||
public IKey CategoryKey { get; set; } | ||
|
||
internal ExpenseTemplateCreated(Price amount, string description, IKey categoryKey) | ||
{ | ||
Ensure.NotNull(categoryKey, "categoryKey"); | ||
Amount = amount; | ||
Description = description; | ||
CategoryKey = categoryKey; | ||
} | ||
} | ||
} |
Oops, something went wrong.