Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/thiagomartins367/mc-code-challenge-backend-developer
Code challenge de desenvolvimento da "Multiverse Travels Booker API", uma API que gerencia o planejamento de viagens no universo de Rick and Morty. Wubbalubbadubdub!
https://github.com/thiagomartins367/mc-code-challenge-backend-developer
crystal docker jennifer kemal
Last synced: 9 days ago
JSON representation
Code challenge de desenvolvimento da "Multiverse Travels Booker API", uma API que gerencia o planejamento de viagens no universo de Rick and Morty. Wubbalubbadubdub!
- Host: GitHub
- URL: https://github.com/thiagomartins367/mc-code-challenge-backend-developer
- Owner: thiagomartins367
- License: mit
- Created: 2023-07-10T22:49:05.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-07-10T22:55:07.000Z (over 1 year ago)
- Last Synced: 2024-10-06T03:05:52.163Z (3 months ago)
- Topics: crystal, docker, jennifer, kemal
- Language: Crystal
- Homepage:
- Size: 50.8 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Multiverse Travels Booker API
This documentation specifies the code for the Multiverse Travels Booker API, intended to manage travel plans in the Rick and Morty universe.
On the home page path `/` you can see the documentation of the API features in
[Swagger](https://swagger.io/).## Installation and Usage
NOTE: It is necessary to have installed the [Crystal](https://crystal-lang.org) language
and the [MySQL](https://dev.mysql.com/downloads/mysql) database management system.1. Install dependencies
```
# Run command
shards install
```2. Build application
```
# Run command
crystal build --static --release src/api.cr -o bin/api
```3. Configuring `Jennifer ORM` database connection settings
```
# File path: ./config/database.ymldefault: &default
user: # database access user
password: # user password
adapter: mysql
skip_dumping_schema_sql: true# ...
production:
<<: *default
db: multiverse_travels_booker # database name
host: # connection host (Ex: localhost)
port: # Connection port (Ex: "3306") [Warning: Port needs to be in `String` format]# ...
```
4. Creating the database and tables
NOTE: The database and table creation commands use the commands listed in the `Makefile` file.```
# Run command to create the database:
make sam db:create# Then run command to create the database tables:
make sam db:migrate# At the end, check that the database and tables were created
```4. Start API
```
# Run command
KEMAL_ENV=production APP_ENV=production ./bin/api# The `KEMAL ENV` and `APP_ENV` variables are required to use the production version of the API.
```5. Check logs in terminal
```
# If everything went well then you will see the logs below:# ...
# [production] Kemal is ready to lead at http://0.0.0.0:3000
# ...
```## Usage in Docker
If you have both [Docker](https://www.docker.com)
and [Docker compose](https://docs.docker.com/compose/install) installed,
you can save a lot of effort.To start the API in the Docker, just run 1 command:
```
# Run command
docker-compose up -d# Container log:
# ...
# [production] Kemal is ready to lead at http://0.0.0.0:3000
# ...
```
Once the containers are working the API can be used.## Development
To develop new features or refactor it is recommended to use Docker, as it provides an isolated and properly configured environment in the `docker-compose.dev.yml` file.
1. Definindo variáveis de ambiente e configurações de conexão
- Create a `./db/.env.development.local` file using the `./db/.env.development.local.example` file.
- Set a password for the `root` database user in the `MYSQL_ROOT_PASSWORD` environment variable which will be used in the database container.
- Create a `./.env.development.local` file using the `./.env.development.local.example` file.
- Set a value for each variable listed in the file.
- Create and configure the `Jennifer ORM` connection file in `./config/database.yml`.
```
# File path: ./config/database.ymldefault: &default
user: root
password: # user password (Same as defined in MYSQL_ROOT_PASSWORD variable)
adapter: mysql
skip_dumping_schema_sql: true# ...
development:
<<: *default
db: dev_multiverse_travels_booker
host: dev_db_multiverse_travels_booker # Container Docker
port: "3306" # Connection port [Warning: Port needs to be in `String` format]# ...
```
2. Starting the development environment
- To create the development Docker environment run the command below:
```
# Run command
docker-compose -f docker-compose.dev.yml up -d
```
After this process, both the API and the database will be working.
NOTE: An initial command `seed` is run every time containers are built to populate the database with data for development.
NOTE: The use of the `make` scripts/commands listed in the `Makefile` file is recommended in the development environment to speed up the development process.## Contributors
- [THIAGO MARTINS](https://github.com/thiagomartins367) - creator and maintainer