Folders
This commit is contained in:
parent
bd5d85fc9f
commit
fc491543c2
|
|
@ -3,6 +3,7 @@
|
|||
namespace Sarga\API\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Sarga\API\Http\Requests\FolderRequest;
|
||||
use Sarga\API\Http\Resources\Checkout\CartResource;
|
||||
use Sarga\API\Http\Resources\Customer\FolderResource;
|
||||
|
|
@ -26,8 +27,11 @@ class Wishlists extends WishlistController
|
|||
{
|
||||
$customer = $request->user();
|
||||
|
||||
$wishlist = $request->has('folder') ? $customer->wishlist_items()->where('folder_id',$request->folder)
|
||||
:$customer->wishlist_items();
|
||||
|
||||
return response([
|
||||
'data' => WishListResource::collection($customer->wishlist_items()->paginate(10)),
|
||||
'data' => WishListResource::collection($wishlist->paginate(10)),
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
@ -64,7 +68,7 @@ class Wishlists extends WishlistController
|
|||
'product_id' => $id,
|
||||
'customer_id' => $customer->id,
|
||||
'price' => $product->min_price ?? $product->price,
|
||||
'folder_id' => $request->folder_id
|
||||
// 'folder_id' => $request->folder_id
|
||||
]);
|
||||
|
||||
return response([
|
||||
|
|
@ -114,17 +118,52 @@ class Wishlists extends WishlistController
|
|||
], 400);
|
||||
}
|
||||
|
||||
public function moveToFolder(Request $request, $folder_id){
|
||||
$customer = $request->user();
|
||||
|
||||
if($this->wishlistRepository->where('customer_id',$customer->id)
|
||||
->whereIn('id',$request->wishlist)
|
||||
->update(['folder_id' => $folder_id])){
|
||||
|
||||
// $folder = app(FolderRepository::class)->with('wishlist')->find($folder_id);
|
||||
|
||||
return response([
|
||||
// 'data' => FolderResource::make($folder),
|
||||
'message' => __('sarga-api::app.wishlist.success-add'),
|
||||
]);
|
||||
}
|
||||
|
||||
return response([
|
||||
// 'data' => FolderResource::make($folder),
|
||||
'message' => __('sarga-api::app.wishlist.success-add'),
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
public function folders(FolderRepository $folderRepository){
|
||||
$customer = request()->user();
|
||||
return FolderResource::collection($folderRepository->findWhere(['customer_id' => $customer->id]));
|
||||
|
||||
$folders = $folderRepository->where('customer_id', $customer->id)
|
||||
->with(['wishlist'=> function($q){
|
||||
$q->take(4);
|
||||
}])
|
||||
->withCount('wishlist')
|
||||
->get();
|
||||
|
||||
return FolderResource::collection($folders);
|
||||
}
|
||||
|
||||
public function getFolder($id)
|
||||
{
|
||||
if($folder = app(FolderRepository::class)->with('wishlist')->find($id))
|
||||
{
|
||||
return FolderResource::make($folder);
|
||||
if($wishlist = $this->wishlistRepository->findWhere([
|
||||
'channel_id' => core()->getCurrentChannel()->id,
|
||||
'folder_id' => $id
|
||||
])->paginate(10)){
|
||||
return response([
|
||||
'data' => WishListResource::collection($wishlist),
|
||||
]);
|
||||
}
|
||||
|
||||
return response(['message' => 'Folder not found'],404);
|
||||
}
|
||||
|
||||
|
|
@ -133,7 +172,10 @@ class Wishlists extends WishlistController
|
|||
$folderRepo = app(FolderRepository::class);
|
||||
|
||||
if($folder = $folderRepo->create(['name' => $request->name, 'customer_id' => $request->user()->id])){
|
||||
return FolderResource::make($folder);
|
||||
return response([
|
||||
'message' => 'Successfully created folder',
|
||||
'data'=>FolderResource::make($folder)
|
||||
],200);
|
||||
}
|
||||
|
||||
return response(['message' => 'Folder creation failed'],400);
|
||||
|
|
|
|||
|
|
@ -18,7 +18,8 @@ class FolderResource extends JsonResource
|
|||
return [
|
||||
'id' => $this->id,
|
||||
'name' => $this->name,
|
||||
'items' => WishlistResource::collection($this->wishlist)
|
||||
'items' => WishlistResource::collection($this->wishlist),
|
||||
'items_count' => $this->wishlist_count ?? 0
|
||||
|
||||
];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -91,6 +91,7 @@ Route::group(['prefix' => 'api'], function () {
|
|||
Route::get('wishlist', [Wishlists::class, 'index']);
|
||||
Route::post('wishlist/{id}', [Wishlists::class, 'addOrRemove']);
|
||||
Route::post('wishlist/{id}/move-to-cart', [Wishlists::class, 'moveToCart']);
|
||||
Route::post('folder/{id}/move-to-folder', [Wishlists::class, 'moveTofolder']);
|
||||
Route::get('folders',[Wishlists::class, 'folders']);
|
||||
|
||||
Route::post('folder',[Wishlists::class, 'createFolder']);
|
||||
|
|
|
|||
Loading…
Reference in New Issue