diff --git a/MiniSpace.Services.Organizations/src/MiniSpace.Services.Organizations.Application/Commands/Handlers/AddOrganizationHandler.cs b/MiniSpace.Services.Organizations/src/MiniSpace.Services.Organizations.Application/Commands/Handlers/AddOrganizationHandler.cs index d7504b46f..ede5a3d92 100644 --- a/MiniSpace.Services.Organizations/src/MiniSpace.Services.Organizations.Application/Commands/Handlers/AddOrganizationHandler.cs +++ b/MiniSpace.Services.Organizations/src/MiniSpace.Services.Organizations.Application/Commands/Handlers/AddOrganizationHandler.cs @@ -32,6 +32,8 @@ public async Task HandleAsync(AddOrganization command, CancellationToken cancell { throw new ParentOrganizationNotFoundException(command.ParentId); } + parent.MakeParent(); + await _organizationRepository.UpdateAsync(parent); } await _organizationRepository.AddAsync(organization); } diff --git a/MiniSpace.Services.Organizations/src/MiniSpace.Services.Organizations.Application/Dto/OrganizationDto.cs b/MiniSpace.Services.Organizations/src/MiniSpace.Services.Organizations.Application/Dto/OrganizationDto.cs index fed6c1795..50ee020cc 100644 --- a/MiniSpace.Services.Organizations/src/MiniSpace.Services.Organizations.Application/Dto/OrganizationDto.cs +++ b/MiniSpace.Services.Organizations/src/MiniSpace.Services.Organizations.Application/Dto/OrganizationDto.cs @@ -5,7 +5,7 @@ public class OrganizationDto public Guid Id { get; set; } public string Name { get; set; } public Guid ParentId { get; set; } - public int MemberCount { get; set; } + public bool IsLeaf { get; set; } } } diff --git a/MiniSpace.Services.Organizations/src/MiniSpace.Services.Organizations.Core/Entities/Organization.cs b/MiniSpace.Services.Organizations/src/MiniSpace.Services.Organizations.Core/Entities/Organization.cs index 179dd76c6..864622442 100644 --- a/MiniSpace.Services.Organizations/src/MiniSpace.Services.Organizations.Core/Entities/Organization.cs +++ b/MiniSpace.Services.Organizations/src/MiniSpace.Services.Organizations.Core/Entities/Organization.cs @@ -7,8 +7,7 @@ public class Organization : AggregateRoot private ISet _organizers = new HashSet(); public string Name { get; private set; } public Guid ParentId { get; private set; } - public bool IsRoot => ParentId == Guid.Empty; - public bool IsLeaf => ParentId != Guid.Empty; + public bool IsLeaf { get; private set; } public IEnumerable Organizers { @@ -16,11 +15,12 @@ public IEnumerable Organizers private set => _organizers = new HashSet(value); } - public Organization(Guid id, string name, Guid parentId, IEnumerable organizers = null) + public Organization(Guid id, string name, Guid parentId, bool isLeaf = true, IEnumerable organizers = null) { Id = id; Name = name; ParentId = parentId; + IsLeaf = isLeaf; Organizers = organizers ?? Enumerable.Empty(); } @@ -35,5 +35,8 @@ public void AddOrganizer(Organizer organizer) } _organizers.Add(organizer); } + + public void MakeParent() + => IsLeaf = false; } } \ No newline at end of file diff --git a/MiniSpace.Services.Organizations/src/MiniSpace.Services.Organizations.Infrastructure/Mongo/Documents/Extensions.cs b/MiniSpace.Services.Organizations/src/MiniSpace.Services.Organizations.Infrastructure/Mongo/Documents/Extensions.cs index 521b1436d..3a3d97380 100644 --- a/MiniSpace.Services.Organizations/src/MiniSpace.Services.Organizations.Infrastructure/Mongo/Documents/Extensions.cs +++ b/MiniSpace.Services.Organizations/src/MiniSpace.Services.Organizations.Infrastructure/Mongo/Documents/Extensions.cs @@ -6,7 +6,7 @@ namespace MiniSpace.Services.Organizations.Infrastructure.Mongo.Documents public static class Extensions { public static Organization AsEntity(this OrganizationDocument document) - => new Organization(document.Id, document.Name, document.ParentId, document.Organizers); + => new Organization(document.Id, document.Name, document.ParentId, document.IsLeaf, document.Organizers); public static OrganizationDocument AsDocument(this Organization entity) => new OrganizationDocument() @@ -14,6 +14,7 @@ public static OrganizationDocument AsDocument(this Organization entity) Id = entity.Id, Name = entity.Name, ParentId = entity.ParentId, + IsLeaf = entity.IsLeaf, Organizers = entity.Organizers }; @@ -23,7 +24,7 @@ public static OrganizationDto AsDto(this OrganizationDocument document) Id = document.Id, Name = document.Name, ParentId = document.ParentId, - MemberCount = document.Organizers.Count() + IsLeaf = document.IsLeaf }; public static Organizer AsEntity(this OrganizerDocument document) diff --git a/MiniSpace.Services.Organizations/src/MiniSpace.Services.Organizations.Infrastructure/Mongo/Documents/OrganizationDocument.cs b/MiniSpace.Services.Organizations/src/MiniSpace.Services.Organizations.Infrastructure/Mongo/Documents/OrganizationDocument.cs index 913f7da50..24946e59b 100644 --- a/MiniSpace.Services.Organizations/src/MiniSpace.Services.Organizations.Infrastructure/Mongo/Documents/OrganizationDocument.cs +++ b/MiniSpace.Services.Organizations/src/MiniSpace.Services.Organizations.Infrastructure/Mongo/Documents/OrganizationDocument.cs @@ -8,6 +8,7 @@ public class OrganizationDocument: IIdentifiable public Guid Id { get; set; } public string Name { get; set; } public Guid ParentId { get; set; } + public bool IsLeaf { get; set; } public IEnumerable Organizers { get; set; } } } \ No newline at end of file