Skip to content

Commit

Permalink
feat : add price and currency valueObjects
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikoo-Asadnejad committed Oct 28, 2023
1 parent c2dc672 commit 8ee1ba9
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Src/Product.Domain/ValueObjects/Currency.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Product.Domain.ValueObjects;

public class Currency : ValueObject
{
public string Value { get; private set; }

Check warning on line 5 in Src/Product.Domain/ValueObjects/Currency.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Value' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
protected override IEnumerable<object> GetEqualityComponents()
{
throw new NotImplementedException();
}
}
30 changes: 30 additions & 0 deletions Src/Product.Domain/ValueObjects/Price.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using Product.Domain.Exceptions;

namespace Product.Domain.ValueObjects;

public class Price : ValueObject
{
public int Value { get; private set; }
public Currency Currency { get; private set; }

public Price()

Check warning on line 10 in Src/Product.Domain/ValueObjects/Price.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Currency' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
{

}
protected override IEnumerable<object> GetEqualityComponents()
{
throw new NotImplementedException();
}

private void SetValue(int value)
{
if (value is 0)
throw new DomainValidationException("price can not be 0");

if(value < 0)
throw new DomainValidationException("price can not be negative");

Value = value;
}

}

0 comments on commit 8ee1ba9

Please sign in to comment.