From 060ec25fcc07529a36c03986fcb4d0257b390c82 Mon Sep 17 00:00:00 2001 From: "Jyotirmoy Bandyopadhyaya [Bravo68]" Date: Thu, 19 Jan 2023 10:04:52 +0530 Subject: [PATCH] Added Mastodon API for Portfolio --- packages/api/controllers/mastodon.controller.ts | 15 +++++++++++++++ packages/api/routes/me/mastodon.routes.ts | 11 +++++++++++ packages/api/services/mastodon.service.ts | 17 +++++++++++++++++ 3 files changed, 43 insertions(+) create mode 100644 packages/api/controllers/mastodon.controller.ts create mode 100644 packages/api/routes/me/mastodon.routes.ts create mode 100644 packages/api/services/mastodon.service.ts diff --git a/packages/api/controllers/mastodon.controller.ts b/packages/api/controllers/mastodon.controller.ts new file mode 100644 index 0000000..09258f2 --- /dev/null +++ b/packages/api/controllers/mastodon.controller.ts @@ -0,0 +1,15 @@ +import { makeResponse } from '../libs' +import MastodonService from '../services/mastodon.service' +import { Request, Response } from 'express' + +export default class MastodonController extends MastodonService { + public fetchMastodonProfile = async (req: Request, res: Response) => { + const data = await this.getMastodonProfile() + return res.send(makeResponse(data)) + } + + public fetchMastodonStatuses = async (req: Request, res: Response) => { + const data = await this.getMastodonStatuses() + return res.send(makeResponse(data)) + } +} diff --git a/packages/api/routes/me/mastodon.routes.ts b/packages/api/routes/me/mastodon.routes.ts new file mode 100644 index 0000000..0533f4a --- /dev/null +++ b/packages/api/routes/me/mastodon.routes.ts @@ -0,0 +1,11 @@ +import { Router } from 'express' +import MastodonController from '../../controllers/mastodon.controller' + +const { fetchMastodonProfile, fetchMastodonStatuses } = new MastodonController() + +const router = Router() + +router.get('/profile', fetchMastodonProfile) +router.get('/statuses', fetchMastodonStatuses) + +export default router diff --git a/packages/api/services/mastodon.service.ts b/packages/api/services/mastodon.service.ts new file mode 100644 index 0000000..31601ce --- /dev/null +++ b/packages/api/services/mastodon.service.ts @@ -0,0 +1,17 @@ +import axiosInstance from '../helpers/axios_client' + +export default class MastodonService { + public getMastodonProfile = async () => { + const { data } = await axiosInstance.get( + 'https://fosstodon.org/api/v1/accounts/109612266657666903' + ) + return data + } + + public getMastodonStatuses = async () => { + const { data } = await axiosInstance.get( + 'https://fosstodon.org/api/v1/accounts/109612266657666903/statuses' + ) + return data + } +}