From 5eec1321179c7bfba176cc62913ee39ac1d68584 Mon Sep 17 00:00:00 2001 From: MuslemRahimi Date: Mon, 23 Sep 2024 01:28:11 +0200 Subject: [PATCH] protect endpoints --- .../basic-materials-sector/+page.server.ts | 43 +++++++++++ .../list/basic-materials-sector/+page.ts | 69 ------------------ .../+page.server.ts | 43 +++++++++++ .../communication-services-sector/+page.ts | 72 ------------------- .../consumer-cyclical-sector/+page.server.ts | 43 +++++++++++ .../list/consumer-cyclical-sector/+page.ts | 68 ------------------ .../consumer-defensive-sector/+page.server.ts | 43 +++++++++++ .../list/consumer-defensive-sector/+page.ts | 69 ------------------ src/routes/list/energy-sector/+page.server.ts | 43 +++++++++++ src/routes/list/energy-sector/+page.ts | 69 ------------------ .../list/financial-sector/+page.server.ts | 43 +++++++++++ src/routes/list/financial-sector/+page.ts | 69 ------------------ .../list/healthcare-sector/+page.server.ts | 43 +++++++++++ src/routes/list/healthcare-sector/+page.ts | 69 ------------------ .../list/industrials-sector/+page.server.ts | 43 +++++++++++ src/routes/list/industrials-sector/+page.ts | 69 ------------------ .../list/real-estate-sector/+page.server.ts | 43 +++++++++++ src/routes/list/real-estate-sector/+page.ts | 68 ------------------ .../list/technology-sector/+page.server.ts | 43 +++++++++++ src/routes/list/technology-sector/+page.ts | 69 ------------------ .../list/utilities-sector/+page.server.ts | 43 +++++++++++ src/routes/list/utilities-sector/+page.ts | 69 ------------------ src/routes/stocks/[tickerID]/+page.svelte | 1 - 23 files changed, 473 insertions(+), 761 deletions(-) create mode 100644 src/routes/list/basic-materials-sector/+page.server.ts delete mode 100644 src/routes/list/basic-materials-sector/+page.ts create mode 100644 src/routes/list/communication-services-sector/+page.server.ts delete mode 100644 src/routes/list/communication-services-sector/+page.ts create mode 100644 src/routes/list/consumer-cyclical-sector/+page.server.ts delete mode 100644 src/routes/list/consumer-cyclical-sector/+page.ts create mode 100644 src/routes/list/consumer-defensive-sector/+page.server.ts delete mode 100644 src/routes/list/consumer-defensive-sector/+page.ts create mode 100644 src/routes/list/energy-sector/+page.server.ts delete mode 100644 src/routes/list/energy-sector/+page.ts create mode 100644 src/routes/list/financial-sector/+page.server.ts delete mode 100644 src/routes/list/financial-sector/+page.ts create mode 100644 src/routes/list/healthcare-sector/+page.server.ts delete mode 100644 src/routes/list/healthcare-sector/+page.ts create mode 100644 src/routes/list/industrials-sector/+page.server.ts delete mode 100644 src/routes/list/industrials-sector/+page.ts create mode 100644 src/routes/list/real-estate-sector/+page.server.ts delete mode 100644 src/routes/list/real-estate-sector/+page.ts create mode 100644 src/routes/list/technology-sector/+page.server.ts delete mode 100644 src/routes/list/technology-sector/+page.ts create mode 100644 src/routes/list/utilities-sector/+page.server.ts delete mode 100644 src/routes/list/utilities-sector/+page.ts diff --git a/src/routes/list/basic-materials-sector/+page.server.ts b/src/routes/list/basic-materials-sector/+page.server.ts new file mode 100644 index 00000000..2dcf61f1 --- /dev/null +++ b/src/routes/list/basic-materials-sector/+page.server.ts @@ -0,0 +1,43 @@ +export const load = async ({ locals }) => { + const { apiKey, apiURL } = locals; + + const getBasicMaterialsSector = async () => { + const postData = { filterList: "basic-materials" }; + + const response = await fetch(apiURL + "/filter-stock-list", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + + const output = await response.json(); + + return output; + }; + + const getHistoricalSector = async () => { + const postData = { filterList: "basic-materials" }; + + const response = await fetch(apiURL + "/historical-sector-price", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + + const output = await response.json(); + + return output; + }; + + // Make sure to return a promise + return { + getBasicMaterialsSector: await getBasicMaterialsSector(), + getHistoricalSector: await getHistoricalSector(), + }; +}; diff --git a/src/routes/list/basic-materials-sector/+page.ts b/src/routes/list/basic-materials-sector/+page.ts deleted file mode 100644 index 12ddd94c..00000000 --- a/src/routes/list/basic-materials-sector/+page.ts +++ /dev/null @@ -1,69 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent }) => { - const getBasicMaterialsSector = async () => { - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache("", "getBasicMaterialsSector"); - if (cachedData) { - output = cachedData; - } else { - const { apiKey, apiURL } = await parent(); - - const postData = { filterList: "basic-materials" }; - - const response = await fetch(apiURL + "/filter-stock-list", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - body: JSON.stringify(postData), - }); - - output = await response.json(); - - // Cache the data for this specific tickerID with a specific name 'getBasicMaterialsSector' - setCache("", output, "getBasicMaterialsSector"); - } - - return output; - }; - - const getHistoricalSector = async () => { - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache("basic-materials", "getHistoricalSector"); - if (cachedData) { - output = cachedData; - } else { - const { apiKey, apiURL } = await parent(); - - const postData = { filterList: "basic-materials" }; - - const response = await fetch(apiURL + "/historical-sector-price", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - body: JSON.stringify(postData), - }); - - output = await response.json(); - - // Cache the data for this specific tickerID with a specific name 'getHistoricalSector' - setCache("basic-materials", output, "getHistoricalSector"); - } - - return output; - }; - - // Make sure to return a promise - return { - getBasicMaterialsSector: await getBasicMaterialsSector(), - getHistoricalSector: await getHistoricalSector(), - }; -}; diff --git a/src/routes/list/communication-services-sector/+page.server.ts b/src/routes/list/communication-services-sector/+page.server.ts new file mode 100644 index 00000000..0b2e635a --- /dev/null +++ b/src/routes/list/communication-services-sector/+page.server.ts @@ -0,0 +1,43 @@ +export const load = async ({ locals }) => { + const { apiKey, apiURL } = locals; + + const getCommunicationServicesSector = async () => { + const postData = { filterList: "communication-services" }; + + const response = await fetch(apiURL + "/filter-stock-list", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + + const output = await response.json(); + + return output; + }; + + const getHistoricalSector = async () => { + const postData = { filterList: "communication-services" }; + + const response = await fetch(apiURL + "/historical-sector-price", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + + const output = await response.json(); + + return output; + }; + + // Make sure to return a promise + return { + getCommunicationServicesSector: await getCommunicationServicesSector(), + getHistoricalSector: await getHistoricalSector(), + }; +}; diff --git a/src/routes/list/communication-services-sector/+page.ts b/src/routes/list/communication-services-sector/+page.ts deleted file mode 100644 index 85a50eb4..00000000 --- a/src/routes/list/communication-services-sector/+page.ts +++ /dev/null @@ -1,72 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent }) => { - const getCommunicationServicesSector = async () => { - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache("", "getCommunicationServicesSector"); - if (cachedData) { - output = cachedData; - } else { - const { apiKey, apiURL } = await parent(); - - const postData = { filterList: "communication-services" }; - - const response = await fetch(apiURL + "/filter-stock-list", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - body: JSON.stringify(postData), - }); - - output = await response.json(); - - // Cache the data for this specific tickerID with a specific name 'getCommunicationServicesSector' - setCache("", output, "getCommunicationServicesSector"); - } - - return output; - }; - - const getHistoricalSector = async () => { - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache( - "communication-services", - "getHistoricalSector", - ); - if (cachedData) { - output = cachedData; - } else { - const { apiKey, apiURL } = await parent(); - - const postData = { filterList: "communication-services" }; - - const response = await fetch(apiURL + "/historical-sector-price", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - body: JSON.stringify(postData), - }); - - output = await response.json(); - - // Cache the data for this specific tickerID with a specific name 'getHistoricalSector' - setCache("communication-services", output, "getHistoricalSector"); - } - - return output; - }; - - // Make sure to return a promise - return { - getCommunicationServicesSector: await getCommunicationServicesSector(), - getHistoricalSector: await getHistoricalSector(), - }; -}; diff --git a/src/routes/list/consumer-cyclical-sector/+page.server.ts b/src/routes/list/consumer-cyclical-sector/+page.server.ts new file mode 100644 index 00000000..6cb55929 --- /dev/null +++ b/src/routes/list/consumer-cyclical-sector/+page.server.ts @@ -0,0 +1,43 @@ +export const load = async ({ locals }) => { + const { apiKey, apiURL } = locals; + + const getConsumerCyclicalSector = async () => { + const postData = { filterList: "consumer-cyclical" }; + + const response = await fetch(apiURL + "/filter-stock-list", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + + const output = await response.json(); + + return output; + }; + + const getHistoricalSector = async () => { + const postData = { filterList: "consumer-cyclical" }; + + const response = await fetch(apiURL + "/historical-sector-price", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + + const output = await response.json(); + + return output; + }; + + // Make sure to return a promise + return { + getConsumerCyclicalSector: await getConsumerCyclicalSector(), + getHistoricalSector: await getHistoricalSector(), + }; +}; diff --git a/src/routes/list/consumer-cyclical-sector/+page.ts b/src/routes/list/consumer-cyclical-sector/+page.ts deleted file mode 100644 index ad0ceb67..00000000 --- a/src/routes/list/consumer-cyclical-sector/+page.ts +++ /dev/null @@ -1,68 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent }) => { - const getConsumerCyclicalSector = async () => { - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache("", "getConsumerCyclicalSector"); - if (cachedData) { - output = cachedData; - } else { - const { apiKey, apiURL } = await parent(); - const postData = { filterList: "consumer-cyclical" }; - - const response = await fetch(apiURL + "/filter-stock-list", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - body: JSON.stringify(postData), - }); - - output = await response.json(); - - // Cache the data for this specific tickerID with a specific name 'getConsumerCyclicalSector' - setCache("", output, "getConsumerCyclicalSector"); - } - - return output; - }; - - const getHistoricalSector = async () => { - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache("consumer-cyclical", "getHistoricalSector"); - if (cachedData) { - output = cachedData; - } else { - const { apiKey, apiURL } = await parent(); - - const postData = { filterList: "consumer-cyclical" }; - - const response = await fetch(apiURL + "/historical-sector-price", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - body: JSON.stringify(postData), - }); - - output = await response.json(); - - // Cache the data for this specific tickerID with a specific name 'getHistoricalSector' - setCache("consumer-cyclical", output, "getHistoricalSector"); - } - - return output; - }; - - // Make sure to return a promise - return { - getConsumerCyclicalSector: await getConsumerCyclicalSector(), - getHistoricalSector: await getHistoricalSector(), - }; -}; diff --git a/src/routes/list/consumer-defensive-sector/+page.server.ts b/src/routes/list/consumer-defensive-sector/+page.server.ts new file mode 100644 index 00000000..aa486954 --- /dev/null +++ b/src/routes/list/consumer-defensive-sector/+page.server.ts @@ -0,0 +1,43 @@ +export const load = async ({ locals }) => { + const { apiKey, apiURL } = locals; + + const getConsumerDefensiveSector = async () => { + const postData = { filterList: "consumer-defensive" }; + + const response = await fetch(apiURL + "/filter-stock-list", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + + const output = await response.json(); + + return output; + }; + + const getHistoricalSector = async () => { + const postData = { filterList: "consumer-defensive" }; + + const response = await fetch(apiURL + "/historical-sector-price", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + + const output = await response.json(); + + return output; + }; + + // Make sure to return a promise + return { + getConsumerDefensiveSector: await getConsumerDefensiveSector(), + getHistoricalSector: await getHistoricalSector(), + }; +}; diff --git a/src/routes/list/consumer-defensive-sector/+page.ts b/src/routes/list/consumer-defensive-sector/+page.ts deleted file mode 100644 index 9972d651..00000000 --- a/src/routes/list/consumer-defensive-sector/+page.ts +++ /dev/null @@ -1,69 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent }) => { - const getConsumerDefensiveSector = async () => { - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache("", "getConsumerDefensiveSector"); - if (cachedData) { - output = cachedData; - } else { - const { apiKey, apiURL } = await parent(); - - const postData = { filterList: "consumer-defensive" }; - - const response = await fetch(apiURL + "/filter-stock-list", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - body: JSON.stringify(postData), - }); - - output = await response.json(); - - // Cache the data for this specific tickerID with a specific name 'getConsumerDefensiveSector' - setCache("", output, "getConsumerDefensiveSector"); - } - - return output; - }; - - const getHistoricalSector = async () => { - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache("consumer-defensive", "getHistoricalSector"); - if (cachedData) { - output = cachedData; - } else { - const { apiKey, apiURL } = await parent(); - - const postData = { filterList: "consumer-defensive" }; - - const response = await fetch(apiURL + "/historical-sector-price", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - body: JSON.stringify(postData), - }); - - output = await response.json(); - - // Cache the data for this specific tickerID with a specific name 'getHistoricalSector' - setCache("consumer-defensive", output, "getHistoricalSector"); - } - - return output; - }; - - // Make sure to return a promise - return { - getConsumerDefensiveSector: await getConsumerDefensiveSector(), - getHistoricalSector: await getHistoricalSector(), - }; -}; diff --git a/src/routes/list/energy-sector/+page.server.ts b/src/routes/list/energy-sector/+page.server.ts new file mode 100644 index 00000000..5817fd4f --- /dev/null +++ b/src/routes/list/energy-sector/+page.server.ts @@ -0,0 +1,43 @@ +export const load = async ({ locals }) => { + const { apiKey, apiURL } = locals; + + const getEnergySector = async () => { + const postData = { filterList: "energy" }; + + const response = await fetch(apiURL + "/filter-stock-list", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + + const output = await response.json(); + + return output; + }; + + const getHistoricalSector = async () => { + const postData = { filterList: "energy" }; + + const response = await fetch(apiURL + "/historical-sector-price", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + + const output = await response.json(); + + return output; + }; + + // Make sure to return a promise + return { + getEnergySector: await getEnergySector(), + getHistoricalSector: await getHistoricalSector(), + }; +}; diff --git a/src/routes/list/energy-sector/+page.ts b/src/routes/list/energy-sector/+page.ts deleted file mode 100644 index bf42b799..00000000 --- a/src/routes/list/energy-sector/+page.ts +++ /dev/null @@ -1,69 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent }) => { - const getEnergySector = async () => { - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache("", "getEnergySector"); - if (cachedData) { - output = cachedData; - } else { - const { apiKey, apiURL } = await parent(); - - const postData = { filterList: "energy" }; - - const response = await fetch(apiURL + "/filter-stock-list", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - body: JSON.stringify(postData), - }); - - output = await response.json(); - - // Cache the data for this specific tickerID with a specific name 'getEnergySector' - setCache("", output, "getEnergySector"); - } - - return output; - }; - - const getHistoricalSector = async () => { - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache("energy", "getHistoricalSector"); - if (cachedData) { - output = cachedData; - } else { - const { apiKey, apiURL } = await parent(); - - const postData = { filterList: "energy" }; - - const response = await fetch(apiURL + "/historical-sector-price", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - body: JSON.stringify(postData), - }); - - output = await response.json(); - - // Cache the data for this specific tickerID with a specific name 'getHistoricalSector' - setCache("energy", output, "getHistoricalSector"); - } - - return output; - }; - - // Make sure to return a promise - return { - getEnergySector: await getEnergySector(), - getHistoricalSector: await getHistoricalSector(), - }; -}; diff --git a/src/routes/list/financial-sector/+page.server.ts b/src/routes/list/financial-sector/+page.server.ts new file mode 100644 index 00000000..8e162740 --- /dev/null +++ b/src/routes/list/financial-sector/+page.server.ts @@ -0,0 +1,43 @@ +export const load = async ({ locals }) => { + const { apiKey, apiURL } = locals; + + const getFinancialSector = async () => { + const postData = { filterList: "financial" }; + + const response = await fetch(apiURL + "/filter-stock-list", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + + const output = await response.json(); + + return output; + }; + + const getHistoricalSector = async () => { + const postData = { filterList: "financial" }; + + const response = await fetch(apiURL + "/historical-sector-price", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + + const output = await response.json(); + + return output; + }; + + // Make sure to return a promise + return { + getFinancialSector: await getFinancialSector(), + getHistoricalSector: await getHistoricalSector(), + }; +}; diff --git a/src/routes/list/financial-sector/+page.ts b/src/routes/list/financial-sector/+page.ts deleted file mode 100644 index e97cdfd6..00000000 --- a/src/routes/list/financial-sector/+page.ts +++ /dev/null @@ -1,69 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent }) => { - const getFinancialSector = async () => { - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache("", "getFinancialSector"); - if (cachedData) { - output = cachedData; - } else { - const { apiKey, apiURL } = await parent(); - - const postData = { filterList: "financial" }; - - const response = await fetch(apiURL + "/filter-stock-list", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - body: JSON.stringify(postData), - }); - - output = await response.json(); - - // Cache the data for this specific tickerID with a specific name 'getFinancialSector' - setCache("", output, "getFinancialSector"); - } - - return output; - }; - - const getHistoricalSector = async () => { - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache("financial", "getHistoricalSector"); - if (cachedData) { - output = cachedData; - } else { - const { apiKey, apiURL } = await parent(); - - const postData = { filterList: "financial" }; - - const response = await fetch(apiURL + "/historical-sector-price", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - body: JSON.stringify(postData), - }); - - output = await response.json(); - - // Cache the data for this specific tickerID with a specific name 'getHistoricalSector' - setCache("financial", output, "getHistoricalSector"); - } - - return output; - }; - - // Make sure to return a promise - return { - getFinancialSector: await getFinancialSector(), - getHistoricalSector: await getHistoricalSector(), - }; -}; diff --git a/src/routes/list/healthcare-sector/+page.server.ts b/src/routes/list/healthcare-sector/+page.server.ts new file mode 100644 index 00000000..6e126360 --- /dev/null +++ b/src/routes/list/healthcare-sector/+page.server.ts @@ -0,0 +1,43 @@ +export const load = async ({ locals }) => { + const { apiKey, apiURL } = locals; + + const getHealthcareSector = async () => { + const postData = { filterList: "healthcare" }; + + const response = await fetch(apiURL + "/filter-stock-list", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + + const output = await response.json(); + + return output; + }; + + const getHistoricalSector = async () => { + const postData = { filterList: "healthcare" }; + + const response = await fetch(apiURL + "/historical-sector-price", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + + const output = await response.json(); + + return output; + }; + + // Make sure to return a promise + return { + getHealthcareSector: await getHealthcareSector(), + getHistoricalSector: await getHistoricalSector(), + }; +}; diff --git a/src/routes/list/healthcare-sector/+page.ts b/src/routes/list/healthcare-sector/+page.ts deleted file mode 100644 index 12fad0d5..00000000 --- a/src/routes/list/healthcare-sector/+page.ts +++ /dev/null @@ -1,69 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent }) => { - const getHealthcareSector = async () => { - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache("", "getHealthcareSector"); - if (cachedData) { - output = cachedData; - } else { - const { apiKey, apiURL } = await parent(); - - const postData = { filterList: "healthcare" }; - - const response = await fetch(apiURL + "/filter-stock-list", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - body: JSON.stringify(postData), - }); - - output = await response.json(); - - // Cache the data for this specific tickerID with a specific name 'getHealthcareSector' - setCache("", output, "getHealthcareSector"); - } - - return output; - }; - - const getHistoricalSector = async () => { - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache("healthcare", "getHistoricalSector"); - if (cachedData) { - output = cachedData; - } else { - const { apiKey, apiURL } = await parent(); - - const postData = { filterList: "healthcare" }; - - const response = await fetch(apiURL + "/historical-sector-price", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - body: JSON.stringify(postData), - }); - - output = await response.json(); - - // Cache the data for this specific tickerID with a specific name 'getHistoricalSector' - setCache("healthcare", output, "getHistoricalSector"); - } - - return output; - }; - - // Make sure to return a promise - return { - getHealthcareSector: await getHealthcareSector(), - getHistoricalSector: await getHistoricalSector(), - }; -}; diff --git a/src/routes/list/industrials-sector/+page.server.ts b/src/routes/list/industrials-sector/+page.server.ts new file mode 100644 index 00000000..8e3dd167 --- /dev/null +++ b/src/routes/list/industrials-sector/+page.server.ts @@ -0,0 +1,43 @@ +export const load = async ({ locals }) => { + const { apiKey, apiURL } = locals; + + const getIndustrialsSector = async () => { + const postData = { filterList: "industrials" }; + + const response = await fetch(apiURL + "/filter-stock-list", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + + const output = await response.json(); + + return output; + }; + + const getHistoricalSector = async () => { + const postData = { filterList: "industrials" }; + + const response = await fetch(apiURL + "/historical-sector-price", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + + const output = await response.json(); + + return output; + }; + + // Make sure to return a promise + return { + getIndustrialsSector: await getIndustrialsSector(), + getHistoricalSector: await getHistoricalSector(), + }; +}; diff --git a/src/routes/list/industrials-sector/+page.ts b/src/routes/list/industrials-sector/+page.ts deleted file mode 100644 index e0084630..00000000 --- a/src/routes/list/industrials-sector/+page.ts +++ /dev/null @@ -1,69 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent }) => { - const getIndustrialsSector = async () => { - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache("", "getIndustrialsSector"); - if (cachedData) { - output = cachedData; - } else { - const { apiKey, apiURL } = await parent(); - - const postData = { filterList: "industrials" }; - - const response = await fetch(apiURL + "/filter-stock-list", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - body: JSON.stringify(postData), - }); - - output = await response.json(); - - // Cache the data for this specific tickerID with a specific name 'getIndustrialsSector' - setCache("", output, "getIndustrialsSector"); - } - - return output; - }; - - const getHistoricalSector = async () => { - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache("industrials", "getHistoricalSector"); - if (cachedData) { - output = cachedData; - } else { - const { apiKey, apiURL } = await parent(); - - const postData = { filterList: "industrials" }; - - const response = await fetch(apiURL + "/historical-sector-price", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - body: JSON.stringify(postData), - }); - - output = await response.json(); - - // Cache the data for this specific tickerID with a specific name 'getHistoricalSector' - setCache("industrials", output, "getHistoricalSector"); - } - - return output; - }; - - // Make sure to return a promise - return { - getIndustrialsSector: await getIndustrialsSector(), - getHistoricalSector: await getHistoricalSector(), - }; -}; diff --git a/src/routes/list/real-estate-sector/+page.server.ts b/src/routes/list/real-estate-sector/+page.server.ts new file mode 100644 index 00000000..823729fa --- /dev/null +++ b/src/routes/list/real-estate-sector/+page.server.ts @@ -0,0 +1,43 @@ +export const load = async ({ locals }) => { + const { apiKey, apiURL } = locals; + + const getRealEstateSector = async () => { + const postData = { filterList: "real-estate" }; + + const response = await fetch(apiURL + "/filter-stock-list", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + + const output = await response.json(); + + return output; + }; + + const getHistoricalSector = async () => { + const postData = { filterList: "real-estate" }; + + const response = await fetch(apiURL + "/historical-sector-price", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + + const output = await response.json(); + + return output; + }; + + // Make sure to return a promise + return { + getRealEstateSector: await getRealEstateSector(), + getHistoricalSector: await getHistoricalSector(), + }; +}; diff --git a/src/routes/list/real-estate-sector/+page.ts b/src/routes/list/real-estate-sector/+page.ts deleted file mode 100644 index 88bd83ed..00000000 --- a/src/routes/list/real-estate-sector/+page.ts +++ /dev/null @@ -1,68 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent }) => { - const getRealEstateSector = async () => { - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache("", "getRealEstateSector"); - if (cachedData) { - output = cachedData; - } else { - const { apiKey, apiURL } = await parent(); - - const postData = { filterList: "real-estate" }; - const response = await fetch(apiURL + "/filter-stock-list", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - body: JSON.stringify(postData), - }); - - output = await response.json(); - - // Cache the data for this specific tickerID with a specific name 'getRealEstateSector' - setCache("", output, "getRealEstateSector"); - } - - return output; - }; - - const getHistoricalSector = async () => { - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache("real-estate", "getHistoricalSector"); - if (cachedData) { - output = cachedData; - } else { - const { apiKey, apiURL } = await parent(); - - const postData = { filterList: "real-estate" }; - - const response = await fetch(apiURL + "/historical-sector-price", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - body: JSON.stringify(postData), - }); - - output = await response.json(); - - // Cache the data for this specific tickerID with a specific name 'getHistoricalSector' - setCache("real-estate", output, "getHistoricalSector"); - } - - return output; - }; - - // Make sure to return a promise - return { - getRealEstateSector: await getRealEstateSector(), - getHistoricalSector: await getHistoricalSector(), - }; -}; diff --git a/src/routes/list/technology-sector/+page.server.ts b/src/routes/list/technology-sector/+page.server.ts new file mode 100644 index 00000000..e0aed335 --- /dev/null +++ b/src/routes/list/technology-sector/+page.server.ts @@ -0,0 +1,43 @@ +export const load = async ({ locals }) => { + const { apiKey, apiURL } = locals; + + const getTechnologySector = async () => { + const postData = { filterList: "technology" }; + + const response = await fetch(apiURL + "/filter-stock-list", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + + const output = await response.json(); + + return output; + }; + + const getHistoricalSector = async () => { + const postData = { filterList: "technology" }; + + const response = await fetch(apiURL + "/historical-sector-price", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + + const output = await response.json(); + + return output; + }; + + // Make sure to return a promise + return { + getTechnologySector: await getTechnologySector(), + getHistoricalSector: await getHistoricalSector(), + }; +}; diff --git a/src/routes/list/technology-sector/+page.ts b/src/routes/list/technology-sector/+page.ts deleted file mode 100644 index 5b7e50f9..00000000 --- a/src/routes/list/technology-sector/+page.ts +++ /dev/null @@ -1,69 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent }) => { - const getTechnologySector = async () => { - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache("", "getTechnologySector"); - if (cachedData) { - output = cachedData; - } else { - const { apiKey, apiURL } = await parent(); - - const postData = { filterList: "technology" }; - - const response = await fetch(apiURL + "/filter-stock-list", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - body: JSON.stringify(postData), - }); - - output = await response.json(); - - // Cache the data for this specific tickerID with a specific name 'getTechnologySector' - setCache("", output, "getTechnologySector"); - } - - return output; - }; - - const getHistoricalSector = async () => { - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache("technology", "getHistoricalSector"); - if (cachedData) { - output = cachedData; - } else { - const { apiKey, apiURL } = await parent(); - - const postData = { filterList: "technology" }; - - const response = await fetch(apiURL + "/historical-sector-price", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - body: JSON.stringify(postData), - }); - - output = await response.json(); - - // Cache the data for this specific tickerID with a specific name 'getHistoricalSector' - setCache("technology", output, "getHistoricalSector"); - } - - return output; - }; - - // Make sure to return a promise - return { - getTechnologySector: await getTechnologySector(), - getHistoricalSector: await getHistoricalSector(), - }; -}; diff --git a/src/routes/list/utilities-sector/+page.server.ts b/src/routes/list/utilities-sector/+page.server.ts new file mode 100644 index 00000000..c9800ef5 --- /dev/null +++ b/src/routes/list/utilities-sector/+page.server.ts @@ -0,0 +1,43 @@ +export const load = async ({ locals }) => { + const { apiKey, apiURL } = locals; + + const getUtilitiesSector = async () => { + const postData = { filterList: "utilities" }; + + const response = await fetch(apiURL + "/filter-stock-list", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + + const output = await response.json(); + + return output; + }; + + const getHistoricalSector = async () => { + const postData = { filterList: "utilities" }; + + const response = await fetch(apiURL + "/historical-sector-price", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + + const output = await response.json(); + + return output; + }; + + // Make sure to return a promise + return { + getUtilitiesSector: await getUtilitiesSector(), + getHistoricalSector: await getHistoricalSector(), + }; +}; diff --git a/src/routes/list/utilities-sector/+page.ts b/src/routes/list/utilities-sector/+page.ts deleted file mode 100644 index 239addf4..00000000 --- a/src/routes/list/utilities-sector/+page.ts +++ /dev/null @@ -1,69 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent }) => { - const getUtilitiesSector = async () => { - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache("", "getUtilitiesSector"); - if (cachedData) { - output = cachedData; - } else { - const { apiKey, apiURL } = await parent(); - - const postData = { filterList: "utilities" }; - - const response = await fetch(apiURL + "/filter-stock-list", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - body: JSON.stringify(postData), - }); - - output = await response.json(); - - // Cache the data for this specific tickerID with a specific name 'getUtilitiesSector' - setCache("", output, "getUtilitiesSector"); - } - - return output; - }; - - const getHistoricalSector = async () => { - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache("utilities", "getHistoricalSector"); - if (cachedData) { - output = cachedData; - } else { - const { apiKey, apiURL } = await parent(); - - const postData = { filterList: "utilities" }; - - const response = await fetch(apiURL + "/historical-sector-price", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - body: JSON.stringify(postData), - }); - - output = await response.json(); - - // Cache the data for this specific tickerID with a specific name 'getHistoricalSector' - setCache("utilities", output, "getHistoricalSector"); - } - - return output; - }; - - // Make sure to return a promise - return { - getUtilitiesSector: await getUtilitiesSector(), - getHistoricalSector: await getHistoricalSector(), - }; -}; diff --git a/src/routes/stocks/[tickerID]/+page.svelte b/src/routes/stocks/[tickerID]/+page.svelte index 65db2312..135877bb 100644 --- a/src/routes/stocks/[tickerID]/+page.svelte +++ b/src/routes/stocks/[tickerID]/+page.svelte @@ -607,7 +607,6 @@ async function historicalPrice(timePeriod: string) { method: "POST", headers: { "Content-Type": "application/json", - "X-API-KEY": data?.apiKey, }, body: JSON.stringify(postData), });