[#1] reviews
This commit is contained in:
@@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class Comment extends Model
|
||||||
|
{
|
||||||
|
public const TYPE_MOVIE = 'movie';
|
||||||
|
public const TYPE_SHOW = 'show';
|
||||||
|
|
||||||
|
protected $fillable = [
|
||||||
|
'entity_id',
|
||||||
|
'entity_type',
|
||||||
|
'user_id',
|
||||||
|
'author_name',
|
||||||
|
'author_avatar',
|
||||||
|
'author_rating',
|
||||||
|
'content',
|
||||||
|
'published_at',
|
||||||
|
'tmdb_id',
|
||||||
|
'tmdb_url',
|
||||||
|
];
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Service\MediaProcessing;
|
namespace App\Service\MediaProcessing;
|
||||||
|
|
||||||
|
use App\Models\Comment;
|
||||||
use App\Models\Genre;
|
use App\Models\Genre;
|
||||||
use App\Models\Image;
|
use App\Models\Image;
|
||||||
use App\Models\ItemToFetchJobs;
|
use App\Models\ItemToFetchJobs;
|
||||||
@@ -263,6 +264,40 @@ class MovieProcessingService implements ProcessingInterface
|
|||||||
$this->removeElementFromRemainingJobs($item->tmdb_id, ItemToFetchJobs::JOB_TRANSLATIONS);
|
$this->removeElementFromRemainingJobs($item->tmdb_id, ItemToFetchJobs::JOB_TRANSLATIONS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function getReviews($item)
|
||||||
|
{
|
||||||
|
$tmdbMovieReviews = $this->moviesApi->getReviews($item->tmdb_id);
|
||||||
|
|
||||||
|
if (empty($tmdbMovieReviews) || !isset($tmdbMovieReviews['results'])){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$movie = Movie::where('tmdb_id', $item->tmdb_id)->first();
|
||||||
|
|
||||||
|
foreach ($tmdbMovieReviews['results'] as $tmdbReview) {
|
||||||
|
$existingReview = Comment::where('entity_id', $movie->id)
|
||||||
|
->where('entity_type', Comment::TYPE_MOVIE)
|
||||||
|
->where('tmdb_id', $tmdbReview['id'])
|
||||||
|
->first();
|
||||||
|
|
||||||
|
if (!$existingReview) {
|
||||||
|
Comment::create([
|
||||||
|
'entity_id' => $movie->id,
|
||||||
|
'entity_type' => Comment::TYPE_MOVIE,
|
||||||
|
'author_name' => $tmdbReview['author'],
|
||||||
|
'author_avatar' => $tmdbReview['author_details']['avatar_path'],
|
||||||
|
'author_rating' => $tmdbReview['author_details']['rating'],
|
||||||
|
'content' => $tmdbReview['content'],
|
||||||
|
'published_at' => $tmdbReview['created_at'],
|
||||||
|
'tmdb_id' => $tmdbReview['id'],
|
||||||
|
'tmdb_url' => $tmdbReview['url'],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->removeElementFromRemainingJobs($item->tmdb_id, ItemToFetchJobs::JOB_REVIEWS);
|
||||||
|
}
|
||||||
|
|
||||||
private function processMovieCollection(int $movieId, $belongsToCollection)
|
private function processMovieCollection(int $movieId, $belongsToCollection)
|
||||||
{
|
{
|
||||||
$movieCollection = MovieCollection::where('tmdb_id', $belongsToCollection['id'])->first();
|
$movieCollection = MovieCollection::where('tmdb_id', $belongsToCollection['id'])->first();
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::create('comments', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->integer('entity_id');
|
||||||
|
$table->string('entity_type');
|
||||||
|
$table->integer('user_id')->nullable(true);
|
||||||
|
$table->string('author_name');
|
||||||
|
$table->string('author_avatar');
|
||||||
|
$table->integer('author_rating');
|
||||||
|
$table->text('content');
|
||||||
|
$table->datetime('published_at');
|
||||||
|
$table->string('tmdb_id');
|
||||||
|
$table->string('tmdb_url');
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('comments');
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user