Reading history
This commit is contained in:
@@ -12,6 +12,7 @@ use Illuminate\Contracts\Routing\ResponseFactory;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Illuminate\Foundation\Application;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response as IlluminateHttpResponse;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
@@ -169,9 +170,14 @@ class ComicController extends Controller
|
||||
// Do an upsert
|
||||
Chapter::upsert($arrayForUpsert, uniqueBy: 'chapter_uuid');
|
||||
|
||||
// Get history
|
||||
$histories = $request->user()->readingHistories()->where('reading_histories.comic_id', $comicObject->id)
|
||||
->distinct()->select('chapter_uuid')->get()->pluck('chapter_uuid');
|
||||
|
||||
return Inertia::render('Comic/Chapters', [
|
||||
'comic' => $comic,
|
||||
'chapters' => $chapters,
|
||||
'histories' => $histories
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -213,12 +219,32 @@ class ComicController extends Controller
|
||||
// Do an upsert
|
||||
Image::upsert($arrayForUpsert, uniqueBy: 'url');
|
||||
|
||||
// Update history
|
||||
$request->user()->readingHistories()->attach($chapterObj->id, ['comic_id' => $comicObj->id]);
|
||||
|
||||
return Inertia::render('Comic/Read', [
|
||||
'comic' => $comic,
|
||||
'chapter' => $chapter,
|
||||
]);
|
||||
}
|
||||
|
||||
public function histories(Request $request): Response
|
||||
{
|
||||
// Get history
|
||||
$histories = $request->user()->readingHistories()->with(['comic:id,name,pathword'])->orderByDesc('reading_histories.created_at')
|
||||
->select(['reading_histories.id as hid', 'reading_histories.created_at', 'chapters.comic_id', 'chapters.name'])->paginate(50)->toArray();
|
||||
|
||||
return Inertia::render('Comic/Histories', [
|
||||
'histories' => $histories
|
||||
]);
|
||||
}
|
||||
|
||||
public function destroyHistories(Request $request): RedirectResponse
|
||||
{
|
||||
$histories = $request->user()->readingHistories()->whereIn('reading_histories.id', $request->get('ids'))->delete();
|
||||
return redirect()->route('comics.histories');
|
||||
}
|
||||
|
||||
public function tags()
|
||||
{
|
||||
// TODO
|
||||
|
||||
Reference in New Issue
Block a user