Skip to content

Commit

Permalink
added public schema for newspaper and a transformer for it
Browse files Browse the repository at this point in the history
  • Loading branch information
theorm committed Nov 8, 2024
1 parent 402b39f commit b723482
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 4 deletions.
30 changes: 29 additions & 1 deletion src/models/generated/schemasPublic.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,37 @@ export interface FindTextReuseClustersResponse {
*/
export interface Newspaper {
/**
* The unique identifier of the newspaper
* The unique identifier of the newspaper.
*/
uid: string;
/**
* The title of the newspaper.
*/
title: string;
/**
* The year of the first available article in the newspaper.
*/
startYear?: number;
/**
* The year of the last available article in the newspaper.
*/
endYear?: number;
/**
* ISO 639-1 codes of languages used in the newspaper.
*/
languageCodes: string[];
/**
* Total number of articles in the newspaper.
*/
totalArticles: number;
/**
* Total number of issues in the newspaper.
*/
totalIssues: number;
/**
* Total number of pages in the newspaper.
*/
totalPages: number;
}


Expand Down
40 changes: 38 additions & 2 deletions src/schema/schemasPublic/Newspaper.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,44 @@
"properties": {
"uid": {
"type": "string",
"description": "The unique identifier of the newspaper"
"description": "The unique identifier of the newspaper."
},
"title": {
"type": "string",
"description": "The title of the newspaper."
},
"startYear": {
"type": "number",
"description": "The year of the first available article in the newspaper.",
"minimum": 0
},
"endYear": {
"type": "number",
"description": "The year of the last available article in the newspaper.",
"minimum": 0
},
"languageCodes": {
"type": "array",
"description": "ISO 639-1 codes of languages used in the newspaper.",
"items": {
"type": "string"
}
},
"totalArticles": {
"type": "number",
"description": "Total number of articles in the newspaper.",
"minimum": 0
},
"totalIssues": {
"type": "number",
"description": "Total number of issues in the newspaper.",
"minimum": 0
},
"totalPages": {
"type": "number",
"description": "Total number of pages in the newspaper.",
"minimum": 0
}
},
"required": ["uid"]
"required": ["uid", "title", "languageCodes", "totalArticles", "totalIssues", "totalPages"]
}
5 changes: 4 additions & 1 deletion src/services/newspapers/newspapers.hooks.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { authenticateAround as authenticate } from '../../hooks/authenticate'
import { rateLimit } from '../../hooks/rateLimiter'
import { OrderByChoices } from './newspapers.schema'
import { transformResponseDataItem } from '../../hooks/transformation'
import { inPublicApi } from '../../hooks/redaction'
import { transformNewspaper } from '../../transformers/newspaper'

const { queryWithCommonParams, validate, utils } = require('../../hooks/params')
const { checkCachedContents, returnCachedContents, saveResultsInCache } = require('../../hooks/redis')
Expand Down Expand Up @@ -66,7 +69,7 @@ module.exports = {

after: {
all: [returnCachedContents(), saveResultsInCache()],
find: [],
find: [transformResponseDataItem(transformNewspaper, inPublicApi)],
get: [],
create: [],
update: [],
Expand Down
15 changes: 15 additions & 0 deletions src/transformers/newspaper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Newspaper as NewspaperInternal } from '../models/generated/schemas'
import { Newspaper as NewspaperPublic } from '../models/generated/schemasPublic'

export const transformNewspaper = (input: NewspaperInternal): NewspaperPublic => {
return {
uid: input.uid,
title: input.name,
startYear: input.startYear ?? undefined,
endYear: input.endYear ?? undefined,
languageCodes: input.languages,
totalArticles: input.countArticles >= 0 ? input.countArticles : 0,
totalIssues: input.countIssues >= 0 ? input.countIssues : 0,
totalPages: input.countPages >= 0 ? input.countPages : 0,
}
}

0 comments on commit b723482

Please sign in to comment.