-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3ebdf88
commit 96cf265
Showing
4 changed files
with
68 additions
and
2 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
41 changes: 41 additions & 0 deletions
41
apps/releaf/backend/Releaf.Application/Query/GetBoxesQuery.cs
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,41 @@ | ||
using MediatR; | ||
using Releaf.Domain.Boxes; | ||
using Releaf.Domain.Repo; | ||
using Releaf.Shared; | ||
|
||
namespace Releaf.Application.Query; | ||
|
||
public class GetBoxesQuery : IRequest<IEnumerable<BoxAggregate>> | ||
{ | ||
public GetBoxesQuery(UserId ownerId) | ||
{ | ||
OwnerId = ownerId; | ||
} | ||
|
||
public UserId OwnerId { get; } | ||
} | ||
|
||
public class GetBoxesQueryHandler : IRequestHandler<GetBoxesQuery, IEnumerable<BoxAggregate>> | ||
{ | ||
public GetBoxesQueryHandler(IBoxRepo boxRepo, ITreeRepo treeRepo) | ||
{ | ||
BoxRepo = boxRepo; | ||
TreeRepo = treeRepo; | ||
} | ||
|
||
public IBoxRepo BoxRepo { get; } | ||
public ITreeRepo TreeRepo { get; } | ||
|
||
public Task<IEnumerable<BoxAggregate>> Handle(GetBoxesQuery request, CancellationToken cancellationToken) | ||
{ | ||
var boxAggregate = BoxRepo.GetBoxesForUser(request.OwnerId); | ||
|
||
foreach (var item in boxAggregate) | ||
{ | ||
var treeDefinition = TreeRepo.GetOne(item.TreeDefinitionId); | ||
item.ChangeTreeDefinition(treeDefinition); | ||
} | ||
|
||
return Task.FromResult(boxAggregate); | ||
} | ||
} |
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
10 changes: 10 additions & 0 deletions
10
apps/releaf/backend/Releaf.Domain/Exceptions/InvalidTreeDefinitionException.cs
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 @@ | ||
using Releaf.Shared; | ||
|
||
namespace Releaf.Domain.Exceptions; | ||
|
||
public class TreeDefinitionNotFoundException : DomainException | ||
{ | ||
public TreeDefinitionNotFoundException() : base($"Tree definition was not found") | ||
{ | ||
} | ||
} |