This is a RESTful API for managing salons, developed with Node.js, Express, MySQL, and Docker. The API allows for CRUD operations on salon data, including the ability to seed initial data, retrieve salon details, and more.
- Basic Authentication for secure access.
- MySQL-based database for storing salon data and working hours.
- API routes for managing salons (
/api/salons). - Database seeding endpoint for populating salons data.
- Support for CORS.
- Logging requests using Morgan.
- Docker support for easy deployment.
Before running this project, ensure that you have the following installed on your local machine:
-
Clone the repository:
git clone https://github.com/p-force/salon-management-api.git cd salon-management-api -
Install dependencies:
npm install
-
Create a
.envfile based on the.env.example:cp .env.example .env
Fill in the necessary values for the database and basic authentication credentials.
-
Setup Database:
Ensure that your MySQL database is properly configured and accessible. To create the required tables, use the
dump.sqlfile:mysql -u DB_USER -h DB_HOST -P DB_PORT -p DB_DATABASE < dump.sqlReplace
DB_USER,DB_HOST,DB_PORT, andDB_DATABASEwith the corresponding values from your.envfile. -
Start the server:
npm start
The API will be running at
http://localhost:8080(or the port specified in the.envfile).
Basic Authentication is enabled for all API routes. The credentials are set in the .env file under BASIC_AUTH_LOGIN and BASIC_AUTH_PASSWORD.
- GET
/api/salons- Get a list of all salons. - GET
/api/salons/:id- Get detailed information about a specific salon by ID. - GET
/api/salons/random/:count?- Get a random salon or a random selection of salons (default is 1). - GET
/api/salons/seed- Seed the database with sample data.
- GET
/logout- Log out (Invalidate session, respond with status 401).
- 404 - Any unmatched route will return a 404 response.
The project comes with a Dockerfile and amvera.yaml to deploy the project on the Amvera platform. To deploy the project with Docker
The database consists of two tables:
-
salons
id: Integer, Auto Increment, Primary Keyname: String, Not Nulladdress: String, Not Nullphone: String, Not Nullimage_url: String
-
working_hours
id: Integer, Auto Increment, Primary Keysalon_id: Integer, Foreign Key tosalons.idopen_time: Timeclose_time: Time
- src/database/Database.js - Contains the database connection logic and methods for interacting with the database.
- src/routes/index.js - Defines the API routes and connects them to the database.
- .env - Configuration file for environment variables such as database credentials and basic authentication credentials.
- Dockerfile - The file used to build a Docker image for the application.
- amvera.yaml - Configuration for deploying the application on the Amvera platform.
This project is licensed under the MIT License - see the LICENSE file for details.