Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions backend/db/blueprint.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ CREATE TABLE IF NOT EXISTS `employees` (
`id` INT AUTO_INCREMENT PRIMARY KEY,
`store_id` INT NOT NULL,
`name` VARCHAR(255) NOT NULL,
`password` VARCHAR(255) NOT NULL,
`role` ENUM('admin', 'staff') NOT NULL DEFAULT 'staff',
FOREIGN KEY (`store_id`) REFERENCES `stores`(`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public function change(): void
$table = $this->table('stores');
$table->addColumn('parent_id', 'integer', ['null' => true, 'default' => null, 'signed'=> false])
->addColumn('name', 'string', ['limit' => 255, 'null' => false])
->addTimestamps()
->create();

$table->addForeignKey('parent_id', 'stores', 'id', ['delete' => 'SET_NULL', 'update' => 'NO_ACTION'])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ public function change(): void
$table = $this->table('employees');
$table->addColumn('store_id', 'integer', ['null' => false, 'signed'=>false]) // integerに変更
->addColumn('name', 'string', ['limit' => 255, 'null' => false])
->addColumn('password', 'string', ['limit' => 255, 'null' => false])
->addColumn('role', 'enum', ['values' => ['admin', 'staff'], 'default' => 'staff', 'null' => false])
->addTimestamps()
->addForeignKey('store_id', 'stores', 'id', ['delete' => 'CASCADE', 'update' => 'NO_ACTION'])
->create();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public function change(): void
$table->addColumn('user_id', 'biginteger', ['null' => false])
->addColumn('paid', 'boolean', ['null' => false, 'default' => false])
->addColumn('disabled', 'boolean', ['null' => false, 'default' => false])
->addTimestamps()
->addIndex(['user_id'], ['unique' => true])
->create();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public function change(): void
->addColumn('store_id', 'integer', ['null' => false, 'signed'=>false])
->addColumn('score', 'integer', ['null' => false])
->addColumn('time', 'timestamp', ['null' => false, 'default' => 'CURRENT_TIMESTAMP'])
->addTimestamps()
->addForeignKey('customer_user_id', 'customers', 'user_id', ['delete' => 'NO_ACTION', 'update' => 'NO_ACTION'])
->addForeignKey('store_id', 'stores', 'id', ['delete' => 'NO_ACTION', 'update' => 'NO_ACTION'])
->addIndex(['customer_user_id', 'time'])
Expand Down
43 changes: 43 additions & 0 deletions backend/db/models/Customer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Customer extends Model
{
protected $table = 'customers';
public $timestamps = true;

protected $fillable = [
'user_id',
'paid',
'disabled',
];

public static function booted()
{
static::creating(function (Customer $customer) {
if (empty($customer->user_id)) {
$customer->user_id = \Illuminate\Support\Facades\DB::raw('UUID_SHORT()');
}
});
}

public function pay(): void
{
$this->paid = true;
$this->save();
}

public function disable(): void
{
$this->disabled = true;
$this->save();
}

public function canPlayGame(): bool
{
return $this->paid && !$this->disabled;
}
}
33 changes: 33 additions & 0 deletions backend/db/models/Employee.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Employee extends Model
{
protected $table = 'employees';
public $timestamps = true;

protected $fillable = [
'store_id',
'name',
'role',
];

protected $hidden = [
'password',
];

public function setPassword($password) {
$this->password = password_hash($password, PASSWORD_DEFAULT);
}
public static function tryLogin($name, $password) :?Employee {
$employee = Employee::where('name', $name)->first();
if ($employee && password_verify($password, $employee->password)) {
return $employee;
}
return null;
}
}
19 changes: 19 additions & 0 deletions backend/db/models/History.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class History extends Model
{
protected $table = 'histories';
public $timestamps = true;

protected $fillable = [
'customer_user_id',
'store_id',
'score',
'time',
];
}
17 changes: 17 additions & 0 deletions backend/db/models/Store.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Store extends Model
{
protected $table = 'stores';
public $timestamps = true;

protected $fillable = [
'parent_id',
'name',
];
}
Loading