-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(#87) add endpoint for getting all suborganizations ids
- Loading branch information
Showing
4 changed files
with
59 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
11 changes: 11 additions & 0 deletions
11
...s/src/MiniSpace.Services.Organizations.Application/Queries/GetAllChildrenOrganizations.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,11 @@ | ||
using Convey.CQRS.Queries; | ||
using MiniSpace.Services.Organizations.Application.DTO; | ||
|
||
namespace MiniSpace.Services.Organizations.Application.Queries | ||
{ | ||
public class GetAllChildrenOrganizations: IQuery<IEnumerable<Guid>> | ||
{ | ||
public Guid ParentId { get; set; } | ||
public Guid RootId { get; 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
29 changes: 29 additions & 0 deletions
29
...Organizations.Infrastructure/Mongo/Queries/Handlers/GetAllChildrenOrganizationsHandler.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,29 @@ | ||
using Convey.CQRS.Queries; | ||
using Convey.Persistence.MongoDB; | ||
using MiniSpace.Services.Organizations.Application.Queries; | ||
using MiniSpace.Services.Organizations.Core.Entities; | ||
using MiniSpace.Services.Organizations.Infrastructure.Mongo.Documents; | ||
|
||
namespace MiniSpace.Services.Organizations.Infrastructure.Mongo.Queries.Handlers | ||
{ | ||
public class GetAllChildrenOrganizationsHandler : IQueryHandler<GetAllChildrenOrganizations, IEnumerable<Guid>> | ||
{ | ||
private readonly IMongoRepository<OrganizationDocument, Guid> _repository; | ||
|
||
public GetAllChildrenOrganizationsHandler(IMongoRepository<OrganizationDocument, Guid> repository) | ||
=> _repository = repository; | ||
|
||
public async Task<IEnumerable<Guid>> HandleAsync(GetAllChildrenOrganizations query, CancellationToken cancellationToken) | ||
{ | ||
var root = await _repository.GetAsync(o => o.Id == query.RootId); | ||
var organization = root?.AsEntity().GetSubOrganization(query.ParentId); | ||
var result = new List<Guid>(); | ||
if (organization != null) | ||
{ | ||
result.AddRange(Organization.FindAllChildrenOrganizations(organization)); | ||
} | ||
|
||
return result; | ||
} | ||
} | ||
} |