Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POC HAPI #52

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions HDX-example-calls.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# HDX example calls

## Locations

Use `PUT`

```bash
curl -X 'PUT' \
'https://api-test.docksal.site/api/v1/hdx_locations/1' \
-H 'accept: application/json' \
-H 'API-KEY: MY-KEY' \
-H 'APP-NAME: HDX' \
-H 'Content-Type: application/json' \
-d '{
"id": 1,
"code": "AFG",
"name": "Afghanistan",
"is_historical": false,
"valid_date": "2023-08-02",
"hdx_admin1s": []
}'
```

or `POST`

```bash
curl -X 'POST' \
'https://api-test.docksal.site/api/v1/hdx_locations' \
-H 'accept: application/json' \
-H 'API-KEY: MY-KEY' \
-H 'APP-NAME: HDX' \
-H 'Content-Type: application/json' \
-d '{
"code": "MLI",
"name": "Mali",
"is_historical": false,
"valid_date": "2023-09-21"
}'
```

## Admin levels

Use `'Content-Type: application/ld+json'`

You can either use `"location_ref": "1"` or `"location_ref": "/api/v1/hdx_locations/1"`

```bash
curl -X 'POST' \
'https://api-test.docksal.site/api/v1/hdx_admin1s' \
-H 'accept: application/json' \
-H 'API-KEY: MY-KEY' \
-H 'APP-NAME: HDX' \
-H 'Content-Type: application/ld+json' \
-d '{
"location_ref": "/api/v1/hdx_locations/1",
"code": "AF17",
"name": "Badakhshan",
"valid_date": "2023-09-21T11:41:22.287Z"
}'
```

```bash
curl -X 'POST' \
'https://api-test.docksal.site/api/v1/hdx_admin2s' \
-H 'accept: application/json' \
-H 'API-KEY: MY-KEY' \
-H 'APP-NAME: HDX' \
-H 'Content-Type: application/ld+json' \
-d '{
"admin1_ref": "/api/v1/hdx_admin1s/1",
"code": "AF1702",
"name": "Argo",
"valid_date": "2023-09-21T12:02:58.896Z"
}'
```
4 changes: 4 additions & 0 deletions config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ services:
tags:
- { name: serializer.normalizer}

App\Serializer\HdxDenormalizer:
tags:
- { name: serializer.normalizer}

App\Serializer\OchaPresenceExternalIdDenormalizer:
tags:
- { name: serializer.normalizer}
Expand Down
Binary file added images/endpoints.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/get.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/methods.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
77 changes: 77 additions & 0 deletions migrations/Version20230920112505.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20230920112505 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE TABLE hdx_admin1 (id INT AUTO_INCREMENT NOT NULL, location_ref_id INT DEFAULT NULL, code VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, centroid_lat NUMERIC(10, 7) DEFAULT NULL, centroid_lon NUMERIC(10, 7) DEFAULT NULL, is_historical TINYINT(1) DEFAULT NULL, valid_date DATE DEFAULT NULL, INDEX IDX_1ED7B316AC5C9AB (location_ref_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE hdx_admin2 (id INT AUTO_INCREMENT NOT NULL, admin1_ref_id INT DEFAULT NULL, code VARCHAR(255) DEFAULT NULL, name VARCHAR(255) NOT NULL, centroid_lat NUMERIC(10, 7) DEFAULT NULL, centroid_lon NUMERIC(10, 7) DEFAULT NULL, is_historical TINYINT(1) DEFAULT NULL, valid_date DATE DEFAULT NULL, INDEX IDX_98E42A8BD9D9962A (admin1_ref_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE hdx_age_range (id INT AUTO_INCREMENT NOT NULL, code VARCHAR(255) NOT NULL, description VARCHAR(255) DEFAULT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE hdx_dataset (id INT AUTO_INCREMENT NOT NULL, hdx_link VARCHAR(255) DEFAULT NULL, code VARCHAR(255) NOT NULL, title VARCHAR(255) NOT NULL, provider_code VARCHAR(255) NOT NULL, provider_name VARCHAR(255) NOT NULL, api_link VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE hdx_gender (id INT AUTO_INCREMENT NOT NULL, code VARCHAR(1) NOT NULL, description VARCHAR(255) DEFAULT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE hdx_location (id INT AUTO_INCREMENT NOT NULL, code VARCHAR(3) NOT NULL, name VARCHAR(255) NOT NULL, centroid_lat NUMERIC(10, 7) DEFAULT NULL, centroid_lon NUMERIC(10, 7) DEFAULT NULL, is_historical TINYINT(1) DEFAULT NULL, valid_date DATE DEFAULT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE hdx_operational_presence (id INT AUTO_INCREMENT NOT NULL, resource_ref_id INT DEFAULT NULL, org_ref_id INT DEFAULT NULL, sector_ref_id INT DEFAULT NULL, admin2_ref_id INT DEFAULT NULL, valid_date DATE DEFAULT NULL, orig_data JSON, INDEX IDX_BD71C5B5E94BAB53 (resource_ref_id), INDEX IDX_BD71C5B582F50C2E (org_ref_id), INDEX IDX_BD71C5B5A66839C7 (sector_ref_id), INDEX IDX_BD71C5B5575691C9 (admin2_ref_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE hdx_org (id INT AUTO_INCREMENT NOT NULL, org_type_ref_id INT DEFAULT NULL, hdx_link VARCHAR(255) DEFAULT NULL, acronym VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, valid_date DATE DEFAULT NULL, INDEX IDX_61C847D89EEC7077 (org_type_ref_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE hdx_org_type (id INT AUTO_INCREMENT NOT NULL, code VARCHAR(255) NOT NULL, description VARCHAR(255) DEFAULT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE hdx_population (id INT AUTO_INCREMENT NOT NULL, resource_ref_id INT DEFAULT NULL, admin2_ref_id INT DEFAULT NULL, gender_ref_id INT DEFAULT NULL, age_range_ref_id INT DEFAULT NULL, valid_date DATE DEFAULT NULL, population INT NOT NULL, orig_data JSON, INDEX IDX_3EB64E86E94BAB53 (resource_ref_id), INDEX IDX_3EB64E86575691C9 (admin2_ref_id), INDEX IDX_3EB64E86ABC2B3FA (gender_ref_id), INDEX IDX_3EB64E86F7CD470C (age_range_ref_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE hdx_resource (id INT AUTO_INCREMENT NOT NULL, dataset_ref_id INT DEFAULT NULL, hdx_link VARCHAR(255) NOT NULL, code VARCHAR(255) NOT NULL, filename VARCHAR(255) NOT NULL, mime_type VARCHAR(255) NOT NULL, update_date DATE NOT NULL, is_hxl TINYINT(1) DEFAULT NULL, api_link VARCHAR(255) DEFAULT NULL, INDEX IDX_2440599747C19513 (dataset_ref_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE hdx_sector (id INT AUTO_INCREMENT NOT NULL, code VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, valid_date DATE DEFAULT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB');
$this->addSql('ALTER TABLE hdx_admin1 ADD CONSTRAINT FK_1ED7B316AC5C9AB FOREIGN KEY (location_ref_id) REFERENCES hdx_location (id)');
$this->addSql('ALTER TABLE hdx_admin2 ADD CONSTRAINT FK_98E42A8BD9D9962A FOREIGN KEY (admin1_ref_id) REFERENCES hdx_admin1 (id)');
$this->addSql('ALTER TABLE hdx_operational_presence ADD CONSTRAINT FK_BD71C5B5E94BAB53 FOREIGN KEY (resource_ref_id) REFERENCES hdx_resource (id)');
$this->addSql('ALTER TABLE hdx_operational_presence ADD CONSTRAINT FK_BD71C5B582F50C2E FOREIGN KEY (org_ref_id) REFERENCES hdx_org (id)');
$this->addSql('ALTER TABLE hdx_operational_presence ADD CONSTRAINT FK_BD71C5B5A66839C7 FOREIGN KEY (sector_ref_id) REFERENCES hdx_sector (id)');
$this->addSql('ALTER TABLE hdx_operational_presence ADD CONSTRAINT FK_BD71C5B5575691C9 FOREIGN KEY (admin2_ref_id) REFERENCES hdx_admin2 (id)');
$this->addSql('ALTER TABLE hdx_org ADD CONSTRAINT FK_61C847D89EEC7077 FOREIGN KEY (org_type_ref_id) REFERENCES hdx_org_type (id)');
$this->addSql('ALTER TABLE hdx_population ADD CONSTRAINT FK_3EB64E86E94BAB53 FOREIGN KEY (resource_ref_id) REFERENCES hdx_resource (id)');
$this->addSql('ALTER TABLE hdx_population ADD CONSTRAINT FK_3EB64E86575691C9 FOREIGN KEY (admin2_ref_id) REFERENCES hdx_admin2 (id)');
$this->addSql('ALTER TABLE hdx_population ADD CONSTRAINT FK_3EB64E86ABC2B3FA FOREIGN KEY (gender_ref_id) REFERENCES hdx_gender (id)');
$this->addSql('ALTER TABLE hdx_population ADD CONSTRAINT FK_3EB64E86F7CD470C FOREIGN KEY (age_range_ref_id) REFERENCES hdx_age_range (id)');
$this->addSql('ALTER TABLE hdx_resource ADD CONSTRAINT FK_2440599747C19513 FOREIGN KEY (dataset_ref_id) REFERENCES hdx_dataset (id)');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE hdx_admin1 DROP FOREIGN KEY FK_1ED7B316AC5C9AB');
$this->addSql('ALTER TABLE hdx_admin2 DROP FOREIGN KEY FK_98E42A8BD9D9962A');
$this->addSql('ALTER TABLE hdx_operational_presence DROP FOREIGN KEY FK_BD71C5B5E94BAB53');
$this->addSql('ALTER TABLE hdx_operational_presence DROP FOREIGN KEY FK_BD71C5B582F50C2E');
$this->addSql('ALTER TABLE hdx_operational_presence DROP FOREIGN KEY FK_BD71C5B5A66839C7');
$this->addSql('ALTER TABLE hdx_operational_presence DROP FOREIGN KEY FK_BD71C5B5575691C9');
$this->addSql('ALTER TABLE hdx_org DROP FOREIGN KEY FK_61C847D89EEC7077');
$this->addSql('ALTER TABLE hdx_population DROP FOREIGN KEY FK_3EB64E86E94BAB53');
$this->addSql('ALTER TABLE hdx_population DROP FOREIGN KEY FK_3EB64E86575691C9');
$this->addSql('ALTER TABLE hdx_population DROP FOREIGN KEY FK_3EB64E86ABC2B3FA');
$this->addSql('ALTER TABLE hdx_population DROP FOREIGN KEY FK_3EB64E86F7CD470C');
$this->addSql('ALTER TABLE hdx_resource DROP FOREIGN KEY FK_2440599747C19513');
$this->addSql('DROP TABLE hdx_admin1');
$this->addSql('DROP TABLE hdx_admin2');
$this->addSql('DROP TABLE hdx_age_range');
$this->addSql('DROP TABLE hdx_dataset');
$this->addSql('DROP TABLE hdx_gender');
$this->addSql('DROP TABLE hdx_location');
$this->addSql('DROP TABLE hdx_operational_presence');
$this->addSql('DROP TABLE hdx_org');
$this->addSql('DROP TABLE hdx_org_type');
$this->addSql('DROP TABLE hdx_population');
$this->addSql('DROP TABLE hdx_resource');
$this->addSql('DROP TABLE hdx_sector');
}
}
179 changes: 179 additions & 0 deletions src/Entity/HdxAdmin1.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
<?php

namespace App\Entity;

use ApiPlatform\Metadata\ApiResource;
use App\Repository\HdxAdmin1Repository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Context;
use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;

#[ORM\Entity(repositoryClass: HdxAdmin1Repository::class)]
#[ApiResource]
class HdxAdmin1
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;

#[ORM\ManyToOne(inversedBy: 'hdxAdmin1s')]
private ?HdxLocation $location_ref = null;

#[ORM\Column(length: 255)]
private ?string $code = null;

#[ORM\Column(length: 255)]
private ?string $name = null;

#[ORM\Column(type: Types::DECIMAL, precision: 10, scale: 7, nullable: true)]
private ?string $centroid_lat = null;

#[ORM\Column(type: Types::DECIMAL, precision: 10, scale: 7, nullable: true)]
private ?string $centroid_lon = null;

#[ORM\Column(nullable: true)]
private ?bool $is_historical = null;

#[ORM\Column(type: Types::DATE_MUTABLE, nullable: true)]
#[Context([DateTimeNormalizer::FORMAT_KEY => 'Y-m-d'])]
#[Context(normalizationContext: [DateTimeNormalizer::FORMAT_KEY => 'Y-m-d'])]
private ?\DateTimeInterface $valid_date = null;

#[ORM\OneToMany(mappedBy: 'admin1_ref', targetEntity: HdxAdmin2::class)]
private Collection $hdxAdmin2s;

public function __construct()
{
$this->hdxAdmin2s = new ArrayCollection();
}

public function getId(): ?int
{
return $this->id;
}

public function setId($id): static
{
$this->id = $id;

return $this;
}

public function getLocationRef(): ?HdxLocation
{
return $this->location_ref;
}

public function setLocationRef(?HdxLocation $location_ref): static
{
$this->location_ref = $location_ref;

return $this;
}

public function getCode(): ?string
{
return $this->code;
}

public function setCode(string $code): static
{
$this->code = $code;

return $this;
}

public function getName(): ?string
{
return $this->name;
}

public function setName(string $name): static
{
$this->name = $name;

return $this;
}

public function getCentroidLat(): ?string
{
return $this->centroid_lat;
}

public function setCentroidLat(?string $centroid_lat): static
{
$this->centroid_lat = $centroid_lat;

return $this;
}

public function getCentroidLon(): ?string
{
return $this->centroid_lon;
}

public function setCentroidLon(?string $centroid_lon): static
{
$this->centroid_lon = $centroid_lon;

return $this;
}

public function isIsHistorical(): ?bool
{
return $this->is_historical;
}

public function setIsHistorical(?bool $is_historical): static
{
$this->is_historical = $is_historical;

return $this;
}

public function getValidDate(): ?\DateTimeInterface
{
return $this->valid_date;
}

public function setValidDate(?\DateTimeInterface $valid_date): static
{
$this->valid_date = $valid_date;

return $this;
}

/**
* @return Collection<int, HdxAdmin2>
*/
public function getHdxAdmin2s(): Collection
{
return $this->hdxAdmin2s;
}

public function addHdxAdmin2(HdxAdmin2 $hdxAdmin2): static
{
if (!$this->hdxAdmin2s->contains($hdxAdmin2)) {
$this->hdxAdmin2s->add($hdxAdmin2);
$hdxAdmin2->setAdmin1Ref($this);
}

return $this;
}

public function removeHdxAdmin2(HdxAdmin2 $hdxAdmin2): static
{
if ($this->hdxAdmin2s->removeElement($hdxAdmin2)) {
// set the owning side to null (unless already changed)
if ($hdxAdmin2->getAdmin1Ref() === $this) {
$hdxAdmin2->setAdmin1Ref(null);
}
}

return $this;
}
}
Loading
Loading