Skip to content

Commit

Permalink
Fix PostGres container;
Browse files Browse the repository at this point in the history
Add entities MunicipalGeometry, StateGeometry and UserPoint

Create Migragion file.
  • Loading branch information
Rafaellcx committed Feb 20, 2024
1 parent 35ddeb6 commit ccbc5e3
Show file tree
Hide file tree
Showing 52 changed files with 10,865 additions and 1 deletion.
36 changes: 36 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# In all environments, the following files are loaded if they exist,
# the latter taking precedence over the former:
#
# * .env contains default values for the environment variables needed by the app
# * .env.local uncommitted file with local overrides
# * .env.$APP_ENV committed environment-specific defaults
# * .env.$APP_ENV.local uncommitted environment-specific overrides
#
# Real environment variables win over .env files.
#
# DO NOT DEFINE PRODUCTION SECRETS IN THIS FILE NOR IN ANY OTHER COMMITTED FILES.
# https://symfony.com/doc/current/configuration/secrets.html
#
# Run "composer dump-env prod" to compile .env files for production use (requires symfony/flex >=1.2).
# https://symfony.com/doc/current/best_practices.html#use-environment-variables-for-infrastructure-configuration

###> symfony/framework-bundle ###
APP_ENV=dev
APP_SECRET=5aff844a62c54caf46a41aeebd52417b
###< symfony/framework-bundle ###

###> doctrine/doctrine-bundle ###
# Format described at https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url
# IMPORTANT: You MUST configure your server version, either here or in config/packages/doctrine.yaml
#
# DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db"
# DATABASE_URL="mysql://app:[email protected]:3306/app?serverVersion=8.0.32&charset=utf8mb4"
# DATABASE_URL="mysql://app:[email protected]:3306/app?serverVersion=10.11.2-MariaDB&charset=utf8mb4"
#DATABASE_URL="postgresql://postgres:[email protected]:5432/geo-polygons?serverVersion=16&charset=utf8"
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
POSTGRES_DB=geo-polygons
POSTGRES_VERSION=14
#DATABASE_URL="postgresql://postgres:[email protected]:5432/geo-polygons?serverVersion=14&charset=utf8"
DATABASE_URL="postgresql://postgres:postgres@geo-polygons-postgres:5432/geo-polygons?serverVersion=14&charset=utf8"
###< doctrine/doctrine-bundle ###
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

###> symfony/framework-bundle ###
/.env.local
/.env.local.php
/.env.*.local
/config/secrets/prod/prod.decrypt.private.php
/public/bundles/
/var/
/vendor/
###< symfony/framework-bundle ###
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3,719 changes: 3,719 additions & 0 deletions .idea/commandlinetools/Symfony_20_02_2024_13_46.xml

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/geo-polygons-symfony.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

78 changes: 78 additions & 0 deletions .idea/php.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 61 additions & 1 deletion README.md
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1 +1,61 @@
# geo-polygons-symfony
## About

TerraQ - Backend test. This test was created to assess your skills in developing a backend application
that integrates geospatial functionalities. The goal is to create an API that interacts with a
PostgreSQL database with the PostGIS extension, providing endpoints for the manipulation and querying
of geospatial data.
Created some items like Contracts, Seeders, Dependency Injection, Docker in Laravel 10.


## Objectives:
1) Install and Configure PostGIS on PostgreSQL;
2) Set up the PostgreSQL environment with PostGIS in Symfony migrations. This should be done to prepare the database for geospatial operations;
3) Create Geospatial Feature Tables

- Table **municipal_geometry**: To store the geometries of municipalities in São Paulo (SP) and Minas Gerais (MG).
Municipalities should be created from the provided GeoJSONs. This table should have the fields "id," "name"
(municipality name), and "geom" (geometry).
- Table **state_geometry**: To store the geometries of states São Paulo (SP) and Minas Gerais (MG).
This table should be created by processing the data from each state's municipalities and performing
a join/dissolve to form the state's geometry. This table should have the fields "id," "name" (state name),
and "geom."
Create the **state_geometry** and **municipal_geometry** tables using the **GeoJSONs** of São Paulo municipalities
and the GeoJSONs of Minas Gerais municipalities as inputs.
- Table **pontos_usuario**: To store points posted by users, with fields for "id," "latitude," "longitude,"
"municipal_id" (municipality ID), and "geom."
- PS: The geometry columns of the created tables should be of type Geometry, have the name "geom," and be in SRID 4326.
4) Develop Specific Endpoints:

- Location Query by Latitude and Longitude (/api/municipal/find): Endpoint to receive latitude and longitude and return the corresponding municipality or an error if not found.
- CRUD for Points (/api/user-point): Implement a complete CRUD to manipulate the "user_points" table, with the methods POST, GET, PUT, DELETE.

## Solution
Made using the Symfony 7 framework, PostgreSQL database with
PostGIS(PostGIS extends the capabilities of the PostgreSQL relational database
by adding support for storing, indexing, and querying geospatial data.) and
Docker for application containerization.

## How to run the project

After downloading the **geo-polygons-symfony** repository, being in its main folder, go up the structure composed of the following containers:

- **geo-polygons-symfony-back:** Composed with nginx and PHP, being exposed to port `9000`;
- **geo-polygons-postgres:** With the PostgreSQL database.

1) Through the following commands:
```sh
docker-compose build --no-cache
```
2) After building the containers, execute the command below to start it.
```sh
docker-compose up -d
```

After finishing the creation of the containers, we must execute the commands below so that the environment is ready to be used:

1. Execute the migrations with the command below to populate the database with the necessary tables of the solution:

```
docker exec -it geo-polygons-symfony-back php bin/console doctrine:migrations:migrate --no-interaction
```
2. Used to populate the tables (Required):
17 changes: 17 additions & 0 deletions bin/console
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env php
<?php

use App\Kernel;
use Symfony\Bundle\FrameworkBundle\Console\Application;

if (!is_file(dirname(__DIR__).'/vendor/autoload_runtime.php')) {
throw new LogicException('Symfony Runtime is missing. Try running "composer require symfony/runtime".');
}

require_once dirname(__DIR__).'/vendor/autoload_runtime.php';

return function (array $context) {
$kernel = new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);

return new Application($kernel);
};
82 changes: 82 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{
"type": "project",
"license": "proprietary",
"minimum-stability": "stable",
"prefer-stable": true,
"require": {
"php": ">=8.1",
"ext-ctype": "*",
"ext-iconv": "*",
"doctrine/doctrine-bundle": "^2.11",
"doctrine/doctrine-migrations-bundle": "^3.3",
"doctrine/orm": "^3.0",
"jms/serializer": "^3.29",
"jsor/doctrine-postgis": "*",
"phpdocumentor/reflection-docblock": "^5.3",
"phpstan/phpdoc-parser": "^1.25",
"symfony/console": "7.0.*",
"symfony/dotenv": "7.0.*",
"symfony/flex": "^2",
"symfony/form": "7.0.*",
"symfony/framework-bundle": "7.0.*",
"symfony/property-access": "7.0.*",
"symfony/property-info": "7.0.*",
"symfony/runtime": "7.0.*",
"symfony/serializer": "7.0.*",
"symfony/validator": "7.0.*",
"symfony/yaml": "7.0.*"
},
"config": {
"allow-plugins": {
"php-http/discovery": true,
"symfony/flex": true,
"symfony/runtime": true
},
"sort-packages": true
},
"autoload": {
"psr-4": {
"App\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"App\\Tests\\": "tests/"
}
},
"replace": {
"symfony/polyfill-ctype": "*",
"symfony/polyfill-iconv": "*",
"symfony/polyfill-php72": "*",
"symfony/polyfill-php73": "*",
"symfony/polyfill-php74": "*",
"symfony/polyfill-php80": "*",
"symfony/polyfill-php81": "*",
"symfony/polyfill-php82": "*"
},
"scripts": {
"auto-scripts": {
"cache:clear": "symfony-cmd",
"assets:install %PUBLIC_DIR%": "symfony-cmd"
},
"post-install-cmd": [
"@auto-scripts"
],
"post-update-cmd": [
"@auto-scripts"
]
},
"conflict": {
"symfony/symfony": "*"
},
"extra": {
"symfony": {
"allow-contrib": false,
"require": "7.0.*"
}
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.5",
"symfony/maker-bundle": "^1.53"
}
}
Loading

0 comments on commit ccbc5e3

Please sign in to comment.