Procházet zdrojové kódy

契約識別子対応

develop
sosuke.iwabuchi před 2 roky
rodič
revize
2d374170b8
6 změnil soubory, kde provedl 91 přidání a 0 odebrání
  1. +2
    -0
      app/Http/Controllers/Web/Contract/CreateParam.php
  2. +27
    -0
      app/Logic/Contract/ContractManager.php
  3. +16
    -0
      app/Logic/Contract/CreateManager.php
  4. +1
    -0
      app/Models/Contract.php
  5. +1
    -0
      app/Repositories/ContractRepository.php
  6. +44
    -0
      database/migrations/2023_08_22_100200_add_column_contracts_contract_code.php

+ 2
- 0
app/Http/Controllers/Web/Contract/CreateParam.php Zobrazit soubor

@@ -8,6 +8,7 @@ use App\Models\Contract;
/**
* @property string $name
* @property ?string $custom
* @property ?string $contractCode
*/

class CreateParam extends BaseParam
@@ -18,6 +19,7 @@ class CreateParam extends BaseParam
[
Contract::COL_NAME_NAME => $this->str(),
Contract::COL_NAME_CUSTOM => $this->str(true),
Contract::COL_NAME_CONTRACT_CODE => $this->str(true),
];
}
}

+ 27
- 0
app/Logic/Contract/ContractManager.php Zobrazit soubor

@@ -57,4 +57,31 @@ abstract class ContractManager
$this->contract->save();
return $this;
}

/**
* 契約識別子がUNIQUE判定する
*
* @param array $messages
* @param boolean $forUpdate
* @return boolean
*/
protected function checkContractCode(array &$messages, bool $forUpdate): bool
{
$contractCode = $this->contract->contract_code;

if ($contractCode === null) {
return true;
}

$query = Contract::whereContractCode($contractCode);
if ($forUpdate) {
$query->whereNot(Contract::COL_NAME_ID, $this->contract->id);
}

if ($query->exists()) {
$messages[Contract::COL_NAME_CONTRACT_CODE] = "すでに使われています";
return false;
}
return true;
}
}

+ 16
- 0
app/Logic/Contract/CreateManager.php Zobrazit soubor

@@ -7,8 +7,24 @@ class CreateManager extends ContractManager
public function create(): array
{
$messages = [];

if (!$this->checkForCreate($messages)) {
return $messages;
}

$this->save();

return $messages;
}

private function checkForCreate(array &$messages): bool
{

$messages = [];
$ret = true;

$ret = $this->checkContractCode($messages, false);

return $ret;
}
}

+ 1
- 0
app/Models/Contract.php Zobrazit soubor

@@ -10,6 +10,7 @@ class Contract extends AppModel

const COL_NAME_NAME = 'name';
const COL_NAME_CUSTOM = 'custom';
const COL_NAME_CONTRACT_CODE = 'contract_code';

public function getModelName(): string
{


+ 1
- 0
app/Repositories/ContractRepository.php Zobrazit soubor

@@ -65,6 +65,7 @@ class ContractRepository extends BaseRepository
$this->makeColumnNameForSelect([$contract, Contract::COL_NAME_ID]),
$this->makeColumnNameForSelect([$contract, Contract::COL_NAME_NAME]),
$this->makeColumnNameForSelect([$contract, Contract::COL_NAME_CUSTOM]),
$this->makeColumnNameForSelect([$contract, Contract::COL_NAME_CONTRACT_CODE]),
$this->makeColumnNameForSelect([$contract, Contract::COL_NAME_UPDATED_AT]),
$this->makeColumnNameForSelect([$contract, Contract::COL_NAME_CREATED_AT]),
];


+ 44
- 0
database/migrations/2023_08_22_100200_add_column_contracts_contract_code.php Zobrazit soubor

@@ -0,0 +1,44 @@
<?php

use App\Util\MigrationHelper;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('contracts', function (Blueprint $table) {
$helper = new MigrationHelper($table);
$table->string("contract_code")->nullable()->comment("契約識別子");
$helper->unique(1, ['contract_code']);
});
Schema::table('contract_histories', function (Blueprint $table) {
$table->string("contract_code")->nullable()->comment("契約識別子");
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('contracts', function (Blueprint $table) {
$helper = new MigrationHelper($table);
$table->dropColumn("contract_code");

$helper->dropIndex(1);
});
Schema::table('contract_histories', function (Blueprint $table) {
$table->dropColumn("contract_code");
});
}
};

Načítá se…
Zrušit
Uložit