Commit workspace changes
This commit is contained in:
@@ -34,11 +34,12 @@ class ArtworkController extends Controller
|
||||
: null;
|
||||
|
||||
$result = $drafts->createDraft(
|
||||
(int) $user->id,
|
||||
$user,
|
||||
(string) $data['title'],
|
||||
isset($data['description']) ? (string) $data['description'] : null,
|
||||
$categoryId,
|
||||
(bool) ($data['is_mature'] ?? false)
|
||||
(bool) ($data['is_mature'] ?? false),
|
||||
$data['group'] ?? null,
|
||||
);
|
||||
|
||||
return response()->json([
|
||||
|
||||
@@ -26,6 +26,13 @@ final class LeaderboardController extends Controller
|
||||
);
|
||||
}
|
||||
|
||||
public function groups(Request $request, LeaderboardService $leaderboards): JsonResponse
|
||||
{
|
||||
return response()->json(
|
||||
$leaderboards->getLeaderboard(Leaderboard::TYPE_GROUP, (string) $request->query('period', 'weekly'))
|
||||
);
|
||||
}
|
||||
|
||||
public function stories(Request $request, LeaderboardService $leaderboards): JsonResponse
|
||||
{
|
||||
return response()->json(
|
||||
|
||||
35
app/Http/Controllers/Api/Search/GroupSearchController.php
Normal file
35
app/Http/Controllers/Api/Search/GroupSearchController.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Controllers\Api\Search;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\GroupDiscoveryService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
final class GroupSearchController extends Controller
|
||||
{
|
||||
public function __construct(private readonly GroupDiscoveryService $groups) {}
|
||||
|
||||
public function __invoke(Request $request): JsonResponse
|
||||
{
|
||||
$q = trim((string) $request->query('q', ''));
|
||||
if (mb_strlen($q) < 2) {
|
||||
return response()->json(['data' => []]);
|
||||
}
|
||||
|
||||
$perPage = min(max((int) $request->query('per_page', 6), 1), 12);
|
||||
$items = array_map(function (array $group): array {
|
||||
$group['group_type'] = $group['type'] ?? null;
|
||||
$group['type'] = 'group';
|
||||
|
||||
return $group;
|
||||
}, $this->groups->searchCards($q, $request->user(), $perPage));
|
||||
|
||||
return response()->json([
|
||||
'data' => $items,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -32,6 +32,7 @@ use Carbon\Carbon;
|
||||
use App\Uploads\Jobs\VirusScanJob;
|
||||
use App\Uploads\Services\PublishService;
|
||||
use App\Services\Activity\UserActivityService;
|
||||
use App\Services\ArtworkAttributionService;
|
||||
use App\Uploads\Exceptions\UploadNotFoundException;
|
||||
use App\Uploads\Exceptions\UploadOwnershipException;
|
||||
use App\Uploads\Exceptions\UploadPublishValidationException;
|
||||
@@ -39,6 +40,8 @@ use App\Uploads\Services\ArchiveInspectorService;
|
||||
use App\Uploads\Services\DraftQuotaService;
|
||||
use App\Uploads\Exceptions\DraftQuotaException;
|
||||
use App\Models\Artwork;
|
||||
use App\Models\Group;
|
||||
use App\Services\GroupArtworkReviewService;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
final class UploadController extends Controller
|
||||
@@ -555,7 +558,7 @@ final class UploadController extends Controller
|
||||
], Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function publish(string $id, Request $request, PublishService $publishService)
|
||||
public function publish(string $id, Request $request, PublishService $publishService, ArtworkAttributionService $attribution)
|
||||
{
|
||||
$user = $request->user();
|
||||
|
||||
@@ -572,6 +575,14 @@ final class UploadController extends Controller
|
||||
'publish_at' => ['nullable', 'string', 'date'],
|
||||
'timezone' => ['nullable', 'string', 'max:64'],
|
||||
'visibility' => ['nullable', 'string', 'in:public,unlisted,private'],
|
||||
'group' => ['nullable', 'string', 'max:90'],
|
||||
'primary_author_user_id' => ['nullable', 'integer', 'min:1'],
|
||||
'contributor_user_ids' => ['nullable', 'array', 'max:20'],
|
||||
'contributor_user_ids.*' => ['integer', 'min:1'],
|
||||
'contributor_credits' => ['nullable', 'array', 'max:20'],
|
||||
'contributor_credits.*.user_id' => ['required', 'integer', 'min:1'],
|
||||
'contributor_credits.*.credit_role' => ['nullable', 'string', 'max:80'],
|
||||
'contributor_credits.*.is_primary' => ['nullable', 'boolean'],
|
||||
]);
|
||||
|
||||
$mode = $validated['mode'] ?? 'now';
|
||||
@@ -623,6 +634,8 @@ final class UploadController extends Controller
|
||||
}
|
||||
$artwork->slug = Str::limit($slugBase, 160, '');
|
||||
$artwork->artwork_timezone = $validated['timezone'] ?? null;
|
||||
$artwork->uploaded_by_user_id = $artwork->uploaded_by_user_id ?: (int) $user->id;
|
||||
$artwork->primary_author_user_id = $artwork->primary_author_user_id ?: (int) $user->id;
|
||||
|
||||
// Sync category if provided
|
||||
$categoryId = isset($validated['category']) ? (int) $validated['category'] : null;
|
||||
@@ -643,6 +656,9 @@ final class UploadController extends Controller
|
||||
$artwork->tags()->sync($tagIds);
|
||||
}
|
||||
|
||||
$artwork->save();
|
||||
$artwork = $attribution->apply($artwork->fresh(['group.members']), $user, $validated);
|
||||
|
||||
if ($mode === 'schedule' && $publishAt) {
|
||||
// Scheduled: store publish_at but don't make public yet
|
||||
$artwork->visibility = $visibility;
|
||||
@@ -735,4 +751,56 @@ final class UploadController extends Controller
|
||||
return response()->json(['message' => $e->getMessage()], Response::HTTP_UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
}
|
||||
|
||||
public function submitForReview(string $id, Request $request, GroupArtworkReviewService $reviews)
|
||||
{
|
||||
$user = $request->user();
|
||||
|
||||
$validated = $request->validate([
|
||||
'title' => ['nullable', 'string', 'max:150'],
|
||||
'description' => ['nullable', 'string'],
|
||||
'category' => ['nullable', 'integer', 'exists:categories,id'],
|
||||
'tags' => ['nullable', 'array', 'max:15'],
|
||||
'tags.*' => ['string', 'max:64'],
|
||||
'is_mature' => ['nullable', 'boolean'],
|
||||
'nsfw' => ['nullable', 'boolean'],
|
||||
'timezone' => ['nullable', 'string', 'max:64'],
|
||||
'visibility' => ['nullable', 'string', 'in:public,unlisted,private'],
|
||||
'group' => ['required', 'string', 'max:90'],
|
||||
'primary_author_user_id' => ['nullable', 'integer', 'min:1'],
|
||||
'contributor_user_ids' => ['nullable', 'array', 'max:20'],
|
||||
'contributor_user_ids.*' => ['integer', 'min:1'],
|
||||
'contributor_credits' => ['nullable', 'array', 'max:20'],
|
||||
'contributor_credits.*.user_id' => ['required', 'integer', 'min:1'],
|
||||
'contributor_credits.*.credit_role' => ['nullable', 'string', 'max:80'],
|
||||
'contributor_credits.*.is_primary' => ['nullable', 'boolean'],
|
||||
]);
|
||||
|
||||
if (! ctype_digit($id)) {
|
||||
return response()->json(['message' => 'Artwork review submission requires an artwork draft id.'], Response::HTTP_UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
$artwork = Artwork::query()->find((int) $id);
|
||||
if (! $artwork) {
|
||||
return response()->json(['message' => 'Artwork not found.'], Response::HTTP_NOT_FOUND);
|
||||
}
|
||||
|
||||
if ((int) $artwork->user_id !== (int) $user->id && (int) ($artwork->uploaded_by_user_id ?? 0) !== (int) $user->id) {
|
||||
return response()->json(['message' => 'Forbidden.'], Response::HTTP_FORBIDDEN);
|
||||
}
|
||||
|
||||
$group = Group::query()->with('members')->where('slug', (string) $validated['group'])->first();
|
||||
if (! $group) {
|
||||
return response()->json(['message' => 'Group not found.'], Response::HTTP_NOT_FOUND);
|
||||
}
|
||||
|
||||
$artwork = $reviews->submit($group, $artwork, $user, $validated);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'artwork_id' => (int) $artwork->id,
|
||||
'status' => 'submitted_for_review',
|
||||
'group_review_status' => (string) $artwork->group_review_status,
|
||||
], Response::HTTP_OK);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user