-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat : add price and currency valueObjects
- Loading branch information
1 parent
c2dc672
commit 8ee1ba9
Showing
2 changed files
with
40 additions
and
0 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
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; } | ||
protected override IEnumerable<object> GetEqualityComponents() | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} |
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,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() | ||
{ | ||
|
||
} | ||
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; | ||
} | ||
|
||
} |