Skip to content

Commit 591a7a1

Browse files
committed
fix: review feedback
Signed-off-by: romanetar <roman_ag@hotmail.com>
1 parent 53c20ad commit 591a7a1

6 files changed

Lines changed: 31 additions & 5 deletions

File tree

app/Http/Controllers/Apis/Protected/Summit/Factories/SummitSponsorshipAddOnTypeValidationRulesFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public static function buildForAdd(array $payload = []): array
3030
public static function buildForUpdate(array $payload = []): array
3131
{
3232
return [
33-
'name' => 'sometimes|string|max:255',
33+
'name' => 'sometimes|required|string|max:255',
3434
];
3535
}
3636
}

app/ModelSerializers/Summit/SummitSponsorshipAddOnSerializer.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@
2323
final class SummitSponsorshipAddOnSerializer extends SilverStripeSerializer
2424
{
2525
protected static $array_mappings = [
26-
'Name' => 'name:json_string',
27-
'TypeId' => 'type_id:json_int',
26+
'Name' => 'name:json_string',
27+
'TypeId' => 'type_id:json_int',
28+
'TypeName' => 'type_name:json_string',
2829
'SponsorshipId' => 'sponsorship_id:json_int',
2930
];
3031

app/Models/Foundation/Summit/SummitSponsorshipAddOn.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ public function getType(): ?SummitSponsorshipAddOnType
7272
return $this->type;
7373
}
7474

75+
public function getTypeName(): ?string
76+
{
77+
return $this->type?->getName();
78+
}
79+
7580
public function setType(SummitSponsorshipAddOnType $type): void
7681
{
7782
$this->type = $type;

app/Repositories/Summit/DoctrineSummitSponsorshipAddOnRepository.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ protected function getOrderMappings(): array
6767
return [
6868
'id' => 'e.id',
6969
'name' => 'e.name',
70+
'type' => 'at.name',
7071
];
7172
}
7273

@@ -98,4 +99,4 @@ public function countByAddOnType(int $type_id): int
9899
->setParameter('type_id', $type_id)
99100
->getSingleScalarResult();
100101
}
101-
}
102+
}

database/migrations/model/Version20260615000001.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ public function up(Schema $schema): void
5252
}
5353

5454
// Seed the four types that correspond to the old string constants.
55+
// INSERT IGNORE makes this safe to re-run (unique constraint on Name).
5556
$this->addSql(<<<SQL
56-
INSERT INTO `SummitSponsorshipAddOnType` (`Created`, `LastEdited`, `Name`) VALUES
57+
INSERT IGNORE INTO `SummitSponsorshipAddOnType` (`Created`, `LastEdited`, `Name`) VALUES
5758
(NOW(), NOW(), 'Booth'),
5859
(NOW(), NOW(), 'Meeting_Room'),
5960
(NOW(), NOW(), 'Schedule_Spot'),

tests/oauth2/OAuth2SummitSponsorshipAddOnTypesApiControllerTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,24 @@ public function testUpdate(): void
227227
$this->assertEquals($new_name, $type->name);
228228
}
229229

230+
public function testUpdateWithEmptyName(): void
231+
{
232+
$params = ['id' => self::$default_type->getId()];
233+
234+
$this->action(
235+
"PUT",
236+
"OAuth2SummitSponsorshipAddOnTypesApiController@update",
237+
$params,
238+
[],
239+
[],
240+
[],
241+
$this->getAuthHeaders(),
242+
json_encode(['name' => ''])
243+
);
244+
245+
$this->assertResponseStatus(412);
246+
}
247+
230248
public function testUpdateNotFound(): void
231249
{
232250
$params = ['id' => PHP_INT_MAX];

0 commit comments

Comments
 (0)