client_repo = $client_repo; } /** * @OA\Get( * path="/api/v1/clients", * operationId="getClients", * tags={"clients"}, * summary="Gets a list of clients", * description="Lists clients, search and filters allow fine grained lists to be generated. Query parameters can be added to performed more fine grained filtering of the clients, these are handled by the ClientFilters class which defines the methods available", * @OA\Parameter(ref="#/components/parameters/X-Api-Secret"), * @OA\Parameter(ref="#/components/parameters/X-Api-Token"), * @OA\Parameter(ref="#/components/parameters/X-Requested-With"), * @OA\Parameter(ref="#/components/parameters/include"), * @OA\Parameter(ref="#/components/parameters/index"), * @OA\Response( * response=200, * description="A list of clients", * @OA\Header(header="X-API-TOKEN", ref="#/components/headers/X-API-TOKEN"), * @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"), * @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"), * @OA\JsonContent(ref="#/components/schemas/Client"), * ), * @OA\Response( * response=422, * description="Validation error", * @OA\JsonContent(ref="#/components/schemas/ValidationError"), * ), * @OA\Response( * response="default", * description="Unexpected Error", * @OA\JsonContent(ref="#/components/schemas/Error"), * ), * ) * */ public function index(ClientFilters $filters) { $clients = Client::filter($filters); return $this->listResponse($clients); } /** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show(ShowClientRequest $request, Client $client) { return $this->itemResponse($client); } /** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit(EditClientRequest $request, Client $client) { return $this->itemResponse($client); } /** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param App\Models\Client $client * @return \Illuminate\Http\Response */ public function update(UpdateClientRequest $request, Client $client) { $client = $this->client_repo->save($request->all(), $client); return $this->itemResponse($client); } /** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function create(CreateClientRequest $request) { $client = ClientFactory::create(auth()->user()->company()->id, auth()->user()->id); return $this->itemResponse($client); } /** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(StoreClientRequest $request) { $client = $this->client_repo->save($request->all(), ClientFactory::create(auth()->user()->company()->id, auth()->user()->id)); $client->load('contacts', 'primary_contact'); return $this->itemResponse($client); } /** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy(DestroyClientRequest $request, Client $client) { //may not need these destroy routes as we are using actions to 'archive/delete' $client->delete(); return response()->json([], 200); } /** * Perform bulk actions on the list view * * @return Collection */ public function bulk() { $action = request()->input('action'); $ids = request()->input('ids'); $clients = Client::withTrashed()->find($ids); $clients->each(function ($client, $key) use($action){ if(auth()->user()->can('edit', $client)) $this->client_repo->{$action}($invoice); }); return $this->listResponse(Client::withTrashed()->whereIn('id', $ids)); } /** * Returns a client statement * * @return [type] [description] */ public function statement() { //todo } }