Skip to content

Commit c77c8a3

Browse files
committed
Add group to fe and dcar match page data models
1 parent 4c25252 commit c77c8a3

File tree

5 files changed

+251
-3
lines changed

5 files changed

+251
-3
lines changed

dotcom-rendering/src/footballTables.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ type MissingScore = {
6262

6363
type ParserError = MissingScore;
6464

65-
const parseTable = (feGroup: FEGroup): Result<ParserError, FootballTable> =>
65+
export const parseTable = (
66+
feGroup: FEGroup,
67+
): Result<ParserError, FootballTable> =>
6668
parseEntries(feGroup.entries).map((entries) => ({
6769
groupName: feGroup.round.name,
6870
entries: entries.sort((a, b) => a.position - b.position),

dotcom-rendering/src/frontend/feFootballMatchPage.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { FEFootballDataPage } from './feFootballDataPage';
2+
import { type FEGroup } from './feFootballTablesPage';
23

34
export type FEFootballPlayerEvent = {
45
eventTime: string;
@@ -42,4 +43,5 @@ export type FEFootballMatch = {
4243

4344
export type FEFootballMatchPage = FEFootballDataPage & {
4445
footballMatch: FEFootballMatch;
46+
group?: FEGroup;
4547
};

dotcom-rendering/src/frontend/schemas/feFootballMatchPage.json

Lines changed: 232 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,238 @@
294294
"id",
295295
"status"
296296
]
297+
},
298+
"group": {
299+
"type": "object",
300+
"properties": {
301+
"round": {
302+
"type": "object",
303+
"properties": {
304+
"roundNumber": {
305+
"type": "string"
306+
},
307+
"name": {
308+
"type": "string"
309+
}
310+
},
311+
"required": [
312+
"roundNumber"
313+
]
314+
},
315+
"entries": {
316+
"type": "array",
317+
"items": {
318+
"type": "object",
319+
"properties": {
320+
"stageNumber": {
321+
"type": "string"
322+
},
323+
"round": {
324+
"type": "object",
325+
"properties": {
326+
"roundNumber": {
327+
"type": "string"
328+
},
329+
"name": {
330+
"type": "string"
331+
}
332+
},
333+
"required": [
334+
"roundNumber"
335+
]
336+
},
337+
"team": {
338+
"type": "object",
339+
"properties": {
340+
"id": {
341+
"type": "string"
342+
},
343+
"name": {
344+
"type": "string"
345+
},
346+
"rank": {
347+
"type": "number"
348+
},
349+
"total": {
350+
"type": "object",
351+
"properties": {
352+
"played": {
353+
"type": "number"
354+
},
355+
"won": {
356+
"type": "number"
357+
},
358+
"drawn": {
359+
"type": "number"
360+
},
361+
"lost": {
362+
"type": "number"
363+
},
364+
"goalsFor": {
365+
"type": "number"
366+
},
367+
"goalsAgainst": {
368+
"type": "number"
369+
}
370+
},
371+
"required": [
372+
"drawn",
373+
"goalsAgainst",
374+
"goalsFor",
375+
"lost",
376+
"played",
377+
"won"
378+
]
379+
},
380+
"home": {
381+
"type": "object",
382+
"properties": {
383+
"played": {
384+
"type": "number"
385+
},
386+
"won": {
387+
"type": "number"
388+
},
389+
"drawn": {
390+
"type": "number"
391+
},
392+
"lost": {
393+
"type": "number"
394+
},
395+
"goalsFor": {
396+
"type": "number"
397+
},
398+
"goalsAgainst": {
399+
"type": "number"
400+
}
401+
},
402+
"required": [
403+
"drawn",
404+
"goalsAgainst",
405+
"goalsFor",
406+
"lost",
407+
"played",
408+
"won"
409+
]
410+
},
411+
"away": {
412+
"type": "object",
413+
"properties": {
414+
"played": {
415+
"type": "number"
416+
},
417+
"won": {
418+
"type": "number"
419+
},
420+
"drawn": {
421+
"type": "number"
422+
},
423+
"lost": {
424+
"type": "number"
425+
},
426+
"goalsFor": {
427+
"type": "number"
428+
},
429+
"goalsAgainst": {
430+
"type": "number"
431+
}
432+
},
433+
"required": [
434+
"drawn",
435+
"goalsAgainst",
436+
"goalsFor",
437+
"lost",
438+
"played",
439+
"won"
440+
]
441+
},
442+
"goalDifference": {
443+
"type": "number"
444+
},
445+
"points": {
446+
"type": "number"
447+
}
448+
},
449+
"required": [
450+
"away",
451+
"goalDifference",
452+
"home",
453+
"id",
454+
"name",
455+
"points",
456+
"rank",
457+
"total"
458+
]
459+
},
460+
"teamUrl": {
461+
"type": "string"
462+
},
463+
"results": {
464+
"type": "array",
465+
"items": {
466+
"type": "object",
467+
"properties": {
468+
"matchId": {
469+
"type": "string"
470+
},
471+
"self": {
472+
"type": "object",
473+
"properties": {
474+
"id": {
475+
"type": "string"
476+
},
477+
"name": {
478+
"type": "string"
479+
},
480+
"score": {
481+
"type": "number"
482+
}
483+
},
484+
"required": [
485+
"id",
486+
"name"
487+
]
488+
},
489+
"foe": {
490+
"type": "object",
491+
"properties": {
492+
"id": {
493+
"type": "string"
494+
},
495+
"name": {
496+
"type": "string"
497+
},
498+
"score": {
499+
"type": "number"
500+
}
501+
},
502+
"required": [
503+
"id",
504+
"name"
505+
]
506+
}
507+
},
508+
"required": [
509+
"foe",
510+
"matchId",
511+
"self"
512+
]
513+
}
514+
}
515+
},
516+
"required": [
517+
"results",
518+
"round",
519+
"stageNumber",
520+
"team"
521+
]
522+
}
523+
}
524+
},
525+
"required": [
526+
"entries",
527+
"round"
528+
]
297529
}
298530
},
299531
"required": [

dotcom-rendering/src/server/handler.sportDataPage.web.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
getParserErrorMessage,
66
parse as parseFootballMatches,
77
} from '../footballMatches';
8-
import { parse as parseFootballTables } from '../footballTables';
8+
import { parse as parseFootballTables, parseTable } from '../footballTables';
99
import type { FECricketMatchPage } from '../frontend/feCricketMatchPage';
1010
import type { FEFootballCompetition } from '../frontend/feFootballDataPage';
1111
import type { FEFootballMatchListPage } from '../frontend/feFootballMatchListPage';
@@ -216,15 +216,23 @@ const parseFEFootballMatch = (
216216
data: FEFootballMatchPage,
217217
): FootballMatchSummaryPage => {
218218
const parsedFootballMatch = parseFootballMatch(data.footballMatch);
219+
const group = data.group && parseTable(data.group);
219220

220221
if (!parsedFootballMatch.ok) {
221222
throw new Error(
222223
`Failed to parse football match: ${parsedFootballMatch.error.kind} ${parsedFootballMatch.error.message}`,
223224
);
224225
}
225226

227+
if (group && !group.ok) {
228+
throw new Error(
229+
`Failed to parse football league table group: ${group.error.kind} ${group.error.message}`,
230+
);
231+
}
232+
226233
return {
227234
match: parsedFootballMatch.value,
235+
group: group?.value,
228236
kind: 'FootballMatchSummary',
229237
nav: {
230238
...extractNAV(data.nav),

dotcom-rendering/src/sportDataPage.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import type { CricketMatch } from './cricketMatch';
22
import type { FootballMatch } from './footballMatch';
33
import type { FootballMatches } from './footballMatches';
4-
import type { FootballTableCompetitions } from './footballTables';
4+
import type {
5+
FootballTable,
6+
FootballTableCompetitions,
7+
} from './footballTables';
58
import type { FESportPageConfig } from './frontend/feFootballDataPage';
69
import type { EditionId } from './lib/edition';
710
import type { NavType } from './model/extract-nav';
@@ -48,6 +51,7 @@ export type CricketMatchPage = SportPageConfig & {
4851

4952
export type FootballMatchSummaryPage = SportPageConfig & {
5053
match: FootballMatch;
54+
group?: FootballTable;
5155
kind: 'FootballMatchSummary';
5256
};
5357

0 commit comments

Comments
 (0)