Page 1 of 1

Extension and Rest API

Posted: 31 May 2018, 15:31
by imaresca91
Hello!,

I recently builded a new extension (myproject/ext) and configured it for creating a new table called departaments with the corresponding Item and Manager (I am not sure is I did the things right). But now I need to create a CRUD for that table so I can manipulate the data from another server.
I was wondering if someone can help me with this issue.
Sorry for my poor english, I wish you can understand.

Thanks for the help!.

Re: Extension and Rest API

Posted: 31 May 2018, 21:23
by aimeos
You can manage your data by creating a new endpoint by implementing a JsonAdm class and template. Look at the existing endpoints (classes) in the ai-admin-jsonadm package:
https://github.com/aimeos/ai-admin-json ... in/jsonadm

Re: Extension and Rest API

Posted: 01 Jun 2018, 09:44
by imaresca91
Thank you very much for quick reply!.

I created:
1 - JsonAdmin Standard class (ext\departaments\admin\jsonadm\src\admin\JsonAdmin\Standard.php).
2 - Departament Standard class (ext\departaments\admin\jsonadm\src\admin\JsonAdmin\Departament\Standard.php).
3 - Template get-standard.php (ext\departaments\admin\jsonadm\templates\get-standard.php)

Doubts and comments:
1, 3 - The code of this classes are the same like the github that was specified in the last reply.
2 - I attach the code of the getListItems function, namespace and extends/implement class because I am not sure if it is ok.
In the getListItems, where I have to implement the departaments/list...?
Code:

Code: Select all

protected function getListItems( array $items, array $include )
    {
        $manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'departament/lists' );
        $search = $manager->createSearch();
        $expr = array(
            $search->compare( '==', 'departament.lists.parentid', array_keys( $items ) ),
            $search->compare( '==', 'departament.lists.domain', $include ),
        );
        $search->setConditions( $search->combine( '&&', $expr ) );
        return $manager->searchItems( $search );
    }
} 

Code: Select all

namespace ext\departaments\admin\jsonadm\src\admin\JsonAdmin\Departament;

Code: Select all

class Standard extends \Aimeos\Admin\JsonAdm\Standard implements \Aimeos\Admin\JsonAdm\Common\Iface
Then i tried Admin/JSONAPI tutorial (https://aimeos.org/docs/Developers/Admi ... e_metadata) but I could not access to my departaments data. Perhaps I have to register my new endpoint in the resources options.

Please, let me know if something is not clear so I can explain it again. I am new at aimeos core.

Thank you very much for the help!. And congratulations about the library!.

Re: Extension and Rest API

Posted: 01 Jun 2018, 21:00
by aimeos
You don't need to copy the Standard.php class. If you have no list or property table related to your department table, I think you don't have to create a class at all because it's then handled by the Standard.php class. As you mentioned correctly, you need to configure your "department" class so it will be added to the meta information:
https://github.com/aimeos/ai-admin-json ... e.php#L144

Re: Extension and Rest API

Posted: 05 Jun 2018, 16:02
by imaresca91
Hello!,

Thank you very much for you reply!.

I just configured my extension correctly. But the problem now is that I have to pass a Laravel cookie to tell Laravel I am athenticated and let me work with my department's CRUD. Also, I tried using passport:client token but it does not work. So the question is, how can I deal with aimeos jsonadm/department requests (GET, POST, PATCH, etc..) without passing a Laravel cookie.

Thanks for your help!.

Re: Extension and Rest API

Posted: 06 Jun 2018, 07:21
by aimeos
You can't because you have to authenticate first. Otherwise, everyone could add, modify or delete records from your shop and believe me, you don't want that!

Re: Extension and Rest API

Posted: 06 Jun 2018, 08:20
by imaresca91
But I don't want to use it without athentication. That's why I want to use passport and an access token.
Aimeos works fine with Laravel passport?, because I didn't have success on it.