CRM Pilates is an application to manage Pilates classroom for small and medium Pilates offices.
- CRM Pilates is made over
python 3.9.9
- You need to install poetry
- You need to install postgres and libpq in order to run tests and run the app locally
- You will need a private key to encrypt / decrypt user password (default is provided for tests purpose only), to generate one, just run:
openssl rand -hex 32
and keep this key in a safe place (provide the value to the environment keySECRET_KEY
)
Documentation:
Everything is in the Makefile
Run a python interpreter in your shell once everything is installed and run the following
>>> from passlib.context import CryptContext
>>> pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
>>> pwd_context.hash('password')
'$2b$12$t.OhZvTO6xAFtUrqdrxkgO9z23VlK0wzkMKg4fESjll6CwayKswXu'
And then execute the following SQL request on your database
INSERT INTO users VALUES (1, 'bertrand', '$2b$12$t.OhZvTO6xAFtUrqdrxkgO9z23VlK0wzkMKg4fESjll6CwayKswXu')
Nat Pryce ADR tools
ADR index is kept here
make install
will install the virtual env, all needed dependencies, setup your local environment and setup local sqlite database
- in tests folder run
docker-compose up
in order to boot a postgres database for tests make test
will run all the tests (you can specifyargs="--db-type sqlite"
orargs="--db-type postgres"
to run tests under sqlite (by default) or postgres)make coverage
will run coverage
NB:
- Postgres event store test use the postgres test connection (that means you need a postgres installed locally to run the tests)
make run
will run the application with all the modules
There is a Dockerfile
within root directory. It builds the api then creates an image.
There is also a docker-compose.yml
file
docker-compose --env-file .env.local up
will:- boot a postgres database container named
crm-pilates-postgres
(login:crm-pilates
, password:example
) - boot an adminer container
- boot the
crm-pilates-api
and load the events persisted in database
- boot a postgres database container named
The API documentation is available in 3 formats:
Resources are authenticated by a JWT with header Authorization: Bearer TOKEN_VALUE
.
To retrieve a token, you need to authenticate on /token
(see below)
- Run the API (see above section)
- Insert a user in user table (encrypt your password with the key provided in docker-compose
⚠️ for local installation purpose only!) - Use the
curl
command line as belowExpected result:curl -X POST http://localhost:8081/token -d 'username=[USERNAME]&password=[PASSWORD]' -H 'Content-Type: application/x-www-form-urlencoded' -v | jq
{ "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJiZXJ0cmFuZCIsImV4cCI6MTY2MTM2NjQ3Mn0.VM37LH4JR0AHn_sn1iGBADhpDh9SoOM9wDc4oDdzmYo", "type": "bearer" }
- The token is valid during 30 minutes
- Run the API (see above section)
- Use the
curl
command line as belowExpected result:curl http://localhost:8081/classrooms -X POST --data '{"name": "advanced class", "start_date": "2021-05-10T10:00", "position": 3, "duration": {"duration": 50, "unit": "MINUTE"}, "subject": "MAT"}' -H "Content-Type: application/json" -H "Authorization: Bearer [TOKEN_VALUE]" -v | jq
{ "name": "advanced class", "id": "33da6f12-efda-4c16-b8af-e5e822fc5459", "position": 3, "start_date": "2021-05-10T10:00:00", "stop_date": null, "duration": { "duration": 50, "unit": "MINUTE" } }
- Run the API (see above section)
- Use the
curl
command line as belowExpected result:curl http://localhost:8081/clients -X POST --data '{"firstname": "John", "lastname": "Doe"}' -H "Content-Type: application/json" -H "Authorization: Bearer [TOKEN_VALUE]" -v | jq
{ "firstname": "John", "lastname": "Doe", "id": "33da6f12-efda-4c16-b8af-e5e822fc5459", }
- Run the API (see above section)
- Create a classroom (see above section)
- Use the
curl
command line as belowExpected result:curl http://localhost:8081/classrooms/{id} -X PATCH --data '{"attendees": [{"id": "A_CLIENT_ID"}]}' -H "Content-Type: application/json" -H "Authorization: Bearer [TOKEN_VALUE]" -v
HTTP/1.1 204 No Content
- Run the API (see above section)
- Add attendees to a classroom (see above section)
- Use the
curl
command line as belowcurl http://localhost:8081/sessions/checkin -X POST --data '{"classroom_id": "CLASSROOM_ID", "session_date": "SESSION_DATE", "attendee": "ATTENDEE_ID"}' -H"Content-Type: application/json" -H "Authorization: Bearer [TOKEN_VALUE]" -v | jq