Commit 3ec81fc5 authored by Jacob Priddy's avatar Jacob Priddy 👌

Get basic logging structure down

parent c56ca4a8
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class Attempt extends Model
{
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function door(): BelongsTo
{
return $this->belongsTo(Door::class);
}
}
......@@ -2,6 +2,7 @@
namespace App;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
......@@ -17,6 +18,22 @@ class Door extends Authenticatable
return $this->belongsToMany(Group::class);
}
/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function entries(): HasMany
{
return $this->hasMany(Entry::class);
}
/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function attempts(): HasMany
{
return $this->hasMany(Attempt::class);
}
public static function boot()
{
parent::boot();
......@@ -24,6 +41,18 @@ class Door extends Authenticatable
static::deleting(static function (Door $door) {
// Detach all groups
$door->groups()->detach();
// Delete all entries
/** @var \App\Entry $entry */
foreach ($door->entries() as $entry) {
$entry->delete();
}
// Delete all attempts
/** @var \App\Attempt $attempt */
foreach ($door->attempts() as $attempt) {
$attempt->delete();
}
});
}
}
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class Entry extends Model
{
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function door(): BelongsTo
{
return $this->belongsTo(Door::class);
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
}
......@@ -32,6 +32,14 @@ class User extends Authenticatable
return $this->hasMany(Token::class);
}
/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function entries(): HasMany
{
$this->hasMany(Entry::class);
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
......@@ -53,6 +61,11 @@ class User extends Authenticatable
foreach ($user->tokens() as $token) {
$token->delete();
}
/** @var \App\Entry $entry */
foreach ($user->entries() as $entry) {
$entry->delete();
}
});
}
}
......@@ -15,7 +15,7 @@ class CreateUsersTable extends Migration
{
// This table holds the user objects in the system
Schema::create('users', function (Blueprint $table) {
$table->bigIncrements('id');
$table->id();
$table->string('first_name');
$table->string('last_name');
$table->string('display_name');
......
......@@ -13,8 +13,8 @@ class CreateFailedJobsTable extends Migration
*/
public function up()
{
Schema::create('failed_jobs', function (Blueprint $table) {
$table->bigIncrements('id');
Schema::create('failed_jobs', static function (Blueprint $table) {
$table->id();
$table->text('connection');
$table->text('queue');
$table->longText('payload');
......
......@@ -14,8 +14,8 @@ class CreateGroupsTable extends Migration
public function up()
{
// This table stores the groups objects stored in the system
Schema::create('groups', function (Blueprint $table) {
$table->bigIncrements('id');
Schema::create('groups', static function (Blueprint $table) {
$table->id();
$table->string('title')->unique();
$table->string('description');
$table->timestamps();
......
......@@ -14,8 +14,8 @@ class CreateGroupUserTable extends Migration
public function up()
{
// This table is a pivot table mapping users into groups
Schema::create('group_user', function (Blueprint $table) {
$table->bigIncrements('id');
Schema::create('group_user', static function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('user_id');
$table->foreign('user_id')->references('id')->on('users');
$table->unsignedBigInteger('group_id');
......
......@@ -14,8 +14,8 @@ class CreateDoorsTable extends Migration
public function up()
{
// This table contains the base door objects stored on the system
Schema::create('doors', function (Blueprint $table) {
$table->bigIncrements('id');
Schema::create('doors', static function (Blueprint $table) {
$table->id();
$table->string('location');
$table->string('name')->unique();
// hashed
......
......@@ -15,8 +15,8 @@ class CreateUserDoorTable extends Migration
{
// This table maps special cases of users getting access to doors
// without being in a special group.
Schema::create('user_door', function (Blueprint $table) {
$table->bigIncrements('id');
Schema::create('user_door', static function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('door_id');
$table->foreign('door_id')->references('id')->on('doors');
$table->unsignedBigInteger('user_id');
......
......@@ -14,8 +14,8 @@ class CreateDoorGroupTable extends Migration
public function up()
{
// This table maps the permissions a specific group has to a specific door
Schema::create('door_group', function (Blueprint $table) {
$table->bigIncrements('id');
Schema::create('door_group', static function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('door_id');
$table->foreign('door_id')->references('id')->on('doors');
$table->unsignedBigInteger('group_id');
......
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateEventsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
// This table houses all event objects
// Add option for code or open mode
Schema::create('events', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('title');
$table->string('description');
// Do I want this here?
$table->boolean('repeat');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('events');
}
}
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateEventScheduleTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
// This table houses time periods for schedules
Schema::create('event_schedule', function (Blueprint $table) {
$table->bigIncrements('id');
// Setup repeat schedule for times? and tie to events
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('event_schedule');
}
}
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateGroupScheduleTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
// This table maps time specific permissions to groups
Schema::create('group_schedule', function (Blueprint $table) {
$table->bigIncrements('id');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('group_schedule');
}
}
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateUserScheduleTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
// This table maps time specific permissions to users
Schema::create('user_schedule', function (Blueprint $table) {
$table->bigIncrements('id');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('user_schedule');
}
}
......@@ -4,7 +4,7 @@ use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateEntryLogTable extends Migration
class CreateLogTable extends Migration
{
/**
* Run the migrations.
......@@ -14,11 +14,12 @@ class CreateEntryLogTable extends Migration
public function up()
{
// This table logs all invalid attempts to open a door
Schema::create('entry_log', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('entered_code');
Schema::create('entries', static function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('user_id');
$table->unsignedBigInteger('door_id');
$table->foreign('door_id')->references('id')->on('doors');
$table->foreign('user_id')->references('id')->on('users');
$table->timestamps();
});
}
......@@ -30,6 +31,6 @@ class CreateEntryLogTable extends Migration
*/
public function down()
{
Schema::dropIfExists('entry_log');
Schema::dropIfExists('entries');
}
}
......@@ -14,7 +14,7 @@ class CreateTokensTable extends Migration
public function up()
{
Schema::create('tokens', static function (Blueprint $table) {
$table->bigIncrements('id');
$table->id();
$table->string('name')->nullable()->default(null);
$table->string('api_token');
$table->unsignedBigInteger('user_id');
......
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateUserDoorEntryTable extends Migration
class CreateAttemptsTable extends Migration
{
/**
* Run the migrations.
......@@ -13,13 +13,10 @@ class CreateUserDoorEntryTable extends Migration
*/
public function up()
{
// This table contains logs of all successful entries by users.
Schema::create('user_door_entry', function (Blueprint $table) {
$table->bigIncrements('id');
Schema::create('attempts', static function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('door_id');
$table->foreign('door_id')->references('id')->on('doors');
$table->unsignedBigInteger('user_id');
$table->foreign('user_id')->references('id')-> on('users');
$table->timestamps();
});
}
......@@ -31,6 +28,6 @@ class CreateUserDoorEntryTable extends Migration
*/
public function down()
{
Schema::dropIfExists('user_door_entry');
Schema::dropIfExists('attempts');
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment