Explanation on how to setup entities for automagic and use in Primate
Entities are concepts inside your project that will have at least:
Storage in database
Enpoints to read, write, update or delete
In this manner, to have an entity we need a group of things described in the following article.
Database Model
For Primate, our ORM is Prisma. In this manner, the database model should exist inside the schema.prisma.
Routes
For the entity to be consumed we need at least one route. In primate, there is a default way to give your entity CrUD capabilities. This can be achieved doing the following:
Create an /entitites folder in the root of your project
Create a folder with the plural name of your entity, for example: /entities/users
Create a file called /entities/[plural/][plural].js for your routes, for example: /entities/users/users.js
Finally, add your routes inside the file in the following way:
This will give the following response when typing http://localhost:1337/[plural]/foo:
Automagic CrUD routes
Part of the automagic of Primate is that it gives automatically a way to Create, Update and Delete entities. To setup the automagic CrUD, you need the following code in your route file:
This will give you automatically the following routes:
GET /[plural] for listing all elements
GET /[plural]/:id for geting one element
POST /[plural] for creating one element
PUT /[plural]/:id for updating one element
DELETE /[plural]/:id for deleting one element
GET /[plural]/:id/metas for getting the metas of one element