update
This commit is contained in:
@@ -42,9 +42,14 @@ class ArtworkResource extends JsonResource
|
||||
$viewerId = (int) optional($request->user())->id;
|
||||
$isLiked = false;
|
||||
$isFavorited = false;
|
||||
$isBookmarked = false;
|
||||
$isFollowing = false;
|
||||
$viewerAward = null;
|
||||
|
||||
$bookmarksCount = Schema::hasTable('artwork_bookmarks')
|
||||
? (int) DB::table('artwork_bookmarks')->where('artwork_id', (int) $this->id)->count()
|
||||
: 0;
|
||||
|
||||
if ($viewerId > 0) {
|
||||
if (Schema::hasTable('artwork_likes')) {
|
||||
$isLiked = DB::table('artwork_likes')
|
||||
@@ -53,6 +58,13 @@ class ArtworkResource extends JsonResource
|
||||
->exists();
|
||||
}
|
||||
|
||||
if (Schema::hasTable('artwork_bookmarks')) {
|
||||
$isBookmarked = DB::table('artwork_bookmarks')
|
||||
->where('user_id', $viewerId)
|
||||
->where('artwork_id', (int) $this->id)
|
||||
->exists();
|
||||
}
|
||||
|
||||
$isFavorited = DB::table('artwork_favourites')
|
||||
->where('user_id', $viewerId)
|
||||
->where('artwork_id', (int) $this->id)
|
||||
@@ -114,6 +126,7 @@ class ArtworkResource extends JsonResource
|
||||
'followers_count' => $followerCount,
|
||||
],
|
||||
'viewer' => [
|
||||
'is_bookmarked' => $isBookmarked,
|
||||
'is_liked' => $isLiked,
|
||||
'is_favorited' => $isFavorited,
|
||||
'is_following_author' => $isFollowing,
|
||||
@@ -121,6 +134,7 @@ class ArtworkResource extends JsonResource
|
||||
'id' => $viewerId > 0 ? $viewerId : null,
|
||||
],
|
||||
'stats' => [
|
||||
'bookmarks' => $bookmarksCount,
|
||||
'views' => (int) ($this->stats?->views ?? 0),
|
||||
'downloads' => (int) ($this->stats?->downloads ?? 0),
|
||||
'favorites' => (int) ($this->stats?->favorites ?? 0),
|
||||
|
||||
Reference in New Issue
Block a user