/openpicnic-api

An API for the OpenPicNic application

Primary LanguageJavaScriptMIT LicenseMIT

openpicnic-api

An API for the OpenPicNic application

Installation

Define the following environment variables:

Database connection:

  • DATABASE_HOST - the host of the database
  • DATABASE_PORT - the port of the database
  • DATABASE_NAME - the name of the database
  • DATABASE_USER - the user of the database
  • DATABASE_PASSWORD - the password of the database

The URL of the site

  • SITE_URL - the url of the site
  • PORT - the port of the site

Connection to the API server

  • API_USERNAME - the username of the API server
  • API_PASSWORD - the password of the API server

⚠ You must be define the following environment variables in the .env file otherwise the application will not work.

Requirements

Software

  • NodeJS v16.18.1 (or higher) (required)
  • MySQL v10.5.15 (or higher) (required)
  • PM2 v5.1.2 (or higher) (optional)
  • PHPMyAdmin v5.0.4 (or higher) (optional)
  • Apache v2.4.54 (or higher) (optional)
  • FTP Server (vsftpd) (required)

Dependencies

  • Express
  • MySQL
  • Dotenv

Information

If the installation fails, delete the package-lock.json file and run npm install again.

Usage/Examples

Start the server

NPM

  npm start

PM2

  pm2 start npm --name "openpicnic-api" -- start

Authentication

The API uses basic authentication. The username and password are defined in the environment variables.

API Reference

Get all users

  GET /api/users

Get a user

  GET /api/users?id=${id} or /api/users?email=${email}
Parameter Type Description
id number Required. User id
email string Required. User email

Create a user

  POST /api/users
Parameter Type Description
nom string Required. User last name
prenom string Required. User first name
email string Required. User email
password string Required. User password
isAdmin boolean Not required. User is admin
idAvatar number Not required. User avatar id

Update a user

  PUT /api/users
Parameter Type Description
id number Required. User id
nom string Not required. User last name
prenom string Not required. User first name
email string Not required. User email
password string Not required. User password
isAdmin boolean Not required. User is admin
idAvatar number Not required. User avatar id

Delete a user

  DELETE /api/users?id=${id}
Parameter Type Description
id number Required. User id

Get all avatars

  GET /api/avatar

Get an avatar

  GET /api/avatar?idAvatar=${idAvatar}
Parameter Type Description
idAvatar number Required. Avatar id

Create an avatar

  POST /api/avatar
Parameter Type Description
nomAvatar string Required. Avatar name
imageURL string Required. Avatar image url

Update an avatar

  PUT /api/avatar
Parameter Type Description
idAvatar number Required. Avatar id
nomAvatar string Not required. Avatar name
imageURL string Not required. Avatar image url

Delete an avatar

  DELETE /api/avatar?idAvatar=${idAvatar}
Parameter Type Description
idAvatar number Required. Avatar id

Get all attributes

  GET /api/attribut

Get an attribute

  GET /api/attribut?idE=${idE}&idL=${idL}
Parameter Type Description
idE number Required. Equipment id
idL number Required. Location id

Create an attribute

  POST /api/attribut
Parameter Type Description
idE number Required. Equipment id
idL number Required. Location id

Delete an attribute

  DELETE /api/attribut?idE=${idE}&idL=${idL}
Parameter Type Description
idE number Required. Equipment id
idL number Required. Location id

Get all equipments

  GET /api/equipement

Get an equipment

  GET /api/equipement?id=${id} or /api/equipement?description=${description}
Parameter Type Description
id number Required. Equipment id
description string Required. Equipment description

Create an equipment

  POST /api/equipement
Parameter Type Description
description string Required. Equipment description

Update an equipment

  PUT /api/equipement
Parameter Type Description
id number Required. Equipment id
description string Not required. Equipment description

Delete an equipment

  DELETE /api/equipement?id=${id}
Parameter Type Description
id number Required. Equipment id

Get all locations

  GET /api/localisation

Get a location

  GET /api/localisation?id=${id} or /api/localisation?nom=${nom}
Parameter Type Description
id number Required. Location id
nom string Required. Location name

Create a location

  POST /api/localisation
Parameter Type Description
nom string Required. Location name
description string Not required. Location description
imageURL string Not required. Location image url
note string Not required. Location note
latitude number Not required. Location latitude
longitude number Not required. Location longitude

Update a location

  PUT /api/localisation
Parameter Type Description
id number Required. Location id
nom string Not required. Location name
description string Not required. Location description
imageURL string Not required. Location image url
note string Not required. Location note
latitude number Not required. Location latitude
longitude number Not required. Location longitude

Delete a location

  DELETE /api/localisation?id=${id}
Parameter Type Description
id number Required. Location id

Get all avis

  GET /api/avis

Get an avis

  GET /api/avis?idU=${idU}&idL=${idL}
Parameter Type Description
idU number Required. User id
idL number Required. Location id

Create an avis

  POST /api/avis
Parameter Type Description
idU number Required. User id
idL number Required. Location id
titre string Not required. Avis title
message string Not required. Avis message
dateAvis string Not required. Avis date
note number Not required. Avis note

Update an avis

  PUT /api/avis
Parameter Type Description
idU number Required. User id
idL number Required. Location id
titre string Not required. Avis title
message string Not required. Avis message
dateAvis string Not required. Avis date
note number Not required. Avis note

Delete an avis

  DELETE /api/avis?idU=${idU}&idL=${idL}
Parameter Type Description
idU number Required. User id
idL number Required. Location id

Get all favorites

  GET /api/favoris

Get a favorite

  GET /api/favoris?idU=${idU}&idL=${idL}
Parameter Type Description
idU number Required. User id
idL number Required. Location id

Create a favorite

  POST /api/favoris
Parameter Type Description
idU number Required. User id
idL number Required. Location id

Delete a favorite

  DELETE /api/favoris?idU=${idU}&idL=${idL}
Parameter Type Description
idU number Required. User id
idL number Required. Location id

Tools and technologies

Authors

License

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