Skip to content

Commit

Permalink
bomb commit
Browse files Browse the repository at this point in the history
  • Loading branch information
bush1D3v committed Nov 3, 2024
1 parent 69ff330 commit 07d24a2
Show file tree
Hide file tree
Showing 31 changed files with 1,144 additions and 677 deletions.
2 changes: 2 additions & 0 deletions api/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import corsConfig from "./config/cors.ts";
import express from "express";
import coinMarketCapRoutes from "./routes/CoinMarketCap.ts";
import brapiDevRoutes from "./routes/BrapiDev.ts";
import currencyQuotesRoutes from "./routes/CurrencyQuotes.ts";

const app = express();

app.use(corsConfig);
app.use(express.json());
app.use(coinMarketCapRoutes);
app.use(brapiDevRoutes);
app.use(currencyQuotesRoutes);

export default app;
44 changes: 22 additions & 22 deletions api/src/proxy/BrapiDev.ts
Original file line number Diff line number Diff line change
@@ -1,49 +1,49 @@
import type { Request, Response } from "express";
import { get } from "../helpers/HttpClient.ts";
import type {Request, Response} from "express";
import {get} from "../helpers/HttpClient.ts";
import dotenv from "dotenv";
import type { Stock } from "../types/BrapiDev/Stock.ts";
import type {Stock} from "../types/BrapiDev/Stock.ts";
dotenv.config();

const BASE_API_URL = process.env.BRAPI_HOST as string;
const API_KEY = process.env.BRAPI_KEY as string;

const defaultHeaders = {
"Accept-Encoding": "deflate, gzip",
"referrer-policy": "origin-when-cross-origin",
"X-Api-Key": API_KEY,
"Accept-Encoding": "deflate, gzip",
"referrer-policy": "origin-when-cross-origin",
"X-Api-Key": API_KEY,
};

interface QueryParams {
limit?: number;
page?: number;
limit?: number;
page?: number;
}

interface ResponseData {
stocks: Stock[];
interface ResponseListStocks {
stocks: Stock[];
}

/**
* Handles the request to get the stocks listing.
* @description Handles the request to get the stocks listing.
*
* @param {Request} req - The request object
* @param {Response} res - The response object
* @returns {void}
* @throws {Error} If the request to the external API fails
*/
export async function listStocks(req: Request, res: Response): Promise<void> {
const { limit = 12, page = 1 }: QueryParams = req.query;
const url = `${BASE_API_URL}/api/quote/list?limit=${limit}&page=${page}`;
const {limit = 12, page = 1}: QueryParams = req.query;
const url = `${BASE_API_URL}/api/quote/list?limit=${limit}&page=${page}`;

try {
const response = await get(url, defaultHeaders);
try {
const response = await get(url, defaultHeaders);

if (!response.ok) throw new Error(await response.json());
if (!response.ok) throw new Error(await response.json());

const jsonData: ResponseData = await response.json();
const jsonData: ResponseListStocks = await response.json();

res.status(200).json(jsonData.stocks);
} catch (error) {
console.error(error);
res.status(500).json({ error: error });
}
res.status(200).json(jsonData.stocks);
} catch (error) {
console.error(error);
res.status(500).json({error: error});
}
}
4 changes: 2 additions & 2 deletions api/src/proxy/CoinMarketCap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ interface ResponseListingLatestData {
}

/**
* Handles the request to get the latest cryptocurrency listings.
* @description Handles the request to get the latest cryptocurrency listings.
*
* @param {Request} req - The request object
* @param {Response} res - The response object
Expand Down Expand Up @@ -57,7 +57,7 @@ interface ResponseDetailData {
}

/**
* Handles the request to get the latest cryptocurrency listings.
* @description Handles the request to get the latest cryptocurrency listings.
*
* @param {Request} req - The request object
* @param {Response} res - The response object
Expand Down
30 changes: 30 additions & 0 deletions api/src/proxy/CurrencyQuotes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import type {Request, Response} from "express";
import {get} from "../helpers/HttpClient.ts";
import type {CurrencyQuotes} from "../types/CurrencyQuotes/CurrencyQuotes.ts";

const BASE_API_URL = process.env.CURRENCYQUOTES_HOST as string;

/**
* @description Handles the request to get the list of currency quotes.
*
* @param {Request} req - The request object
* @param {Response} res - The response object
* @returns {void}
* @throws {Error} If the request to the external API fails
*/
export async function listCurrencyQuotes(req: Request, res: Response): Promise<void> {
const url = `${BASE_API_URL}/api/latest.json`;

try {
const response = await get(url);

if (!response.ok) throw new Error(await response.json());

const jsonData: CurrencyQuotes = await response.json();

res.json(jsonData);
} catch (error) {
console.error(error);
res.status(500).json({error: error});
}
}
2 changes: 1 addition & 1 deletion api/src/routes/BrapiDev.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import express from "express";
import { listStocks } from "../proxy/BrapiDev.ts";
import {listStocks} from "../proxy/BrapiDev.ts";

const brapiDevRoutes = express();

Expand Down
8 changes: 8 additions & 0 deletions api/src/routes/CurrencyQuotes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import express from "express";
import {listCurrencyQuotes} from "../proxy/CurrencyQuotes.ts";

const currencyQuotesRoutes = express();

currencyQuotesRoutes.get("/api/latest.json", listCurrencyQuotes);

export default currencyQuotesRoutes;
18 changes: 9 additions & 9 deletions api/src/types/BrapiDev/Stock.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
export interface Stock {
stock: string;
name: string;
close: number;
change: number;
volume: number;
market_cap: number;
logo: string;
sector: string;
type: string;
stock: string;
name: string;
close: number;
change: number;
volume: number;
market_cap: number;
logo: string;
sector: string;
type: string;
}
7 changes: 7 additions & 0 deletions api/src/types/CurrencyQuotes/CurrencyQuotes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type {Rates} from "./Rates";

export interface CurrencyQuotes {
table: string;
rates: Rates;
lastupdate: string; // ISO 8601 date string
}
193 changes: 193 additions & 0 deletions api/src/types/CurrencyQuotes/Rates.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
export interface Rates {
AED: number;
AFN: number;
ALL: number;
AMD: number;
ANG: number;
AOA: number;
ARS: number;
AUD: number;
AWG: number;
AZN: number;
BAM: number;
BBD: number;
BDT: number;
BGN: number;
BHD: number;
BIF: number;
BMD: number;
BND: number;
BOB: number;
BRL: number;
BSD: number;
BTC: number;
BTN: number;
BTS: number;
BWP: number;
BYN: number;
BZD: number;
CAD: number;
CDF: number;
CHF: number;
CLF: number;
CLP: number;
CNH: number;
CNY: number;
COP: number;
CRC: number;
CUC: number;
CUP: number;
CVE: number;
CZK: number;
DASH: number;
DJF: number;
DKK: number;
DOGE: number;
DOP: number;
DZD: number;
EGP: number;
ERN: number;
ETB: number;
ETH: number;
EUR: number;
FJD: number;
FKP: number;
GBP: number;
GEL: number;
GGP: number;
GHS: number;
GIP: number;
GMD: number;
GNF: number;
GTQ: number;
GYD: number;
HKD: number;
HNL: number;
HRK: number;
HTG: number;
HUF: number;
IDR: number;
ILS: number;
IMP: number;
INR: number;
IQD: number;
IRR: number;
ISK: number;
JEP: number;
JMD: number;
JOD: number;
JPY: number;
KES: number;
KGS: number;
KHR: number;
KMF: number;
KPW: number;
KRW: number;
KWD: number;
KYD: number;
KZT: number;
LAK: number;
LBP: number;
LD: number;
LKR: number;
LRD: number;
LSL: number;
LTC: number;
LYD: number;
MAD: number;
MDL: number;
MGA: number;
MKD: number;
MMK: number;
MNT: number;
MOP: number;
MRO: number;
MRU: number;
MUR: number;
MVR: number;
MWK: number;
MXN: number;
MYR: number;
MZN: number;
NAD: number;
NGN: number;
NIO: number;
NOK: number;
NPR: number;
NXT: number;
NZD: number;
OMR: number;
PAB: number;
PEN: number;
PGK: number;
PHP: number;
PKR: number;
PLN: number;
PYG: number;
QAR: number;
RON: number;
RSD: number;
RUB: number;
RWF: number;
SAR: number;
SBD: number;
SCR: number;
SDG: number;
SEK: number;
SGD: number;
SHP: number;
SLL: number;
SOS: number;
SRD: number;
SSP: number;
STD: number;
STN: number;
STR: number;
SVC: number;
SYP: number;
SZL: number;
THB: number;
TJS: number;
TMT: number;
TND: number;
TOP: number;
TRY: number;
TTD: number;
TWD: number;
TZS: number;
UAH: number;
UGX: number;
USD: number;
UYU: number;
UZS: number;
VEF_BLKMKT: number;
VEF_DICOM: number;
VEF_DIPRO: number;
VES: number;
VND: number;
VUV: number;
WST: number;
XAF: number;
XAG: number;
XAU: number;
XCD: number;
XDR: number;
XMR: number;
XOF: number;
XPD: number;
XPF: number;
XPT: number;
XRP: number;
YER: number;
ZAR: number;
ZMW: number;
ZWL: number;
NMC: number;
PPC: number;
NVC: number;
XPM: number;
EAC: number;
VTC: number;
EMC: number;
FCT: number;
}
Loading

0 comments on commit 07d24a2

Please sign in to comment.