Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API: implement method POST to /objects endpoint #714

Closed
batopa opened this issue Jun 23, 2015 · 3 comments
Closed

API: implement method POST to /objects endpoint #714

batopa opened this issue Jun 23, 2015 · 3 comments

Comments

@batopa
Copy link
Member

batopa commented Jun 23, 2015

/objects endpoint has to support POST request to create new objects.

We could use POST to create new relations, children, etc... on existent object. For example

  • /objects/13/relations/attach create new relations attach to object 13
  • /objects/1/children create new children of object 1
@batopa batopa self-assigned this Jun 23, 2015
@batopa batopa added this to the 3-stable milestone Jun 23, 2015
batopa added a commit that referenced this issue Jul 8, 2015
batopa added a commit that referenced this issue Jul 8, 2015
also move check on writableObjects in ApiValidator
batopa added a commit that referenced this issue Jul 8, 2015
batopa added a commit that referenced this issue Jul 8, 2015
batopa added a commit that referenced this issue Jul 8, 2015
Save in private attribute $relations to avoid to perform the same operations many times
Every time the config is cached the $relations attribute is generated
batopa added a commit that referenced this issue Jul 8, 2015
to save relations on existent object
batopa added a commit that referenced this issue Jul 8, 2015
batopa added a commit that referenced this issue Jul 9, 2015
batopa added a commit that referenced this issue Jul 9, 2015
@batopa
Copy link
Member Author

batopa commented Jul 10, 2015

Implemented POST /objects

Added ApiValidatorComponent to validate data from client and other stuff.

To save objects you have to define in configuration what object types are allowed

$config['api'] = array(
   ....
    'validation' => array(
        'writableObjects' => array('document', 'event')
    )
);

or from ApiController

public $components = array(
        'ResponseHandler' => array('type' => 'json'),
        'ApiFormatter',
        'ApiValidator' => array(
            'writableObjects' => array('document', 'event')
        ),
        'BeAuthJwt'
    );

Saving new objects (user has to be authenticated) data from client must contain:

  • object_type
  • at least a parent (parents key) accessible (with right permission for user authorized) on publication tree or at least a relation (relations key) with another object reachable (where reachable means an accessible object on tree or related to an accessible object on tree).

Example of valid data from client:

{
    "data": {
        "title": "My title",
        "object_type": "event",
        "description": "bla bla bla",
        "parents": [1, 34, 65],
        "relations": {
            "attach": [
                {
                    "related_id": 12,
                    "params": {
                        "label": "foobar"
                    }
                },
                {
                    "related_id": 23
                }
            ],
            "seealso": [
                {
                    "related_id": 167
                }   
            ]
        },
        "categories": ["name-category-one", "name-category-two"],
        "tags": ["name-tag_one", "name-tag-two"],
        "geo_tags": [
            {
                "title": "geo tag title",
                "address": "via ....",
                "latitude": 43.012,
                "longitude": 10.45
            }
        ],
        "date_items": [
            {
                "start_date": "2015-07-08T15:00:35+0200",
                "end_date": "2015-07-08T15:00:35+0200",
                "days": [0,3,4]
            },
            {
                "start_date": "2015-09-01T15:00:35+0200",
                "end_date": "2015-09-30T15:00:35+0200"
            }
        ]
    }
}

dates must be in ISO 8601 format.

You can use POST also to update an existent object. In that case the object id has to be passed in "data" object from client and object_type can be omitted.

batopa added a commit that referenced this issue Jul 14, 2015
save/update children of :id
@batopa
Copy link
Member Author

batopa commented Jul 17, 2015

GET /objects/10/relations/attach to add/edit relation attach to object 10 implemented.

To add/edit a relation the client payload should for example

{
    "data": {
        "related_id": 15,
        "priority": 1,
        "params": {
            "label": "lorem"
        }
    }
}

If relation attach between 10 and 15 not exists it will be created else it will be updated. If relation is created and missing priority it will set to max value on db + 1.

To add/update many relations at once client has to pass an array of relations data:

{
    "data": [
        {
            "related_id": 12,
            "priority": 1,
            "params": {
                "label": "lorem"
            }
        },
        {
            "related_id": 13,
        },
        {
            "related_id": 9
        }
    ]
}

@batopa
Copy link
Member Author

batopa commented Aug 12, 2015

@batopa batopa closed this as completed Aug 12, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant