A write up of my thought process while developing this solution can be found here.
- Docker
- Postgres docker image
- Ruby & rails
- A good attitude
First pull down the postgres docker image:
docker pull postgres
next, start the container:
docker run --name postgres-db -e POSTGRES_PASSWORD=test -d -p 5555:5432 postgres
This will start the container (postgres-db) on port 5555 and initialize a postgres user with the password test. From your db connection of choice, connect to the db with the postgres user and execute the db_setup.sql to create a new database. Once the database, in a new db connection, connect to the guild database and run the table_setup.sql script.
Optional: you can run the db_seed.rb script to seed the database:
> gem install faker
> gem install pg
> ruby ./db/db_seed.rd
wait! Installing pg didn't work for me!
In order to install pg, you need to have postgres installed locally. Which is a problem if you're just using docker...
Fortunately, it seems like you can install pg with just the libpq libraries.
Note: For the sake of simplicity, I'm using the default postgres user and a simple password. This should be a much more secure password, and passed in via an env var.
> cd server/
> bundle install
> bundle exec rackup --host 0.0.0.0 -p 3000
> docker build --tag ruby-server .
> docker run -p 3000:3000 ruby-server
Note: You'll need to configure a docker network for the containers to talk to each other locally, due to time constrains, I wasn't able to finish the docker compose file in time. In order for the application to talk to the container, you'll want to run the server on the host machine, rather than from the container, else you'll get a db connection error.
> cd ./server
> gem install rspec
> rspec test.rb
Parameters:
recipientId: Int,
limit: Int //required
offset: Int,
Response
{
"messages": [
{
"messageId": "2751",
"senderId": "3",
"receiverId": "2",
"message": "Id omnis architecto. Delectus dolor voluptas. Sed ut non.",
"timestamp": "2021-01-04 17:28:06"
},
...
],
"limit": 100,
"offset": 0
}
Request:
{
'recieverId': Int,
'message': int,
'timestamp': DateTime
}
Some final thoughts about the implementation and trade offs can be viewed here.