mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-08 20:22:42 +01:00
CRUD
This commit is contained in:
parent
8b4c1d25da
commit
dc981b40ab
169
app/Console/Commands/stubs/api-controller.stub
Normal file
169
app/Console/Commands/stubs/api-controller.stub
Normal file
@ -0,0 +1,169 @@
|
||||
<?php
|
||||
|
||||
namespace $NAMESPACE$;
|
||||
|
||||
//use Response;
|
||||
//use Input;
|
||||
//use App\Models\$STUDLY_NAME$;
|
||||
use App\Http\Controllers\BaseAPIController;
|
||||
use Modules\$STUDLY_NAME$\Repositories\$STUDLY_NAME$Repository;
|
||||
use Modules\$STUDLY_NAME$\Http\Requests\$STUDLY_NAME$Request;
|
||||
use Modules\$STUDLY_NAME$\Http\Requests\Create$STUDLY_NAME$Request;
|
||||
use Modules\$STUDLY_NAME$\Http\Requests\Update$STUDLY_NAME$Request;
|
||||
|
||||
class $STUDLY_NAME$ApiController extends BaseAPIController
|
||||
{
|
||||
protected $$STUDLY_NAME$Repo;
|
||||
protected $entityType = '$LOWER_NAME$';
|
||||
|
||||
public function __construct($STUDLY_NAME$Repository $$LOWER_NAME$Repo)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->$LOWER_NAME$Repo = $$LOWER_NAME$Repo;
|
||||
}
|
||||
|
||||
/**
|
||||
* @SWG\Get(
|
||||
* path="/$LOWER_NAME$",
|
||||
* summary="List of $LOWER_NAME$",
|
||||
* tags={"$LOWER_NAME$"},
|
||||
* @SWG\Response(
|
||||
* response=200,
|
||||
* description="A list with $LOWER_NAME$",
|
||||
* @SWG\Schema(type="array", @SWG\Items(ref="#/definitions/$STUDLY_NAME$"))
|
||||
* ),
|
||||
* @SWG\Response(
|
||||
* response="default",
|
||||
* description="an ""unexpected"" error"
|
||||
* )
|
||||
* )
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$data = $this->$LOWER_NAME$Repo->all();
|
||||
|
||||
return $this->listResponse($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @SWG\Get(
|
||||
* path="/$LOWER_NAME$/{$LOWER_NAME$_id}",
|
||||
* summary="Individual $STUDLY_NAME$",
|
||||
* tags={"$LOWER_NAME$"},
|
||||
* @SWG\Response(
|
||||
* response=200,
|
||||
* description="A single $LOWER_NAME$",
|
||||
* @SWG\Schema(type="object", @SWG\Items(ref="#/definitions/$STUDLY_NAME$"))
|
||||
* ),
|
||||
* @SWG\Response(
|
||||
* response="default",
|
||||
* description="an ""unexpected"" error"
|
||||
* )
|
||||
* )
|
||||
*/
|
||||
|
||||
public function show($STUDLY_NAME$Request $request)
|
||||
{
|
||||
return $this->itemResponse($request->entity());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @SWG\Post(
|
||||
* path="/$LOWER_NAME$",
|
||||
* tags={"$LOWER_NAME$"},
|
||||
* summary="Create a $LOWER_NAME$",
|
||||
* @SWG\Parameter(
|
||||
* in="body",
|
||||
* name="body",
|
||||
* @SWG\Schema(ref="#/definitions/$STUDLY_NAME$")
|
||||
* ),
|
||||
* @SWG\Response(
|
||||
* response=200,
|
||||
* description="New $LOWER_NAME$",
|
||||
* @SWG\Schema(type="object", @SWG\Items(ref="#/definitions/$STUDLY_NAME$"))
|
||||
* ),
|
||||
* @SWG\Response(
|
||||
* response="default",
|
||||
* description="an ""unexpected"" error"
|
||||
* )
|
||||
* )
|
||||
*/
|
||||
public function store(Create$STUDLY_NAME$Request $request)
|
||||
{
|
||||
$$LOWER_NAME$ = $this->$LOWER_NAME$Repo->save($request->input());
|
||||
|
||||
return $this->itemResponse($$LOWER_NAME$);
|
||||
}
|
||||
|
||||
/**
|
||||
* @SWG\Put(
|
||||
* path="/$LOWER_NAME$/{$LOWER_NAME$_id}",
|
||||
* tags={"$LOWER_NAME$"},
|
||||
* summary="Update a $LOWER_NAME$",
|
||||
* @SWG\Parameter(
|
||||
* in="body",
|
||||
* name="body",
|
||||
* @SWG\Schema(ref="#/definitions/$STUDLY_NAME$")
|
||||
* ),
|
||||
* @SWG\Response(
|
||||
* response=200,
|
||||
* description="Update $LOWER_NAME$",
|
||||
* @SWG\Schema(type="object", @SWG\Items(ref="#/definitions/$STUDLY_NAME$"))
|
||||
* ),
|
||||
* @SWG\Response(
|
||||
* response="default",
|
||||
* description="an ""unexpected"" error"
|
||||
* )
|
||||
* )
|
||||
*/
|
||||
|
||||
public function update(Update$STUDLY_NAME$Request $request, $publicId)
|
||||
{
|
||||
if ($request->action) {
|
||||
return $this->handleAction($request);
|
||||
}
|
||||
|
||||
//$data = $request->input();
|
||||
//$data['public_id'] = $publicId;
|
||||
$$LOWER_NAME$ = $this->$LOWER_NAME$Repo->save($request->input(), $request->entity());
|
||||
|
||||
return $this->itemResponse($$LOWER_NAME$);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @SWG\Delete(
|
||||
* path="/$LOWER_NAME$/{$LOWER_NAME$_id}",
|
||||
* tags={"$LOWER_NAME$"},
|
||||
* summary="Delete a $LOWER_NAME$",
|
||||
* @SWG\Parameter(
|
||||
* in="body",
|
||||
* name="body",
|
||||
* @SWG\Schema(ref="#/definitions/$STUDLY_NAME$")
|
||||
* ),
|
||||
* @SWG\Response(
|
||||
* response=200,
|
||||
* description="Delete $LOWER_NAME$",
|
||||
* @SWG\Schema(type="object", @SWG\Items(ref="#/definitions/$STUDLY_NAME$"))
|
||||
* ),
|
||||
* @SWG\Response(
|
||||
* response="default",
|
||||
* description="an ""unexpected"" error"
|
||||
* )
|
||||
* )
|
||||
*/
|
||||
|
||||
public function destroy(Update$STUDLY_NAME$Request $request)
|
||||
{
|
||||
$$LOWER_NAME$ = $request->entity();
|
||||
|
||||
$this->$LOWER_NAME$Repo->delete($$LOWER_NAME$);
|
||||
|
||||
return $this->itemResponse($$LOWER_NAME$);
|
||||
}
|
||||
|
||||
}
|
34
app/Console/Commands/stubs/transformer.stub
Normal file
34
app/Console/Commands/stubs/transformer.stub
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace $NAMESPACE$;
|
||||
|
||||
use Modules\$STUDLY_NAME$\Models\$STUDLY_NAME$;
|
||||
use App\Ninja\Transformers\EntityTransformer;
|
||||
|
||||
/**
|
||||
* @SWG\Definition(definition="$STUDLY_NAME$", @SWG\Xml(name="$STUDLY_NAME$"))
|
||||
*/
|
||||
|
||||
class $STUDLY_NAME$Transformer extends EntityTransformer
|
||||
{
|
||||
/**
|
||||
* @SWG\Property(property="id", type="integer", example=1, readOnly=true)
|
||||
* @SWG\Property(property="user_id", type="integer", example=1)
|
||||
* @SWG\Property(property="account_key", type="string", example="123456")
|
||||
* @SWG\Property(property="updated_at", type="timestamp", example="")
|
||||
* @SWG\Property(property="archived_at", type="timestamp", example="1451160233")
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param $STUDLY_NAME$ $$LOWER_NAME$
|
||||
* @return array
|
||||
*/
|
||||
public function transform($STUDLY_NAME$ $$LOWER_NAME$)
|
||||
{
|
||||
return array_merge($this->getDefaults($$LOWER_NAME$), [
|
||||
'id' => (int) $$LOWER_NAME$->public_id,
|
||||
'updated_at' => $this->getTimestamp($$LOWER_NAME$->updated_at),
|
||||
'archived_at' => $this->getTimestamp($$LOWER_NAME$->deleted_at),
|
||||
]);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user