Skip to content

Commit

Permalink
Merge pull request #9 from RapidKit/fix/new-skaleton-based-on-base
Browse files Browse the repository at this point in the history
fix: new skaleton based on new base
  • Loading branch information
ramaID authored Jun 16, 2024
2 parents 9e68bfe + 6461413 commit 8cc10c0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 60 deletions.
77 changes: 18 additions & 59 deletions stubs/controller.stub
Original file line number Diff line number Diff line change
Expand Up @@ -2,71 +2,30 @@

namespace App\Http\Controllers\Api;

// use App\Data\UserData as DataObject; // TODO: sesuaikan class data
use App\Http\Controllers\Controller;
// use App\Models\User as Model; // TODO: sesuaikan class model
use Illuminate\Http\Response;
use Spatie\LaravelData\PaginatedDataCollection;
use App\Models\User as Model; // TODO: sesuaikan class model
use App\Http\Requests\AuthorStoreRequest as StoreRequest;
use App\Http\Requests\AuthorUpdateRequest as UpdateRequest;
use RapidKit\LaravelRestify\Bases\BaseRequest;

class {{ name }} extends Controller
class {{ name }} extends \RapidKit\LaravelRestify\Bases\BaseController
{
public function __construct(public Model $model)
{
$this->middleware('auth:sanctum')->only(['store', 'update', 'destroy']);
}

/**
* Display a listing of the resource.
*
* @return PaginatedDataCollection<array-key, DataObject>
*/
public function index()
{
return DataObject::collect(
$this->model->query()->paginate()
);
public function __construct(
protected Model $model,
) {
}

/**
* Store a newly created resource in storage.
*/
public function store(DataObject $data): DataObject
public function model(): Model
{
$attributes = $data->toArray();
$model = $this->model->query()->create($attributes);

return DataObject::from($model);
return $this->model;
}

/**
* Display the specified resource.
*/
public function show(
Model $model // TODO: adjust route param
): DataObject {
return DataObject::from($model);
}
// public function store(BaseRequest $base): Author
// {
// return parent::store(AuthorStoreRequest::createFrom($base));
// }

/**
* Update the specified resource in storage.
*/
public function update(
DataObject $data,
Model $model, // TODO: adjust route param
): Response {
$model->update($data->toArray());

return response()->noContent();
}

/**
* Remove the specified resource from storage.
*/
public function destroy(
Model $model // TODO: adjust route param
): Response {
$model->delete();

return response()->noContent();
}
// public function update(BaseRequest $base, string|int $id): \Illuminate\Http\Response
// {
// return parent::update(AuthorUpdateRequest::createFrom($base), $id);
// }
}
2 changes: 1 addition & 1 deletion stubs/data.stub
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace App\Data;

#[\Spatie\TypeScriptTransformer\Attributes\TypeScript]
final class {{ name }} extends \Spatie\LaravelData\Data
final class {{ name }} extends \RapidKit\LaravelRestify\Bases\BaseData
{
public function __construct(
// TODO: sesuaikan dengan migration
Expand Down

0 comments on commit 8cc10c0

Please sign in to comment.