lots of progress
This commit is contained in:
@@ -3,9 +3,15 @@
|
||||
namespace App\Http\Controllers\Forum;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Forum\Category;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class CategoriesController extends Controller
|
||||
{
|
||||
//
|
||||
public function index()
|
||||
{
|
||||
$categories = Category::with('threads')->get();
|
||||
|
||||
return view('forum.index', compact('categories'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@ namespace App\Http\Controllers;
|
||||
use App\Http\Requests\MediaListRequest;
|
||||
use App\Models\MediaList;
|
||||
use App\Models\MediaListItem;
|
||||
use App\Models\Movie;
|
||||
use App\Models\Show;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
@@ -12,27 +14,31 @@ use Illuminate\Support\Str;
|
||||
|
||||
class MediaListController extends Controller
|
||||
{
|
||||
public function index()
|
||||
public function index(string $slug)
|
||||
{
|
||||
$lists = MediaList::whereNotIn('name', MediaList::SPECIAL_LISTS)
|
||||
->where('user_id', Auth::user()->id)
|
||||
->get();
|
||||
|
||||
return view('profile.lists.index', compact('lists'));
|
||||
$user = User::where('slug', $slug)->first();
|
||||
|
||||
return view('profile.lists.index', compact('lists', 'user'));
|
||||
}
|
||||
|
||||
public function show(string $userSlug, string $listSlug)
|
||||
{
|
||||
$user = User::where('slug', $userSlug)->first();
|
||||
$list = MediaList::where('user_id', $user->id)->where('slug', $listSlug)->first();
|
||||
$items = MediaListItem::where('media_list_id', $list->id)->paginate(15);
|
||||
$items = MediaListItem::with('item')->where('media_list_id', $list->id)->paginate(15);
|
||||
|
||||
return view('profile.lists.show', compact('list', 'items'));
|
||||
return view('profile.lists.show', compact('list', 'items', 'user'));
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
return view('profile.lists.create');
|
||||
$user = Auth::user();
|
||||
|
||||
return view('profile.lists.create', compact('user'));
|
||||
}
|
||||
|
||||
public function store(MediaListRequest $request)
|
||||
@@ -48,4 +54,49 @@ class MediaListController extends Controller
|
||||
|
||||
return redirect()->route('profile.list.show', [Auth::user()->slug, $slug]);
|
||||
}
|
||||
|
||||
public function toggleListItem(string $listSlug, int $itemId, string $itemType)
|
||||
{
|
||||
$mediaList = MediaList::where('slug', $listSlug)
|
||||
->where('user_id', Auth::user()->id)
|
||||
->first();
|
||||
|
||||
if ($itemType == 'movie') {
|
||||
$item = Movie::find($itemId);
|
||||
} else {
|
||||
$item = Show::find($itemId);
|
||||
}
|
||||
|
||||
if (!$item) {
|
||||
return response()->json([
|
||||
'success' => false
|
||||
]);
|
||||
}
|
||||
|
||||
$mediaListItem = MediaListItem::where('media_list_id', $mediaList->id)
|
||||
->where('item_id', $itemId)
|
||||
->where('item_type', $itemType)
|
||||
->first();
|
||||
|
||||
if ($mediaListItem) {
|
||||
$mediaListItem->delete();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'added' => false,
|
||||
]);
|
||||
}
|
||||
|
||||
MediaListItem::create([
|
||||
'media_list_id' => $mediaList->id,
|
||||
'item_id' => $itemId,
|
||||
'item_type' => $itemType,
|
||||
'tmdb_id' => $item->tmdb_id,
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'added' => true,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Rate;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class RatingController extends Controller
|
||||
{
|
||||
public function rate(string $itemType, int $itemId, float $rate)
|
||||
{
|
||||
Rate::updateOrCreate(
|
||||
[
|
||||
'user_id' => auth()->user()->id,
|
||||
'item_id' => $itemId,
|
||||
'item_type' => $itemType,
|
||||
],
|
||||
[
|
||||
'rate' => $rate
|
||||
]
|
||||
);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'rate' => $rate,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -6,5 +6,10 @@ use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Category extends Model
|
||||
{
|
||||
//
|
||||
protected $table = 'forum_categories';
|
||||
|
||||
public function threads()
|
||||
{
|
||||
return $this->hasMany(Thread::class, 'category_id', 'id');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,5 +6,5 @@ use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Thread extends Model
|
||||
{
|
||||
//
|
||||
protected $table = 'forum_threads';
|
||||
}
|
||||
|
||||
@@ -12,4 +12,13 @@ class MediaListItem extends Model
|
||||
'item_type',
|
||||
'tmdb_id',
|
||||
];
|
||||
|
||||
public function item()
|
||||
{
|
||||
if ($this->item_type == 'movie') {
|
||||
return $this->hasOne(Movie::class, 'id', 'item_id');
|
||||
}
|
||||
|
||||
return $this->hasOne(Show::class, 'id', 'item_id');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,32 @@ class Movie extends Model
|
||||
'release_date' => 'date'
|
||||
];
|
||||
|
||||
public function wasListedBy(string $listSlug, User $user)
|
||||
{
|
||||
$mediaList = MediaList::where('slug', $listSlug)->where('user_id', $user->id)->first();
|
||||
|
||||
if ($mediaList) {
|
||||
$mediaListItem = MediaListItem::where('media_list_id', $mediaList->id)
|
||||
->where('item_id', $this->id)
|
||||
->where('item_type', 'movie')
|
||||
->first();
|
||||
|
||||
return !empty($mediaListItem);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function ratingBy(User $user)
|
||||
{
|
||||
$rating = Rate::where('user_id', $user->id)
|
||||
->where('item_id', $this->id)
|
||||
->where('item_type', 'movie')
|
||||
->first();
|
||||
|
||||
return $rating ? $rating->rate : null;
|
||||
}
|
||||
|
||||
public function director()
|
||||
{
|
||||
return $this->belongsToMany(Person::class, 'movie_cast', 'movie_id', 'person_id')
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Rate extends Model
|
||||
{
|
||||
protected $table = 'ratings';
|
||||
|
||||
protected $fillable = [
|
||||
'item_id',
|
||||
'item_type',
|
||||
'rate',
|
||||
'user_id',
|
||||
];
|
||||
}
|
||||
@@ -315,10 +315,25 @@ class MovieProcessingService implements ProcessingInterface
|
||||
->where('tmdb_id', $tmdbReview['id'])
|
||||
->first();
|
||||
|
||||
// @todo create user
|
||||
$user = User::where('name', $tmdbReview['author'])->first();
|
||||
|
||||
if (!$user) {
|
||||
$user = User::create([
|
||||
'name' => $tmdbReview['author'],
|
||||
'slug' => Str::slug($tmdbReview['author']),
|
||||
'email' => $tmdbReview['author'].'@nowhere.wtf',
|
||||
'password' => 'no_password_neeeded_here',
|
||||
'is_dummy_account' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
if (!$existingReview) {
|
||||
Comment::create([
|
||||
'entity_id' => $movie->id,
|
||||
'entity_type' => Comment::TYPE_MOVIE,
|
||||
'user_id' => $user->id,
|
||||
'author_name' => $tmdbReview['author'],
|
||||
'author_avatar' => $tmdbReview['author_details']['avatar_path'],
|
||||
'author_rating' => $tmdbReview['author_details']['rating'],
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
class ToolService
|
||||
{
|
||||
public static function isCurrentRoute(
|
||||
string $routePath
|
||||
)
|
||||
{
|
||||
$currentPath = Route::getCurrentRequest()->path();
|
||||
$uri = ltrim(str_replace(env('APP_URL'), '', $routePath), '/');
|
||||
|
||||
return $currentPath == $uri;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user