diff --git a/README.md b/README.md index 20d6e06..6c3b440 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,7 @@ Berita Indo API (or in English is Indonesian News API) is an API to display many - `/v1/tribun-news/:zone/:type` : Get specific news data by zone and type news of Tribun News - `/v1/jawa-pos/:type`: Get all news data of Jawa Pos News - `/v1/jawa-pos/:type`: Get specific news data by type news of Jawa Pos News +- `/v1/vice/`: Get all news data of Vice Indonesia > Each API Endpoint have a query paramaters named 'title', and this query parameters will be usefull if you want to search the API data by the title. @@ -53,6 +54,7 @@ Berita Indo API (or in English is Indonesian News API) is an API to display many - [x] BBC News - [x] Tribun News - [x] Jawa Pos News + - [x] Vice - Improve API - [x] Search data news - [ ] Paginate data diff --git a/api/controllers/graphql/index.ts b/api/controllers/graphql/index.ts index 3e3bf85..55f6a77 100644 --- a/api/controllers/graphql/index.ts +++ b/api/controllers/graphql/index.ts @@ -138,6 +138,10 @@ const listsApi: ListsApi[] = [ label: 'Liputan 6 News', all: 'https://berita-indo-api.vercel.app/v1/liputan6-news', }, + { + label: 'Vice', + all: 'https://berita-indo-api.vercel.app/v1/vice', + }, ]; export const resolvers = { diff --git a/api/controllers/index.ts b/api/controllers/index.ts index 4d9f53c..7e708a9 100644 --- a/api/controllers/index.ts +++ b/api/controllers/index.ts @@ -9,6 +9,7 @@ import Liputan6News from './newshandler/Liputan6News' import BbcNews from './newshandler/BbcNews' import TribunNews from './newshandler/TribunNews' import JawaPosNews from './newshandler/JawaPosNews' +import ViceNews from './newshandler/ViceNews' import notFound from './404' export default { @@ -23,5 +24,6 @@ export default { BbcNews, TribunNews, JawaPosNews, + ViceNews, notFound } \ No newline at end of file diff --git a/api/controllers/newshandler/ViceNews.ts b/api/controllers/newshandler/ViceNews.ts new file mode 100644 index 0000000..0bc9c45 --- /dev/null +++ b/api/controllers/newshandler/ViceNews.ts @@ -0,0 +1,54 @@ +import { Response, Request } from 'express' +import { parserRss } from '../../../utils/parser' +import { RSS_VICE } from '../../../const' +import { DataResponse } from '../../../types/common' + +interface Params { + page?: string +} + +const limitString = (str: string, limit: number):string => { + const string: string = str + const length: number = limit + const result: string = string.length > length ? string.substring(0, length) + '....' : string; + return result +} + +class ViceNews { + static async getAllNews(req: Request, res: Response) { + try { + const { page }: Partial = req.params + const url = RSS_VICE.replace('{page}', `&page=${page}` ?? "") + const result = await parserRss(url) + const data = result.items.map((items) => { + items.image = { + small: items.enclosure.url + } + items.description = limitString(items.contentSnippet, 300) + delete items.contentSnippet + delete items.pubDate + delete items.enclosure + delete items.description + delete items.guid + delete items['content:encoded'] + delete items['content:encodedSnippet'] + delete items['dc:creator'] + return items + }) + const dataResponse: DataResponse = { + code: 200, + status: "OK", + messages: `Result of all news in Vice Indonesia`, + total: data.length, + data: data + } + return res.status(200).send(dataResponse) + } catch (e) { + return res.status(500).send({ + message: `${e.message}` + }) + } + } +} + +export default ViceNews \ No newline at end of file diff --git a/api/routes.ts b/api/routes.ts index 78401fb..6a3d3de 100644 --- a/api/routes.ts +++ b/api/routes.ts @@ -65,7 +65,10 @@ router.get('/', (_, res: Response) => { all: "https://berita-indo-api.vercel.app/v1/jawa-pos", listType: ["nasional", "entertainment", "pendidikan", "hukum-kriminal", "pemilihan", "sepak-bola", "jabodetabek", "internasional", "lifestyle", "kesehatan", "infrastruktur", "features", "oto-dan-tekno", "arsitektur-dan-desain", "art-space", "opini", "wisata-dan-kuliner", "hoax-atau-bukan"], example: "https://berita-indo-api.vercel.app/v1/jawa-pos/nasional" - } + }, + "Vice": { + all: "https://berita-indo-api.vercel.app/v1/vice", + }, }, author: "Satya Wikananda", source: "https://github.com/satyawikananda/berita-indo-api" @@ -91,6 +94,7 @@ router.get('/v1/bbc-news/', BeritaIndo.BbcNews.getAllNews) router.get('/v1/tribun-news/:zone/:type', BeritaIndo.TribunNews.getNews) router.get('/v1/tribun-news/:zone?', BeritaIndo.TribunNews.getAllNews) router.get('/v1/jawa-pos/:type?', BeritaIndo.JawaPosNews.getAllNews) +router.get('/v1/vice/:page?', BeritaIndo.ViceNews.getAllNews) router.all('*', BeritaIndo.notFound) diff --git a/const.ts b/const.ts index 2491bb4..056de9b 100644 --- a/const.ts +++ b/const.ts @@ -17,4 +17,5 @@ export const RSS_OKEZONE = { export const RSS_LIPUTAN6: string = 'https://feed.liputan6.com/rss' export const RSS_BBC: string = 'https://feeds.bbci.co.uk/indonesia/{type}/rss.xml' export const RSS_TRIBUN: string = 'https://{zone}.tribunnews.com/rss/' -export const RSS_JAWAPOS: string = 'https://www.jawapos.com/{type}/feed/' \ No newline at end of file +export const RSS_JAWAPOS: string = 'https://www.jawapos.com/{type}/feed/' +export const RSS_VICE: string = 'https://www.vice.com/id/rss?locale=id_id{page}'