Skip to content

Commit

Permalink
Merge pull request #36 from ipkpjersi/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
ipkpjersi authored Nov 26, 2024
2 parents 3747a3a + 8f92019 commit f6d6224
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
8 changes: 5 additions & 3 deletions app/Console/Commands/DeleteAnime.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Console\Commands;

use App\Models\Anime;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
Expand Down Expand Up @@ -32,7 +33,7 @@ public function handle(): void
$this->info("Fetching details for anime ID $animeId...");

// Fetch the anime details
$anime = DB::table('anime')->find($animeId);
$anime = Anime::getAnimeDetails($animeId);

if (!$anime) {
$this->error('Anime ID is invalid or does not exist.');
Expand Down Expand Up @@ -85,7 +86,8 @@ private function displayAnimeDetails($anime)
$this->info("Title: $anime->title");
$this->info("Year: " . ($anime->year ?? 'UNKNOWN'));
$this->info("Season: " . ($anime->season ?? 'UNKNOWN'));
$this->info("Type: " . ($anime->anime_type_id ?? 'UNKNOWN'));
$this->info("Type: " . optional($anime->anime_type)->type ?: 'UNKNOWN');
$this->info("Status: " . optional($anime->anime_status)->status ?: 'UNKNOWN');
$this->info("Episodes: " . ($anime->episodes ?? 'UNKNOWN'));
$this->info("Synonyms: " . ($anime->synonyms ?? 'NONE'));
$this->info("-----------------------");
Expand All @@ -100,4 +102,4 @@ private function confirmDelete()

return strtolower($confirmation) === 'yes';
}
}
}
5 changes: 3 additions & 2 deletions app/Console/Commands/MergeAnimeDuplicate.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Console\Commands;

use App\Models\Anime;
use App\Services\DuplicateAnimeService;
use Illuminate\Console\Command;

Expand Down Expand Up @@ -32,8 +33,8 @@ public function handle(DuplicateAnimeService $duplicateAnimeService): void
$this->info("Fetching details for anime ID $oldAnimeId and $newAnimeId...");

// Fetch anime details for both old and new anime
$oldAnime = $duplicateAnimeService->getAnimeDetails($oldAnimeId);
$newAnime = $duplicateAnimeService->getAnimeDetails($newAnimeId);
$oldAnime = Anime::getAnimeDetails($oldAnimeId);
$newAnime = Anime::getAnimeDetails($newAnimeId);

if (!$oldAnime || !$newAnime) {
$this->error('One or both of the anime IDs are invalid.');
Expand Down
7 changes: 7 additions & 0 deletions app/Models/Anime.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,11 @@ public function reviews(): HasMany
{
return $this->hasMany(AnimeReview::class, 'anime_id');
}

public static function getAnimeDetails($animeId)
{
return Anime::select('id', 'title', 'year', 'season', 'anime_type_id', 'anime_status_id', 'episodes', 'synonyms')
->with('anime_type', 'anime_status')
->find($animeId);
}
}
7 changes: 0 additions & 7 deletions app/Services/DuplicateAnimeService.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,4 @@ public function mergeDuplicateAnime($oldAnimeId, $newAnimeId, $logger = null)
return ['status' => 'error', 'message' => 'Merge failed: ' . $e->getMessage()];
}
}

public function getAnimeDetails($animeId)
{
return Anime::select('id', 'title', 'year', 'season', 'anime_type_id', 'anime_status_id', 'episodes', 'synonyms')
->with('anime_type', 'anime_status')
->find($animeId);
}
}

0 comments on commit f6d6224

Please sign in to comment.