Skip to content

Repository files navigation

WerckerAURGitHub last commitGitHub contributors

JavaScript PurAí API for Node.js

Module in Node.js, Express and MySQL that provides an RESTful API. Made with MVC pattern. Support for authorization and authentication with JWT tokens.

This project package the following functions:

  • Events
  • Categories
  • Sale Places
  • User
  • Login

Features must be added:

Installation

Get via git clone:

$ git clone https://github.com/purai/nodejs_api.git
$ cd nodejs_api

Create a MySQL database without any tables. Then just set the database config at db-connect.js file:

constconnection=mysql.createConnection({host: 'localhost',port: 3306,user: 'root',password: 'root',database: 'purai_app'});

All tables will be add when server get started. You can, optionally, uncomment this call method at db-connect.js to add sample data in the tables: addSampleData(connection)

Get dependencies with Yarn:

$ yarn install

Usage

Start the server with yarn start.

The application will automatically restart when files get changed due nodemon.

server

And the application will start at http://localhost:3000.

Documentation

Used Swagger framework to document and test.

http://localhost:3000/documentation/

Getting a Token

Send a POST request to http://localhost:3000/login with user parameters.

{
"email": "string",
"password": "string"
}

To request locked methods set the header key Authorization and the token as value.

Curl request example with token

curl -X POST "http://localhost:3000/events" -H "accept: application/json" -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6InN0cmluZ0BzdHJpbmcuY29tIiwidXNlcklkIjoiZDViNzJjMDAiLCJpYXQiOjE1MzUyMjcwNTh9.OcIZ0EMDale9Ry5PvDYQAKtup1znaQc2Iti1iBPaBlE"

Login Endpoints

POST http://localhost:3000/login

ParameterTypeRequiredDescription
bodyobjectPass login data object in body

Login object example with sample data

{
"email": "admin@mail.com",
"password": "admin"
}

User Endpoints

GET http://localhost:3000/user

ParameterTypeRequiredDescription
statusintGET filtered by status. (1: Active, 0: Inactive)
uuidstringGET filtered by UUID. (e.g.: dbfdd3d0-a808-11e8-aa56-a3de1ec713c5)

DELETE http://localhost:3000/user/{uuid}

ParameterTypeRequiredDescription
uuidstringUser UUID to get deleted

POST http://localhost:3000/user/signup

ParameterTypeRequiredDescription
bodyobjectPass user data object in body

PUT http://localhost:3000/user/{uuid}

ParameterTypeRequiredDescription
uuidstringUser UUID to get changed
bodyobjectPass user data object in body

User data object example

{
"status": 1,
"name": "string",
"email": "string@mail.com",
"password": "string"
}

User data response example

{
"users": [
{
"uuid": "dbfdd3d0-a808-11e8-aa56-a3de1ec713c5",
"status": 1,
"name": "admin",
"email": "admin@mail.com"
}
]
}

Events Endpoints

GET http://localhost:3000/events

ParameterTypeRequiredDescription
statusintGET filtered by status. (1: Active, 0: Inactive)
featuredintGET filtered by featured. (1: True, 0: False)
uuidstringGET filtered by UUID. (e.g.: 955b9575-e542-461c-939a-5ef41e733859)
searchstringGET filtered by term in event title, place, address and city
pageintGET filtered by page number considering limit value. (Default page is 1)
limitintGET filtered by limit informed. If 0 returns all records. (Default value is 10)
upcomingstringdeprecated GET filtered by upcoming events. By default only events with a date greater than or equal to the current date will be returned. Date format yyyy-MM-dd
categorystringGET filtered by terms in category name
saleplacestringGET filtered by terms in sale places name

DELETE http://localhost:3000/events/{uuid}

ParameterTypeRequiredDescription
uuidstringEvent's UUID to get deleted

POST http://localhost:3000/events

ParameterTypeRequiredDescription
bodyobjectPass event data object in body

PUT http://localhost:3000/events/{uuid}

ParameterTypeRequiredDescription
uuidstringEvent's UUID to get changed
bodyobjectPass event data object in body

Event data object example

{
"status": 1,
"featured": 0,
"title": "string",
"image": File,"about": "string",
"price": "string",
"date": "2022-01-01 20:00",
"address": "string",
"city": "string",
"id_category": 1,
"id_sale_place": 1
}

Event data response example

{
"events": [
{
"id": 1,
"uuid": "955b9575-e542-461c-939a-5ef41e733859",
"status": 1,
"featured": 0,
"created_at": "2022-01-01T00:00:00",
"updated_at": "2022-01-01T00:00:00",
"title": "Sample Event",
"image": "http://localhost:3000/uploads/events/sample-event.jpg",
"about": "Sample event description",
"price": "R$ 100,00",
"date": "2022-01-01T00:00:00",
"address": "Apple Campus, Cupertino, CA 95014, EUA",
"city": "Cupertino",
"id_category": 1,
"id_sale_place": 1,
"sale_place": {
"id": 1,
"uuid": "ffd9d343-585a-40ee-bc58-c1e6935dcbdd",
"status": 1,
"title": "Entre em contato para mais detalhes",
"phone": ""
},
"category": {
"id": 1,
"uuid": "1670d1f8-8d9e-46bb-8a19-b85cdd27e016",
"status": 1,
"title": "Festa e Show",
"category_image": "http://localhost:3000/uploads/categories/sample-category.jpg"
}
}
]
}

Categories Endpoints

GET http://localhost:3000/categories

ParameterTypeRequiredDescription
statusintGET filtered by status. (1: Active, 0: Inactive)
uuidstringGET filtered by UUID. (e.g.: 1670d1f8-8d9e-46bb-8a19-b85cdd27e016)
searchstringGET filtered by term in category title
pageintGET filtered by page number considering limit value. (Default page is 1)
limitintGET filtered by limit informed. If 0 returns all records. (Default value is 10)

DELETE http://localhost:3000/categories/{uuid}

ParameterTypeRequiredDescription
uuidstringCategory's UUID to get deleted

POST http://localhost:3000/categories

ParameterTypeRequiredDescription
bodyobjectPass category data object in body

PUT http://localhost:3000/categories/{uuid}

ParameterTypeRequiredDescription
uuidstringCategory's UUID to get changed
bodyobjectPass category data object in body

Category data object example

{
"status": 1,
"title": "string",
"category_image": File
}

Category data response example

{
"categories": [
{
"id": 1,
"uuid": "1670d1f8-8d9e-46bb-8a19-b85cdd27e016",
"status": 1,
"title": "Festa e Show",
"category_image": "http://localhost:3000/uploads/categories/sample-category.jpg"
},
{
"id": 2,
"uuid": "2ddbd4bd-527a-428b-b640-d3f9318b06b8",
"status": 1,
"title": "Curso e Workshop",
"category_image": "http://localhost:3000/uploads/categories/sample-category.jpg"
}
]
}

Sale Places Endpoints

GET http://localhost:3000/salePlaces

ParameterTypeRequiredDescription
statusintGET filtered by status. (1: Active, 0: Inactive)
uuidstringGET filtered by UUID. (e.g.: ffd9d343-585a-40ee-bc58-c1e6935dcbdd)
searchstringGET filtered by term in sale place title
pageintGET filtered by page number considering limit value. (Default page is 1)
limitintGET filtered by limit informed. If 0 returns all records. (Default value is 10)

DELETE http://localhost:3000/salePlaces/{uuid}

ParameterTypeRequiredDescription
uuidstringSale Places' UUID to get deleted

POST http://localhost:3000/salePlaces

ParameterTypeRequiredDescription
bodyobjectPass sale place data object in body

PUT http://localhost:3000/salePlaces/{uuid}

ParameterTypeRequiredDescription
uuidstringSale Places' UUID to get changed
bodyobjectPass sale place data object in body

Sale Place data object example

{
"status": 1,
"title": "string",
"phone": "string"
}

Sale Place data response example

{
"sale_places": [
{
"id": 1,
"uuid": "ffd9d343-585a-40ee-bc58-c1e6935dcbdd",
"status": 1,
"title": "Entre em contato para mais detalhes",
"phone": ""
}
]
}

License

This project is licensed under the GNU GPLv3 License - see the LICENSE file for details

Made with ❤️ by Felipe Mendes.

About

JavaScript PurAí API for Node.js

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages