The Exercise Microservice is a component of the Workout Tracker web application responsible for managing and providing information about various exercises.
- Node.js and npm installed on your development machine.
- A running database (e.g., PostgreSQL) configured for use with Prisma.
- Basic knowledge of JavaScript, Node.js, and Prisma.
-
Clone this repository.
git clone https://github.com/ASE-WS23-GruppeA/exercise-service.git cd exercise-service
-
Install dependencies.
npm install
-
Start the server:
npm start
The service should now be accessible at http://localhost:3000 by default.
The "Workouts Service" uses a PostgreSQL database for storing workout and exercise set data, and it utilizes Prisma as an ORM (Object-Relational Mapping) tool. Follow these steps to configure the database and Prisma:
-
Ensure you have PostgreSQL installed and running on your system.
-
Create a database named "exercises" in PostgreSQL. This can typically be done using a PostgreSQL command line tool or a GUI tool like pgAdmin.
-
Create a
.env
file in the project directory. -
Add the following configuration to the
.env
file with your PostgreSQL database connection URL:DATABASE_URL=your_postgresql_database_url_here
Replace
your_postgresql_database_url_here
with the actual URL for your PostgreSQL database. The URL usually follows the format:postgresql://username:password@localhost:5432/exercises
-
Save the
.env
file.
-
Generate Prisma Client, which is used to access your database in your code:
npx prisma generate
-
Create and apply a new migration to your database. This will set up the initial schema as defined in
schema.prisma
:npx prisma migrate dev --name init
-
After running the migration, verify that the tables have been created in your
exercises
database. -
Insert data at the
exercises
table:node dataInsertion.js
The Exercise Microservice provides the following API endpoints:
GET /exercises
: Retrieve a list of all exercises.GET /exercises/:id
: Retrieve a specific exercise by ID.
To start the microservice, run:
npm start
To retrieve a list of all exercises:
curl http://localhost:3000/exercises
To retrieve a specific exercise by ID (replace 1 with the desired exercise ID):
curl http://localhost:3000/exercises/1