|
|
@@ -4,6 +4,8 @@ namespace App\Services;
|
|
|
|
|
|
use App\Models\Article;
|
|
|
use App\Models\ArticleCollection;
|
|
|
+use App\Http\Resources\ArticleResource;
|
|
|
+use Illuminate\Support\Facades\Log;
|
|
|
|
|
|
class ArticleService
|
|
|
{
|
|
|
@@ -46,4 +48,18 @@ class ArticleService
|
|
|
->get()->toArray();
|
|
|
return array_map(fn($item) => $item['article_id'], $inCollection);
|
|
|
}
|
|
|
+
|
|
|
+ public function getArticle(string $id): array
|
|
|
+ {
|
|
|
+ $result = Article::where('uid', $id)->first();
|
|
|
+ if (!$result) {
|
|
|
+ Log::warning("没有查询到数据 id={$id}");
|
|
|
+ return ['error' => "没有查询到数据 id={$id}", 'code' => 404];
|
|
|
+ }
|
|
|
+
|
|
|
+ return [
|
|
|
+ 'data' => new ArticleResource($result),
|
|
|
+ 'ok' => true
|
|
|
+ ];
|
|
|
+ }
|
|
|
}
|