Skip to content

alexdodonov/mezon-crud-service

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Set of classes for creating CRUD services

Open Collective Build Status codecov

Installation

Just print in console

composer require mezon/crud-service

And that's all )

First steps

Now we are ready to create out first CRUD service. Here it is:

/**
 * Service class
 */
class TodoService extends \Mezon\CrudService\CrudService
{

    /**
     * Constructor
     */
    public function __construct()
    {
        parent::__construct([
            'fields' => [
                'id' => [
                    'type' => 'integer'
                ],
                'title' => [
                    'type' => 'string'
                ]
            ],
            'table-name' => 'records',
            'entity-name' => 'record'
        ]);
    }
}

$service = new TodoService();
$service->run();

The main part of this listing is:

parent::__construct([
	'fields' => [
		'id' => [
			'type' => 'integer'
		],
		'title' => [
			'type' => 'string'
		]
	],
	'table-name' => 'records',
	'entity-name' => 'record'
]);

Here we describe a list of fields of our entity, table name where it is stored and entity name.

Default endpoints

Out of the box a list of CRUD endpoints are available:

GET /list/
GET /all/ 
GET /exact/list/[il:ids]/
GET /exact/[i:id]/
GET /fields/
POST|PUT /delete/[i:id]/
POST|DELETE  /delete/
POST|PUT /create/
POST /update/[i:id]/
GET /new/from/[s:date]/
GET /records/count/
GET /last/[i:count]/
GET /records/count/[s:field]