Skip to content

Commit b9b6649

Browse files
authored
Remove crosspost information from list API endpoints (#1731)
1 parent 0bfc13b commit b9b6649

9 files changed

+44
-16
lines changed

src/Controller/Api/Entry/DomainEntriesRetrieveApi.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public function __invoke(
157157
try {
158158
\assert($value instanceof Entry);
159159
$this->handlePrivateContent($value);
160-
$dtos[] = $this->serializeEntry($factory->createDto($value), $this->tagLinkRepository->getTagsOfContent($value), $this->entryRepository->findCross($value));
160+
$dtos[] = $this->serializeEntry($factory->createDto($value), $this->tagLinkRepository->getTagsOfContent($value));
161161
} catch (\Exception $e) {
162162
continue;
163163
}

src/Controller/Api/Entry/EntriesRetrieveApi.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ public function collection(
208208
try {
209209
\assert($value instanceof Entry);
210210
$this->handlePrivateContent($value);
211-
$dtos[] = $this->serializeEntry($factory->createDto($value), $this->tagLinkRepository->getTagsOfContent($value), $this->entryRepository->findCross($value));
211+
$dtos[] = $this->serializeEntry($factory->createDto($value), $this->tagLinkRepository->getTagsOfContent($value));
212212
} catch (AccessDeniedException $e) {
213213
continue;
214214
}
@@ -324,7 +324,7 @@ public function subscribed(
324324
try {
325325
\assert($value instanceof Entry);
326326
$this->handlePrivateContent($value);
327-
$dtos[] = $this->serializeEntry($factory->createDto($value), $this->tagLinkRepository->getTagsOfContent($value), $this->entryRepository->findCross($value));
327+
$dtos[] = $this->serializeEntry($factory->createDto($value), $this->tagLinkRepository->getTagsOfContent($value));
328328
} catch (\Exception $e) {
329329
continue;
330330
}
@@ -440,7 +440,7 @@ public function moderated(
440440
try {
441441
\assert($value instanceof Entry);
442442
$this->handlePrivateContent($value);
443-
$dtos[] = $this->serializeEntry($factory->createDto($value), $this->tagLinkRepository->getTagsOfContent($value), $this->entryRepository->findCross($value));
443+
$dtos[] = $this->serializeEntry($factory->createDto($value), $this->tagLinkRepository->getTagsOfContent($value));
444444
} catch (\Exception $e) {
445445
continue;
446446
}
@@ -556,7 +556,7 @@ public function favourited(
556556
try {
557557
\assert($value instanceof Entry);
558558
$this->handlePrivateContent($value);
559-
$dtos[] = $this->serializeEntry($factory->createDto($value), $this->tagLinkRepository->getTagsOfContent($value), $this->entryRepository->findCross($value));
559+
$dtos[] = $this->serializeEntry($factory->createDto($value), $this->tagLinkRepository->getTagsOfContent($value));
560560
} catch (\Exception $e) {
561561
continue;
562562
}

src/Controller/Api/Entry/MagazineEntriesRetrieveApi.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public function __invoke(
158158
foreach ($entries->getCurrentPageResults() as $value) {
159159
try {
160160
\assert($value instanceof Entry);
161-
$dtos[] = $this->serializeEntry($factory->createDto($value), $this->tagLinkRepository->getTagsOfContent($value), $this->entryRepository->findCross($value));
161+
$dtos[] = $this->serializeEntry($factory->createDto($value), $this->tagLinkRepository->getTagsOfContent($value));
162162
} catch (\Exception $e) {
163163
continue;
164164
}

src/Controller/Api/Entry/UserEntriesRetrieveApi.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public function __invoke(
153153
foreach ($entries->getCurrentPageResults() as $value) {
154154
try {
155155
\assert($value instanceof Entry);
156-
$dtos[] = $this->serializeEntry($factory->createDto($value), $this->tagLinkRepository->getTagsOfContent($value), $this->entryRepository->findCross($value));
156+
$dtos[] = $this->serializeEntry($factory->createDto($value), $this->tagLinkRepository->getTagsOfContent($value));
157157
} catch (\Exception $e) {
158158
continue;
159159
}

src/DTO/EntryResponseDto.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ class EntryResponseDto implements \JsonSerializable
5454
public ?array $bookmarks = null;
5555

5656
/**
57-
* @var EntryResponseDto[]|null $crosspostedEntries other entries that share either the link or the title (if that is longer than 10 characters)
57+
* @var EntryResponseDto[]|null $crosspostedEntries other entries that share either the link or the title (if that is longer than 10 characters).
58+
* If this property is null it means that this endpoint does not contain information about it,
59+
* only an empty array means that there are no crossposts
5860
*/
5961
#[OA\Property(type: 'array', items: new OA\Items(ref: new Model(type: EntryResponseDto::class)))]
6062
public ?array $crosspostedEntries;

tests/Functional/Controller/Api/Entry/DomainEntryRetrieveApiTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public function testApiCanGetDomainEntriesAnonymous(): void
3636
self::assertSame($magazine->getId(), $jsonData['items'][0]['magazine']['magazineId']);
3737
self::assertEquals('link', $jsonData['items'][0]['type']);
3838
self::assertSame(0, $jsonData['items'][0]['numComments']);
39+
self::assertNull($jsonData['items'][0]['crosspostedEntries']);
3940
}
4041

4142
public function testApiCanGetDomainEntries(): void
@@ -72,6 +73,7 @@ public function testApiCanGetDomainEntries(): void
7273
self::assertSame($magazine->getId(), $jsonData['items'][0]['magazine']['magazineId']);
7374
self::assertEquals('link', $jsonData['items'][0]['type']);
7475
self::assertSame(0, $jsonData['items'][0]['numComments']);
76+
self::assertNull($jsonData['items'][0]['crosspostedEntries']);
7577
}
7678

7779
public function testApiCanGetDomainEntriesNewest(): void
@@ -372,5 +374,6 @@ public function testApiCanGetDomainEntriesWithUserVoteStatus(): void
372374
self::assertEquals('link', $jsonData['items'][0]['type']);
373375
self::assertEquals('another-entry', $jsonData['items'][0]['slug']);
374376
self::assertNull($jsonData['items'][0]['apId']);
377+
self::assertNull($jsonData['items'][0]['crosspostedEntries']);
375378
}
376379
}

tests/Functional/Controller/Api/Entry/EntryRetrieveApiTest.php

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,6 +1199,10 @@ public function testApiGetAuthorNotModerator(): void
11991199
self::assertFalse($jsonData['items'][1]['isAuthorModeratorInMagazine']);
12001200
}
12011201

1202+
/**
1203+
* This function tests that the collection endpoint does not contain crosspost information,
1204+
* but fetching a single entry does.
1205+
*/
12021206
public function testApiContainsCrosspostInformation(): void
12031207
{
12041208
$magazine1 = $this->getMagazineByName('acme');
@@ -1227,17 +1231,29 @@ public function testApiContainsCrosspostInformation(): void
12271231
self::assertIsArray($jsonData['items'][0]);
12281232
self::assertArrayKeysMatch(self::ENTRY_RESPONSE_KEYS, $jsonData['items'][0]);
12291233
self::assertSame($entry1->getId(), $jsonData['items'][0]['entryId']);
1230-
self::assertIsArray($jsonData['items'][0]['crosspostedEntries']);
1231-
self::assertCount(1, $jsonData['items'][0]['crosspostedEntries']);
1232-
self::assertArrayKeysMatch(self::ENTRY_RESPONSE_KEYS, $jsonData['items'][0]['crosspostedEntries'][0]);
1233-
self::assertSame($entry2->getId(), $jsonData['items'][0]['crosspostedEntries'][0]['entryId']);
1234+
self::assertNull($jsonData['items'][0]['crosspostedEntries']);
12341235

12351236
self::assertIsArray($jsonData['items'][1]);
12361237
self::assertArrayKeysMatch(self::ENTRY_RESPONSE_KEYS, $jsonData['items'][1]);
12371238
self::assertSame($entry2->getId(), $jsonData['items'][1]['entryId']);
1238-
self::assertIsArray($jsonData['items'][1]['crosspostedEntries']);
1239-
self::assertCount(1, $jsonData['items'][1]['crosspostedEntries']);
1240-
self::assertArrayKeysMatch(self::ENTRY_RESPONSE_KEYS, $jsonData['items'][1]['crosspostedEntries'][0]);
1241-
self::assertSame($entry1->getId(), $jsonData['items'][1]['crosspostedEntries'][0]['entryId']);
1239+
self::assertNull($jsonData['items'][1]['crosspostedEntries']);
1240+
1241+
$this->client->request('GET', '/api/entry/'.$entry1->getId());
1242+
self::assertResponseIsSuccessful();
1243+
$jsonData = self::getJsonResponse($this->client);
1244+
1245+
self::assertIsArray($jsonData['crosspostedEntries']);
1246+
self::assertCount(1, $jsonData['crosspostedEntries']);
1247+
self::assertArrayKeysMatch(self::ENTRY_RESPONSE_KEYS, $jsonData['crosspostedEntries'][0]);
1248+
self::assertSame($entry2->getId(), $jsonData['crosspostedEntries'][0]['entryId']);
1249+
1250+
$this->client->request('GET', '/api/entry/'.$entry2->getId());
1251+
self::assertResponseIsSuccessful();
1252+
$jsonData = self::getJsonResponse($this->client);
1253+
1254+
self::assertIsArray($jsonData['crosspostedEntries']);
1255+
self::assertCount(1, $jsonData['crosspostedEntries']);
1256+
self::assertArrayKeysMatch(self::ENTRY_RESPONSE_KEYS, $jsonData['crosspostedEntries'][0]);
1257+
self::assertSame($entry1->getId(), $jsonData['crosspostedEntries'][0]['entryId']);
12421258
}
12431259
}

tests/Functional/Controller/Api/Entry/MagazineEntryRetrieveApiTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public function testApiCanGetMagazineEntriesAnonymous(): void
3636
self::assertSame($magazine->getId(), $jsonData['items'][0]['magazine']['magazineId']);
3737
self::assertEquals('link', $jsonData['items'][0]['type']);
3838
self::assertSame(0, $jsonData['items'][0]['numComments']);
39+
self::assertNull($jsonData['items'][0]['crosspostedEntries']);
3940
}
4041

4142
public function testApiCanGetMagazineEntries(): void
@@ -72,6 +73,7 @@ public function testApiCanGetMagazineEntries(): void
7273
self::assertSame($magazine->getId(), $jsonData['items'][0]['magazine']['magazineId']);
7374
self::assertEquals('link', $jsonData['items'][0]['type']);
7475
self::assertSame(0, $jsonData['items'][0]['numComments']);
76+
self::assertNull($jsonData['items'][0]['crosspostedEntries']);
7577
}
7678

7779
public function testApiCanGetMagazineEntriesPinnedFirst(): void
@@ -118,6 +120,7 @@ public function testApiCanGetMagazineEntriesPinnedFirst(): void
118120
self::assertSame(0, $jsonData['items'][0]['numComments']);
119121
self::assertSame(0, $jsonData['items'][0]['uv']);
120122
self::assertTrue($jsonData['items'][0]['isPinned']);
123+
self::assertNull($jsonData['items'][0]['crosspostedEntries']);
121124

122125
self::assertIsArray($jsonData['items'][1]);
123126
self::assertArrayKeysMatch(self::ENTRY_RESPONSE_KEYS, $jsonData['items'][1]);
@@ -129,6 +132,7 @@ public function testApiCanGetMagazineEntriesPinnedFirst(): void
129132
self::assertSame(1, $jsonData['items'][1]['numComments']);
130133
self::assertSame(1, $jsonData['items'][1]['uv']);
131134
self::assertFalse($jsonData['items'][1]['isPinned']);
135+
self::assertNull($jsonData['items'][1]['crosspostedEntries']);
132136
}
133137

134138
public function testApiCanGetMagazineEntriesNewest(): void

tests/Functional/Controller/Api/Entry/UserEntryRetrieveApiTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public function testApiCanGetUserEntriesAnonymous(): void
4040
self::assertSame($otherUser->getId(), $jsonData['items'][0]['user']['userId']);
4141
self::assertEquals('link', $jsonData['items'][0]['type']);
4242
self::assertSame(0, $jsonData['items'][0]['numComments']);
43+
self::assertNull($jsonData['items'][0]['crosspostedEntries']);
4344
}
4445

4546
public function testApiCanGetUserEntries(): void
@@ -80,6 +81,7 @@ public function testApiCanGetUserEntries(): void
8081
self::assertSame($otherUser->getId(), $jsonData['items'][0]['user']['userId']);
8182
self::assertEquals('link', $jsonData['items'][0]['type']);
8283
self::assertSame(0, $jsonData['items'][0]['numComments']);
84+
self::assertNull($jsonData['items'][0]['crosspostedEntries']);
8385
}
8486

8587
public function testApiCanGetUserEntriesNewest(): void
@@ -381,5 +383,6 @@ public function testApiCanGetUserEntriesWithUserVoteStatus(): void
381383
self::assertEquals('link', $jsonData['items'][0]['type']);
382384
self::assertEquals('another-entry', $jsonData['items'][0]['slug']);
383385
self::assertNull($jsonData['items'][0]['apId']);
386+
self::assertNull($jsonData['items'][0]['crosspostedEntries']);
384387
}
385388
}

0 commit comments

Comments
 (0)