WIP - bookmark module
This commit is contained in:
parent
3792d108cc
commit
5eea82fc5a
38
app/Http/Controllers/StudyBookmarkController.php
Normal file
38
app/Http/Controllers/StudyBookmarkController.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Requests\BookmarkCrudRequest;
|
||||
use App\Models\StudyBookmark;
|
||||
|
||||
class StudyBookmarkController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
return StudyBookmark::all();
|
||||
}
|
||||
|
||||
public function store(BookmarkCrudRequest $request)
|
||||
{
|
||||
return StudyBookmark::create($request->validated());
|
||||
}
|
||||
|
||||
public function show(StudyBookmark $studyBookmark)
|
||||
{
|
||||
return $studyBookmark;
|
||||
}
|
||||
|
||||
public function update(BookmarkCrudRequest $request, StudyBookmark $studyBookmark)
|
||||
{
|
||||
$studyBookmark->update($request->validated());
|
||||
|
||||
return $studyBookmark;
|
||||
}
|
||||
|
||||
public function destroy(StudyBookmark $studyBookmark)
|
||||
{
|
||||
$studyBookmark->delete();
|
||||
|
||||
return response()->json();
|
||||
}
|
||||
}
|
21
app/Http/Requests/BookmarkCrudRequest.php
Normal file
21
app/Http/Requests/BookmarkCrudRequest.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class BookmarkCrudRequest extends FormRequest
|
||||
{
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'study_id' => ['required', 'exists:studies'],
|
||||
'user_id' => ['required', 'exists:users'],
|
||||
];
|
||||
}
|
||||
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
@ -517,6 +517,11 @@ public function isStudyComplete(): bool
|
||||
return $this->report_status->value >= ReportStatus::Finalized->value;
|
||||
}
|
||||
|
||||
public function bookmarkedByUsers()
|
||||
{
|
||||
return $this->belongsToMany(User::class, 'study_bookmarks');
|
||||
}
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
|
18
app/Models/StudyBookmark.php
Normal file
18
app/Models/StudyBookmark.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class StudyBookmark extends BaseModel
|
||||
{
|
||||
public function study(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Study::class);
|
||||
}
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
}
|
@ -179,6 +179,11 @@ public function panels(): HasManyThrough
|
||||
return $this->hasManyThrough(AssignmentPanel::class, AssignmentPanelRadiologist::class);
|
||||
}
|
||||
|
||||
public function bookmarkedStudies(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Study::class, 'study_bookmarks');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the attributes that should be cast.
|
||||
*
|
||||
|
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Study;
|
||||
use App\Models\User;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('study_bookmarks', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignIdFor(Study::class)->constrained()->cascadeOnDelete();
|
||||
$table->foreignIdFor(User::class)->constrained()->cascadeOnDelete()->index();
|
||||
$table->timestamps();
|
||||
|
||||
$table->unique(['study_id', 'user_id']);
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('study_bookmarks');
|
||||
}
|
||||
};
|
Loading…
Reference in New Issue
Block a user