Skip to content

Commit

Permalink
add OrgNameValidator to validate organization name
Browse files Browse the repository at this point in the history
  • Loading branch information
SparkLee committed Feb 23, 2023
1 parent c4b4c35 commit 487fd0e
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 2 deletions.
10 changes: 10 additions & 0 deletions app/Domain/Common/Exceptions/BusinessException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace App\Domain\Common\Exceptions;

use RuntimeException;

class BusinessException extends RuntimeException
{

}
8 changes: 8 additions & 0 deletions app/Domain/Common/Validators/Validator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace App\Domain\Common\Validators;

class Validator
{

}
9 changes: 7 additions & 2 deletions app/Domain/OrgMng/Org/OrgBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@
namespace App\Domain\OrgMng\Org;

use App\Domain\OrgMng\Org\DTO\OrgDomainDTO;
use App\Domain\OrgMng\Org\Validator\OrgNameValidator;

class OrgBuilder
{
private OrgDomainDTO $orgDomainDTO;
private OrgNameValidator $orgNameValidator;

public function orgDomainDTO(OrgDomainDTO $orgDomainDTO): self
public function orgDomainDTO(OrgDomainDTO $orgDomainDTO,
OrgNameValidator $orgNameValidator): self
{
$this->orgDomainDTO = $orgDomainDTO;
$this->orgNameValidator = $orgNameValidator;
return $this;
}

Expand All @@ -22,6 +26,7 @@ public function build(): Org

private function validate(): void
{

$dto = $this->orgDomainDTO;
$this->orgNameValidator->verify($dto->getTenantId(), $dto->getSuperiorId(), $dto->getName());
}
}
26 changes: 26 additions & 0 deletions app/Domain/OrgMng/Org/Validator/OrgNameValidator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
add<?php

namespace App\Domain\OrgMng\Org\Validator;

use App\Domain\Common\Exceptions\BusinessException;

class OrgNameValidator
{
public function verify(int $tenantId, int $superiorId, string $name)
{
$this->nameShouldNotEmpty($name);
$this->nameShouldNotDuplicatedInSameSuperior($tenantId, $superiorId, $name);
}

private function nameShouldNotEmpty(string $name)
{
if (empty($name)) {
throw new BusinessException("组织名不能为空");
}
}

private function nameShouldNotDuplicatedInSameSuperior(int $tenantId, int $superiorId, string $name)
{

}
}

0 comments on commit 487fd0e

Please sign in to comment.