Skip to content

Commit 24e044e

Browse files
authored
Merge pull request #233 from boherm/fix-horse-color-api-endpoint
Fix color -> coat_color for horses
2 parents 31a1213 + ae4b39b commit 24e044e

6 files changed

Lines changed: 13 additions & 13 deletions

File tree

api_module/src/ApiPlatform/Resources/Horse.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class Horse
4848

4949
#[Assert\NotBlank]
5050
#[Assert\Type('string')]
51-
public ?string $color = null;
51+
public ?string $coatColor = null;
5252

5353
#[Assert\NotBlank]
5454
#[Assert\Type('float')]
@@ -60,7 +60,7 @@ public static function fromObjectModel(ObjectModelHorse $omHorse): self
6060
$horse = new self();
6161
$horse->id = (int) $omHorse->id;
6262
$horse->name = $omHorse->name;
63-
$horse->color = $omHorse->color;
63+
$horse->coatColor = $omHorse->coat_color;
6464
$horse->weight = $omHorse->weight;
6565

6666
return $horse;

api_module/src/ApiPlatform/State/HorseProcessor.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function process(mixed $data, Operation $operation, array $uriVariables =
5252
if ($operation instanceof Post && $data instanceof Horse) {
5353
$horse = $this->horseRepository->create(
5454
$data->name,
55-
$data->color,
55+
$data->coatColor,
5656
$data->weight,
5757
);
5858

@@ -69,7 +69,7 @@ public function process(mixed $data, Operation $operation, array $uriVariables =
6969
$horse = $this->horseRepository->update(
7070
$data->id,
7171
$data->name,
72-
$data->color,
72+
$data->coatColor,
7373
$data->weight,
7474
);
7575

api_module/src/ApiPlatform/State/HorseProvider.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ public function provide(Operation $operation, array $uriVariables = [], array $c
6161
$horse->name = $newData->name;
6262
}
6363

64-
if (null !== $newData->color) {
65-
$horse->color = $newData->color;
64+
if (null !== $newData->coatColor) {
65+
$horse->coatColor = $newData->coatColor;
6666
}
6767

6868
if (null !== $newData->weight) {
@@ -94,7 +94,7 @@ private function findAllHorses(): array
9494
$h = new Horse();
9595
$h->id = (int) $horse['id_horse'];
9696
$h->name = $horse['name'];
97-
$h->color = $horse['color'];
97+
$h->coatColor = $horse['coat_color'];
9898
$h->weight = $horse['weight'];
9999

100100
$horsesArray[] = $h;

api_module/src/Entity/Horse.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@
3131
class Horse extends ObjectModel
3232
{
3333
public $name;
34-
public $color;
34+
public $coat_color;
3535
public $weight;
3636

3737
public static $definition = [
3838
'table' => 'horse',
3939
'primary' => 'id_horse',
4040
'fields' => [
4141
'name' => ['type' => self::TYPE_STRING, 'validate' => 'isCleanHtml', 'required' => true, 'size' => 64],
42-
'color' => ['type' => self::TYPE_STRING, 'validate' => 'isCleanHtml', 'required' => true, 'size' => 64],
42+
'coat_color' => ['type' => self::TYPE_STRING, 'validate' => 'isCleanHtml', 'required' => true, 'size' => 64],
4343
'weight' => ['type' => self::TYPE_FLOAT, 'validate' => 'isFloat', 'required' => true],
4444
],
4545
];

api_module/src/Repository/HorseRepository.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function findHorseById(int $id): ?Horse
5151
public function findAllHorses(): array
5252
{
5353
return $this->connection->createQueryBuilder()
54-
->select('h.id_horse, h.name, h.color, h.weight')
54+
->select('h.id_horse, h.name, h.coat_color, h.weight')
5555
->from($this->dbPrefix . 'horse', 'h')
5656
->executeQuery()
5757
->fetchAllAssociative()
@@ -62,7 +62,7 @@ public function create(string $name, string $color, float $weight): Horse
6262
{
6363
$horse = new Horse();
6464
$horse->name = $name;
65-
$horse->color = $color;
65+
$horse->coat_color = $color;
6666
$horse->weight = $weight;
6767
$horse->save();
6868

@@ -79,7 +79,7 @@ public function update(int $id, string $name, string $color, float $weight): Hor
7979
{
8080
$horse = new Horse($id);
8181
$horse->name = $name;
82-
$horse->color = $color;
82+
$horse->coat_color = $color;
8383
$horse->weight = $weight;
8484
$horse->save();
8585

api_module/src/Resources/data/install.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
CREATE TABLE IF NOT EXISTS `PREFIX_hamster` (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(64) NOT NULL, description VARCHAR(64) NOT NULL, weight FLOAT NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB
33

44
-- Horse (legacy ObjectModel)
5-
CREATE TABLE IF NOT EXISTS `PREFIX_horse` (id_horse INT AUTO_INCREMENT NOT NULL, name VARCHAR(64) NOT NULL, color VARCHAR(64) NOT NULL, weight FLOAT NOT NULL, PRIMARY KEY(id_horse)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB
5+
CREATE TABLE IF NOT EXISTS `PREFIX_horse` (id_horse INT AUTO_INCREMENT NOT NULL, name VARCHAR(64) NOT NULL, coat_color VARCHAR(64) NOT NULL, weight FLOAT NOT NULL, PRIMARY KEY(id_horse)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB

0 commit comments

Comments
 (0)