Commit 4690c1db585f0f989a6eefb116bb3318074319c7

Authored by Alex Savenko
1 parent 5177e547

create project

app/library/App/Model/Project.php 0 → 100644
  1 +<?php
  2 +
  3 +namespace App\Model;
  4 +
  5 +class Project extends \App\Mvc\DateTrackingModel
  6 +{
  7 + public $id;
  8 + public $name;
  9 + public $user_id;
  10 +
  11 + public function getSource()
  12 + {
  13 + return 'project';
  14 + }
  15 +
  16 + public function columnMap()
  17 + {
  18 + return parent::columnMap() + [
  19 + 'id' => 'id',
  20 + 'name' => 'name',
  21 + 'user_id' => 'user_id'
  22 + ];
  23 + }
  24 +
  25 + public function initialize() {
  26 +
  27 + $this->belongsTo('user_id', User::class, 'id', [
  28 + 'alias' => 'User',
  29 + ]);
  30 + }
  31 +}
... ...
app/library/App/Resources/ProjectResource.php 0 → 100644
  1 +<?php
  2 +/**
  3 + * Created by PhpStorm.
  4 + * User: Alex Savenko
  5 + * Date: 09.02.2017
  6 + * Time: 14:38
  7 + */
  8 +
  9 +namespace App\Resources;
  10 +
  11 +use PhalconRest\Api\ApiEndpoint;
  12 +use PhalconRest\Api\ApiResource;
  13 +use App\Model\Project;
  14 +use PhalconRest\Transformers\ModelTransformer;
  15 +use App\Constants\AclRoles;
  16 +use PhalconRest\Mvc\Controllers\CrudResourceController;
  17 +
  18 +class ProjectResource extends ApiResource {
  19 +
  20 + public function initialize()
  21 + {
  22 + $this
  23 + ->name('Project')
  24 + ->model(Project::class)
  25 + ->expectsJsonData()
  26 + ->transformer(ModelTransformer::class)
  27 + ->itemKey('project')
  28 + ->collectionKey('projects')
  29 + ->deny(AclRoles::UNAUTHORIZED)
  30 + ->handler(CrudResourceController::class)
  31 +
  32 + ->endpoint(ApiEndpoint::all())
  33 + ->endpoint(ApiEndpoint::create())
  34 + ->endpoint(ApiEndpoint::find())
  35 + ->endpoint(ApiEndpoint::update())
  36 + ->endpoint(ApiEndpoint::remove());
  37 + }
  38 +
  39 +}
0 40 \ No newline at end of file
... ...