Skip to content

recchia/url-shortener

Repository files navigation

URL Shortener

Application for generate short url version from long urls, developed with Symfony 6.0, Api Platform and queues. PostgreSQL as Database and Queue service. You can use Postman or develop a js client to try the app following the api docs.

How to

  • To list more frequently accessed urls use: http(s)://{domain}/api/short_urls?page=1&itemsPerPage=100&order%5Bhits%5D=desc
  • To create a new one make a post request to: http(s)://{domain}:8000/api/short_urls with the following payload:
{
  "longUrl": "valid_url"
}

###Requirements:

  • Docker
  • Docker Compose

###Steps for setup

1 - Get the project:

git clone [email protected]:recchia/url-shortener.git
cd shortener

2 - create the following environment variables or left default in docker-compose:

POSTGRES_VERSION=13
POSTGRES_DB=database_name
POSTGRES_PASSWORD=database_password
POSTGRES_USER=database_user

and copy .env file as .env.local, make sure the DATABASE_URL has the same values as docker-compose database.

3 - Start containers:

docker-compose up -d

4 - Install vendors:

docker-compose exec php composer install

5 - Install and compile assets:

docker-compose exec php yarn install
docker-compose exec php yarn dev

6 - Execute Migrations:

 docker-compose exec php bin/console d:m:m

7 - Execute worker:

docker-compose exec php bin/console messenger:consume async

8 - Load in browser:

  • http://{domain}/api for Api docs (swagger UI)
  • http://{domain}/{shortUrlId} to redirect

Run Test Suite

Create test database

docker-compose exec php bin/console d:d:c --env=test

Execute Migrations

 docker-compose exec php bin/console d:m:m --env=test

Load Fixtures

docker-compose exec php bin/console d:f:load --env=test

Run tests

docker-compose exec php php bin/phpunit --testdox