mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-22 14:31:26 +00:00
Update CollectionsController, add new self route
This commit is contained in:
parent
e47353f1fd
commit
bc2495c676
2 changed files with 135 additions and 111 deletions
|
@ -2,25 +2,15 @@
|
|||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Auth;
|
||||
use App\{
|
||||
Collection,
|
||||
CollectionItem,
|
||||
Profile,
|
||||
Status
|
||||
};
|
||||
use League\Fractal;
|
||||
use App\Transformer\Api\{
|
||||
AccountTransformer,
|
||||
StatusTransformer,
|
||||
};
|
||||
use League\Fractal\Serializer\ArraySerializer;
|
||||
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
|
||||
use App\Collection;
|
||||
use App\CollectionItem;
|
||||
use App\Services\AccountService;
|
||||
use App\Services\CollectionService;
|
||||
use App\Services\FollowerService;
|
||||
use App\Services\StatusService;
|
||||
use App\Status;
|
||||
use Auth;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class CollectionController extends Controller
|
||||
{
|
||||
|
@ -31,10 +21,11 @@ class CollectionController extends Controller
|
|||
|
||||
$collection = Collection::firstOrCreate([
|
||||
'profile_id' => $profile->id,
|
||||
'published_at' => null
|
||||
'published_at' => null,
|
||||
]);
|
||||
$collection->visibility = 'draft';
|
||||
$collection->save();
|
||||
|
||||
return view('collection.create', compact('collection'));
|
||||
}
|
||||
|
||||
|
@ -52,12 +43,14 @@ class CollectionController extends Controller
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
return view('collection.show', compact('collection'));
|
||||
}
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
abort_if(! Auth::check(), 403);
|
||||
|
||||
return $request->all();
|
||||
}
|
||||
|
||||
|
@ -67,7 +60,7 @@ class CollectionController extends Controller
|
|||
$this->validate($request, [
|
||||
'title' => 'nullable|max:50',
|
||||
'description' => 'nullable|max:500',
|
||||
'visibility' => 'nullable|string|in:public,private,draft'
|
||||
'visibility' => 'nullable|string|in:public,private,draft',
|
||||
]);
|
||||
|
||||
$pid = $request->user()->profile_id;
|
||||
|
@ -78,6 +71,7 @@ class CollectionController extends Controller
|
|||
$collection->save();
|
||||
|
||||
CollectionService::deleteCollection($id);
|
||||
|
||||
return CollectionService::setCollection($collection->id, $collection);
|
||||
}
|
||||
|
||||
|
@ -87,7 +81,7 @@ class CollectionController extends Controller
|
|||
$this->validate($request, [
|
||||
'title' => 'nullable|max:50',
|
||||
'description' => 'nullable|max:500',
|
||||
'visibility' => 'required|alpha|in:public,private,draft'
|
||||
'visibility' => 'required|alpha|in:public,private,draft',
|
||||
]);
|
||||
$profile = Auth::user()->profile;
|
||||
$collection = Collection::whereProfileId($profile->id)->findOrFail($id);
|
||||
|
@ -99,6 +93,7 @@ class CollectionController extends Controller
|
|||
$collection->visibility = $request->input('visibility');
|
||||
$collection->published_at = now();
|
||||
$collection->save();
|
||||
|
||||
return CollectionService::setCollection($collection->id, $collection);
|
||||
}
|
||||
|
||||
|
@ -126,7 +121,7 @@ class CollectionController extends Controller
|
|||
|
||||
$this->validate($request, [
|
||||
'collection_id' => 'required|int|min:1|exists:collections,id',
|
||||
'post_id' => 'required|int|min:1'
|
||||
'post_id' => 'required|int|min:1',
|
||||
]);
|
||||
|
||||
$profileId = $request->user()->profile_id;
|
||||
|
@ -161,7 +156,7 @@ class CollectionController extends Controller
|
|||
$item = CollectionItem::firstOrCreate([
|
||||
'collection_id' => $collection->id,
|
||||
'object_type' => 'App\Status',
|
||||
'object_id' => $status->id
|
||||
'object_id' => $status->id,
|
||||
], [
|
||||
'order' => $count,
|
||||
]);
|
||||
|
@ -280,7 +275,7 @@ class CollectionController extends Controller
|
|||
abort_if(! $request->user(), 403);
|
||||
$this->validate($request, [
|
||||
'collection_id' => 'required|int|min:1|exists:collections,id',
|
||||
'post_id' => 'required|int|min:1'
|
||||
'post_id' => 'required|int|min:1',
|
||||
]);
|
||||
|
||||
$profileId = $request->user()->profile_id;
|
||||
|
@ -319,4 +314,31 @@ class CollectionController extends Controller
|
|||
|
||||
return 200;
|
||||
}
|
||||
|
||||
public function getSelfCollections(Request $request)
|
||||
{
|
||||
abort_if(! $request->user(), 404);
|
||||
$user = $request->user();
|
||||
$pid = $user->profile_id;
|
||||
|
||||
$profile = AccountService::get($pid, true);
|
||||
if (! $profile || ! isset($profile['id'])) {
|
||||
return response()->json([], 404);
|
||||
}
|
||||
|
||||
return Collection::whereProfileId($pid)
|
||||
->orderByDesc('id')
|
||||
->paginate(9)
|
||||
->map(function ($collection) {
|
||||
$c = CollectionService::getCollection($collection->id);
|
||||
$c['items'] = collect(CollectionService::getItems($collection->id))
|
||||
->map(function ($id) {
|
||||
return StatusService::get($id, false);
|
||||
})->filter()->values();
|
||||
|
||||
return $c;
|
||||
})
|
||||
->filter()
|
||||
->values();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -133,6 +133,7 @@ Route::group(['prefix' => 'api'], function() use($middleware) {
|
|||
Route::post('update/{id}', 'CollectionController@store')->middleware($middleware);
|
||||
Route::delete('delete/{id}', 'CollectionController@delete')->middleware($middleware);
|
||||
Route::post('remove', 'CollectionController@deleteId')->middleware($middleware);
|
||||
Route::get('self', 'CollectionController@getSelfCollections')->middleware($middleware);
|
||||
});
|
||||
|
||||
Route::group(['prefix' => 'direct'], function () use($middleware) {
|
||||
|
@ -264,6 +265,7 @@ Route::group(['prefix' => 'api'], function() use($middleware) {
|
|||
Route::post('update/{id}', 'CollectionController@store')->middleware($middleware);
|
||||
Route::delete('delete/{id}', 'CollectionController@delete')->middleware($middleware);
|
||||
Route::post('remove', 'CollectionController@deleteId')->middleware($middleware);
|
||||
Route::get('self', 'CollectionController@getSelfCollections')->middleware($middleware);
|
||||
});
|
||||
|
||||
Route::group(['prefix' => 'compose'], function () use($middleware) {
|
||||
|
|
Loading…
Reference in a new issue