Skip to content

Commit

Permalink
(#87) add validation for organization name
Browse files Browse the repository at this point in the history
  • Loading branch information
eggwhat committed May 17, 2024
1 parent f919761 commit 6b90192
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ public async Task HandleAsync(CreateOrganization command, CancellationToken canc
throw new ParentOrganizationNotFoundException(command.ParentId);
}

if (string.IsNullOrWhiteSpace(command.Name))
{
throw new InvalidOrganizationNameException(command.Name);
}

var organization = new Organization(command.OrganizationId, command.Name);
parent.AddSubOrganization(organization);
await _organizationRepository.UpdateAsync(root);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Convey.CQRS.Commands;
using MiniSpace.Services.Organizations.Application.Events;
using MiniSpace.Services.Organizations.Application.Exceptions;
using MiniSpace.Services.Organizations.Application.Services;
using MiniSpace.Services.Organizations.Core.Entities;
using MiniSpace.Services.Organizations.Core.Repositories;
Expand Down Expand Up @@ -27,6 +28,11 @@ public async Task HandleAsync(CreateRootOrganization command, CancellationToken
{
throw new Exceptions.UnauthorizedAccessException("admin");
}

if (string.IsNullOrWhiteSpace(command.Name))
{
throw new InvalidOrganizationNameException(command.Name);
}

var organization = new Organization(command.OrganizationId, command.Name);
await _organizationRepository.AddAsync(organization);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace MiniSpace.Services.Organizations.Application.Exceptions
{
public class InvalidOrganizationNameException : AppException
{
public override string Code { get; } = "invalid_organization_name";
public string Name { get; }

public InvalidOrganizationNameException(string name) : base($"Invalid organization name: {name}.")
{
Name = name;
}
}
}

0 comments on commit 6b90192

Please sign in to comment.