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
public class ProposalService | |
{ | |
public void AcceptProposal(Guid proposalId) | |
{ | |
var proposal = _repository.Find(proposalId); | |
//calling Accept method instead of changing its properties | |
proposal.Accept(); | |
_repository.Save(proposal); | |
var proposalsToDeny = _repository.FindOpenForCandidate(proposal.CandidateId); |
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 would let the Proposal aggregate to operate on other aggregates | |
public class Proposal | |
{ | |
public Candidate Candidate { get; } | |
public JobListing JobListing { get; } | |
} | |
//this is why we should refer to other aggregates by id | |
public class Proposal | |
{ |
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
var inconsistentComment = new Comment(closedProposalId, anyCandidateIdIWant, content); | |
_commentsRepository.Save(comment); |
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
public class Proposal | |
{ | |
private List<Comments> _comments; | |
public IReadOnlyList<Comments> Comments => _comments.AsReadOnly(); | |
private bool IsOpenForComments => Status == ProposalStatus.Pending; | |
public Guid CandidateId { get; } | |
public Guid JobListingId { get; } | |
public ProposaStatus Status { get; private set; } | |
public DateTime ClosedAt { get; private set; } |
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
public class Comment | |
{ | |
public Guid ProposalId { get; } | |
public Guid UserId { get; } | |
public string Content { get; private set; } | |
public Comment(Guid proposalId, Guid userId, string content) | |
{ | |
if(String.IsNullOrWhiteSpace(content)) | |
throw new DomainException("Empty comments not allowed"); |
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
public class ProposalService | |
{ | |
public void AcceptProposal(Guid proposalId) | |
{ | |
var proposal = _repository.Find(proposalId); | |
//calling Accept method instead of changing its properties | |
proposal.Accept(); | |
_repository.Save(proposal); | |
_logger.Info($"Proposal {proposal.id} was accepted"); | |
} |
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
public class ProposalService | |
{ | |
public void AcceptProposal(Guid proposalId) | |
{ | |
//retrieve proposal aggregate from repository | |
var proposal = _repository.Find(proposalId); | |
//if proposal is expired, fail fast | |
if(DateTime.Now.Substract(proprosal.SentAt).TotalDays > 15) | |
throw new DomainException("This proprosal has expired"); |
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
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var command = _mapper.ToWithrawCommand(args); | |
_accountService.WithdrawAmount(command); | |
} | |
} |
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
[Route("api/[controller]")] | |
[ApiController] | |
public class AccountController : ControllerBase | |
{ | |
[HttpPost("{id}/withdraw")] | |
public ActionResult WithdrawAmount(WithdrawAmountCommand command) | |
{ | |
_accountService.WithdrawAmount(command); | |
return Ok() | |
} |
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
public class AccountService | |
{ | |
public void WithdrawAmount(WithdrawAmountCommand command) | |
{ | |
var account = _repository.Find(command.AccountId); | |
account.Withdraw(command.Amount); | |
_logger.Info($"Client {account.OwnerId} withdrew {command.Amount}"); | |
_broker.Send(new AmountWithdrewEvent(account.Id, command.Amount)); | |
} | |
} |