Skip to content

Commit

Permalink
Added basic models and factories
Browse files Browse the repository at this point in the history
  • Loading branch information
korridor committed Jan 21, 2024
1 parent 0c626e6 commit ad90734
Show file tree
Hide file tree
Showing 29 changed files with 1,476 additions and 116 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
APP_NAME=Laravel
APP_ENV=local
APP_KEY=
APP_KEY=base64:UNQNf1SXeASNkWux01Rj8EnHYx8FO0kAxWNDwktclkk=
APP_DEBUG=true
APP_URL=http://localhost

Expand Down
11 changes: 11 additions & 0 deletions .github/workflows/pint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: PHP Linting
on: push
jobs:
pint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: "laravel-pint"
uses: aglipanci/[email protected]
with:
configPath: "pint.json"
42 changes: 42 additions & 0 deletions app/Models/Client.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

declare(strict_types=1);

namespace App\Models;

use Database\Factories\ClientFactory;
use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

/**
* @property string $id
* @property string $name
* @property string $organization_id
* @property-read Team $organization
*
* @method static ClientFactory factory()
*/
class Client extends Model
{
use HasFactory;
use HasUuids;

/**
* The attributes that should be cast.
*
* @var array<string, string>
*/
protected $casts = [
'name' => 'string',
];

/**
* @return BelongsTo<Team, Client>
*/
public function organization(): BelongsTo
{
return $this->belongsTo(Team::class, 'organization_id');
}
}
63 changes: 63 additions & 0 deletions app/Models/Project.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

declare(strict_types=1);

namespace App\Models;

use Database\Factories\ProjectFactory;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;

/**
* @property string $id
* @property string $name
* @property string $organization_id
* @property string $client_id
* @property-read Team $organization
* @property-read Client|null $client
* @property-read Collection<Task> $tasks
*
* @method static ProjectFactory factory()
*/
class Project extends Model
{
use HasFactory;
use HasUuids;

/**
* The attributes that should be cast.
*
* @var array<string, string>
*/
protected $casts = [
'name' => 'string',
];

/**
* @return BelongsTo<Team, Project>
*/
public function organization(): BelongsTo
{
return $this->belongsTo(Team::class, 'organization_id');
}

/**
* @return BelongsTo<Client, Project>
*/
public function client(): BelongsTo
{
return $this->belongsTo(Client::class, 'client_id');
}

/**
* @return HasMany<Task>
*/
public function tasks(): HasMany
{
return $this->hasMany(Task::class);
}
}
42 changes: 42 additions & 0 deletions app/Models/Tag.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

declare(strict_types=1);

namespace App\Models;

use Database\Factories\TagFactory;
use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

/**
* @property string $id
* @property string $name
* @property string $organization_id
* @property-read Team $organization
*
* @method static TagFactory factory()
*/
class Tag extends Model
{
use HasFactory;
use HasUuids;

/**
* The attributes that should be cast.
*
* @var array<string, string>
*/
protected $casts = [
'name' => 'string',
];

/**
* @return BelongsTo<Team, Tag>
*/
public function organization(): BelongsTo
{
return $this->belongsTo(Team::class, 'organization_id');
}
}
52 changes: 52 additions & 0 deletions app/Models/Task.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

declare(strict_types=1);

namespace App\Models;

use Database\Factories\TaskFactory;
use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

/**
* @property string $id
* @property string $name
* @property string $project_id
* @property string $organization_id
* @property-read Project $project
* @property-read Team $organization
*
* @method static TaskFactory factory()
*/
class Task extends Model
{
use HasFactory;
use HasUuids;

/**
* The attributes that should be cast.
*
* @var array<string, string>
*/
protected $casts = [
'name' => 'string',
];

/**
* @return BelongsTo<Project, Task>
*/
public function project(): BelongsTo
{
return $this->belongsTo(Project::class);
}

/**
* @return BelongsTo<Team, Task>
*/
public function organization(): BelongsTo
{
return $this->belongsTo(Team::class, 'organization_id');
}
}
77 changes: 77 additions & 0 deletions app/Models/TimeEntry.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

declare(strict_types=1);

namespace App\Models;

use Database\Factories\TimeEntryFactory;
use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Support\Carbon;

/**
* @property string $id
* @property string $description
* @property Carbon $start
* @property Carbon|null $end
* @property bool $billable
* @property array $tags
* @property-read User $user
* @property-read Team $organization
* @property-read Project|null $project
* @property-read Task|null $task
*
* @method static TimeEntryFactory factory()
*/
class TimeEntry extends Model
{
use HasFactory;
use HasUuids;

/**
* The attributes that should be cast.
*
* @var array<string, string>
*/
protected $casts = [
'description' => 'string',
'start' => 'datetime',
'end' => 'datetime',
'billable' => 'bool',
'tags' => 'array',
];

/**
* @return BelongsTo<User, TimeEntry>
*/
public function user(): BelongsTo
{
return $this->belongsTo(User::class, 'user_id');
}

/**
* @return BelongsTo<Team, TimeEntry>
*/
public function organization(): BelongsTo
{
return $this->belongsTo(Team::class, 'organization_id');
}

/**
* @return BelongsTo<Project, TimeEntry>
*/
public function project(): BelongsTo
{
return $this->belongsTo(Project::class, 'project_id');
}

/**
* @return BelongsTo<Task, TimeEntry>
*/
public function task(): BelongsTo
{
return $this->belongsTo(Task::class, 'task_id');
}
}
16 changes: 15 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
"laravel/jetstream": "^4.2",
"laravel/passport": "*",
"laravel/tinker": "^2.8",
"tightenco/ziggy": "^1.0"
"tightenco/ziggy": "^1.0",
"tpetry/laravel-postgresql-enhanced": "^0.33.0"
},
"require-dev": {
"brianium/paratest": "^7.3",
"fakerphp/faker": "^1.9.1",
"larastan/larastan": "^2.0",
"laravel/pint": "^1.0",
Expand Down Expand Up @@ -54,6 +56,18 @@
],
"analyse": [
"@php ./vendor/bin/phpstan analyse --memory-limit=2G --configuration=phpstan.neon"
],
"ptest": [
"@php artisan test --parallel --colors=always --stop-on-failure"
],
"test": [
"@php artisan test --colors=always --stop-on-failure"
],
"test:coverage": [
"@php artisan test --coverage --colors=always --stop-on-failure"
],
"fix": [
"@php pint"
]
},
"extra": {
Expand Down
Loading

0 comments on commit ad90734

Please sign in to comment.