Rework and optimize database columns + add descriptions
This commit is contained in:
parent
39be89f10f
commit
81a4ffec24
9 changed files with 84 additions and 64 deletions
|
|
@ -4,7 +4,13 @@ namespace App\Enums;
|
|||
|
||||
enum ExcludeTypeEnum : Int
|
||||
{
|
||||
/**
|
||||
* Ig post defined by its id
|
||||
*/
|
||||
case post = 1;
|
||||
/**
|
||||
* Ig user defined by its username
|
||||
*/
|
||||
case user = 2;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ namespace App\Jobs;
|
|||
|
||||
use App\Enums\ExcludeTypeEnum;
|
||||
use App\Models\InstaMedia;
|
||||
use App\Models\InstaMediaExclude;
|
||||
use App\Models\InstaMediaExclusion;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
|
@ -48,10 +48,10 @@ class InstaGetTopMediasJob implements ShouldQueue
|
|||
*/
|
||||
\extract($this->fetchConfigParameters());
|
||||
|
||||
/** @var \Illuminate\Database\Eloquent\Collection<array-key,\App\Models\InstaMediaExclude> */
|
||||
$excludePosts = InstaMediaExclude::query()->where('type', ExcludeTypeEnum::post)->get();
|
||||
/** @var \Illuminate\Database\Eloquent\Collection<array-key,\App\Models\InstaMediaExclude> */
|
||||
$excludeUsers = InstaMediaExclude::query()->where('type', ExcludeTypeEnum::user)->get();
|
||||
/** @var \Illuminate\Database\Eloquent\Collection<array-key,\App\Models\InstaMediaExclusion> */
|
||||
$excludePosts = InstaMediaExclusion::query()->where('type', ExcludeTypeEnum::post)->get();
|
||||
/** @var \Illuminate\Database\Eloquent\Collection<array-key,\App\Models\InstaMediaExclusion> */
|
||||
$excludeUsers = InstaMediaExclusion::query()->where('type', ExcludeTypeEnum::user)->get();
|
||||
|
||||
/** @var \App\Lib\Instagram\ApiFetcher */
|
||||
$igFetcherClient = \app('Instagram');
|
||||
|
|
|
|||
|
|
@ -52,12 +52,12 @@ class ApiFetcher
|
|||
* @phpcs:disable Generic.Files.LineLength.TooLong
|
||||
* @phpcs:disable Squiz.Commenting.FunctionComment.IncorrectTypeHint
|
||||
*
|
||||
* @param integer $hashtag_id The IG hashtag Id we whould target.
|
||||
* @param integer $user_id The IG user id we want to fetch.
|
||||
* @param \Illuminate\Database\Eloquent\Collection<\App\Models\InstaMediaExclude> $excludedPosts The IG user id we want to fetch.
|
||||
* @param \Illuminate\Database\Eloquent\Collection<\App\Models\InstaMediaExclude> $excludedUsers The IG user id we want to fetch.
|
||||
* @param integer $limit The limit of how many post should be fetched.
|
||||
* @param integer $media_count How many media we want to fetch.
|
||||
* @param integer $hashtag_id The IG hashtag Id we whould target.
|
||||
* @param integer $user_id The IG user id we want to fetch.
|
||||
* @param \Illuminate\Database\Eloquent\Collection<\App\Models\InstaMediaExclusion> $excludedPosts The IG user id we want to fetch.
|
||||
* @param \Illuminate\Database\Eloquent\Collection<\App\Models\InstaMediaExclusion> $excludedUsers The IG user id we want to fetch.
|
||||
* @param integer $limit The limit of how many post should be fetched.
|
||||
* @param integer $media_count How many media we want to fetch.
|
||||
* @return \Illuminate\Support\Collection<array-key,\App\Lib\Instagram\Objects\TopMedia>
|
||||
* @throws \RuntimeException If a call error or a response parsing error occurs.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace App\Lib\Instagram\Objects;
|
||||
|
||||
use stdClass;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
/**
|
||||
* @property string $insta_id
|
||||
|
|
@ -16,7 +16,7 @@ use stdClass;
|
|||
*
|
||||
* @package App\Lib\Instagram\Objects
|
||||
*/
|
||||
class TopMedia extends stdClass
|
||||
class TopMedia extends \stdClass
|
||||
{
|
||||
/**
|
||||
* Set this object data from Ig api data
|
||||
|
|
@ -29,7 +29,7 @@ class TopMedia extends stdClass
|
|||
$this->insta_id = $ig_media->id;
|
||||
$this->type = $ig_media->media_type;
|
||||
$this->permalink = $ig_media->permalink;
|
||||
$this->timestamp = $ig_media->timestamp;
|
||||
$this->timestamp = Carbon::parse($ig_media->timestamp);
|
||||
$this->comments_count = \intval($ig_media->comments_count);
|
||||
$this->like_count = \optional($ig_media)->like_count ? \intval($ig_media->like_count) : null;
|
||||
$this->caption = $ig_media->caption;
|
||||
|
|
|
|||
|
|
@ -5,17 +5,21 @@ namespace App\Models;
|
|||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* @property integer $insta_id A unique instagram id that can be used for api calls.
|
||||
* @property string $type The instagram object type, commonly IMAGE or CAROUSEL_ALBUM.
|
||||
* @property string $username The instagram user name, scrapped using OG description.
|
||||
* @property string $caption The object text content.
|
||||
* @property string $permalink The uri where is stored the Instagram object.
|
||||
* @property \Carbon\Carbon $timestamp UTC timestamp from instagram api.
|
||||
* @property integer $comments_count The number of comments.
|
||||
* @property null|integer $like_count The number of likes.
|
||||
* @package App\Models
|
||||
*/
|
||||
class InstaMedia extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* $table
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = "insta_medias";
|
||||
|
||||
/**
|
||||
* $fillable
|
||||
*
|
||||
|
|
@ -31,4 +35,13 @@ class InstaMedia extends Model
|
|||
'username',
|
||||
'caption'
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $casts = [
|
||||
'timestamp' => 'immutable_datetime'
|
||||
];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|||
use Illuminate\Database\Eloquent\Model;
|
||||
use App\Enums\ExcludeTypeEnum;
|
||||
|
||||
class InstaMediaExclude extends Model
|
||||
class InstaMediaExclusion extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('insta_media', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger("insta_id")->unique()
|
||||
->comment('A unique instagram id that can be used for api calls');
|
||||
$table->string("type")->comment('The instagram object type, commonly IMAGE or CAROUSEL_ALBUM');
|
||||
$table->string('username')->comment('The instagram user name, scrapped using OG description');
|
||||
$table->text('caption')->comment('The object text content');
|
||||
$table->string("permalink")->comment('The uri where is stored the Instagram object');
|
||||
$table->timestamp('timestamp')->comment('UTC timestamp from instagram api');
|
||||
$table->unsignedInteger("comments_count");
|
||||
$table->unsignedInteger("like_count")->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('insta_medias');
|
||||
}
|
||||
};
|
||||
|
|
@ -1,39 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('insta_medias', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string("insta_id")->unique();
|
||||
$table->string("type");
|
||||
$table->string("permalink");
|
||||
$table->string("timestamp");
|
||||
$table->bigInteger("comments_count");
|
||||
$table->bigInteger("like_count")->nullable();
|
||||
$table->string('username');
|
||||
$table->text('caption');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('insta_medias');
|
||||
}
|
||||
};
|
||||
|
|
@ -13,10 +13,10 @@ return new class extends Migration
|
|||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('insta_media_excludes', function (Blueprint $table) {
|
||||
Schema::create('insta_media_exclusions', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedTinyInteger('type')->comment("Enum 1 = post, 2 = user");
|
||||
$table->string('value');
|
||||
$table->unsignedTinyInteger('type')->comment("ExcludeTypeEnum 1 = post, 2 = user");
|
||||
$table->string('value')->comment('Post: ig id, User : ig username');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue