diff --git a/.env.sample b/.env.sample deleted file mode 100644 index 247a89c..0000000 --- a/.env.sample +++ /dev/null @@ -1,6 +0,0 @@ -NEXT_PUBLIC_FIREBASE_API_KEY="" -NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN="" -NEXT_PUBLIC_FIREBASE_DATABASE_URL="" -NEXT_PUBLIC_FIREBASE_PROJECT_ID="" -NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET="" -NEXT_PUBLIC_FIREBASE_APP_ID="" diff --git a/package-lock.json b/package-lock.json index 5cf11ce..6e18dc7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,11 +1,11 @@ { - "name": "nextjs-app-router-with-firebase-auth", + "name": "bossprep", "version": "0.1.0", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "nextjs-app-router-with-firebase-auth", + "name": "bossprep", "version": "0.1.0", "dependencies": { "bootstrap": "^5.3.3", diff --git a/package.json b/package.json index 3328a4b..50b4553 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "nextjs-app-router-with-firebase-auth", + "name": "bossprep", "version": "0.1.0", "private": true, "scripts": { diff --git a/src/api/questionData.js b/src/api/questionData.js new file mode 100644 index 0000000..c90bd90 --- /dev/null +++ b/src/api/questionData.js @@ -0,0 +1,62 @@ +import { clientCredentials } from '../utils/client'; + +const endpoint = clientCredentials.databaseURL; + +const getQuestions = () => + new Promise((resolve, reject) => { + fetch(`${endpoint}/questions`, { + method: 'GET', + headers: { 'Content-Type': 'application/json' }, + }) + .then((res) => res.json()) + .then(resolve) + .catch(reject); + }); + +const getQuestion = (id) => + new Promise((resolve, reject) => { + fetch(`${endpoint}/questions/${id}`, { + method: 'GET', + headers: { 'Content-Type': 'application/json' }, + }) + .then((res) => res.json()) + .then(resolve) + .catch(reject); + }); + +const createQuestion = (questionData) => + new Promise((resolve, reject) => { + fetch(`${endpoint}/questions`, { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify(questionData), + }) + .then((res) => res.json()) + .then(resolve) + .catch(reject); + }); + +const updateQuestion = (id, questionData) => + new Promise((resolve, reject) => { + fetch(`${endpoint}/questions/${id}`, { + method: 'PUT', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify(questionData), + }) + .then((res) => res.json()) + .then(resolve) + .catch(reject); + }); + +const deleteQuestion = (id) => + new Promise((resolve, reject) => { + fetch(`${endpoint}/questions/${id}`, { + method: 'DELETE', + headers: { 'Content-Type': 'application/json' }, + }) + .then((res) => res.json()) + .then(resolve) + .catch(reject); + }); + +export { getQuestions, getQuestion, createQuestion, updateQuestion, deleteQuestion }; diff --git a/src/api/responseData.js b/src/api/responseData.js new file mode 100644 index 0000000..0069fd1 --- /dev/null +++ b/src/api/responseData.js @@ -0,0 +1,73 @@ +import { clientCredentials } from '../utils/client'; + +const endpoint = clientCredentials.databaseURL; + +const getResponses = () => + new Promise((resolve, reject) => { + fetch(`${endpoint}/responses`, { + method: 'GET', + headers: { 'Content-Type': 'application/json' }, + }) + .then((res) => res.json()) + .then(resolve) + .catch(reject); + }); + +const getResponsesByQuestion = (questionId) => + new Promise((resolve, reject) => { + fetch(`${endpoint}/responses?questionId=${questionId}`, { + method: 'GET', + headers: { 'Content-Type': 'application/json' }, + }) + .then((res) => res.json()) + .then(resolve) + .catch(reject); + }); + +const getResponse = (id) => + new Promise((resolve, reject) => { + fetch(`${endpoint}/responses/${id}`, { + method: 'GET', + headers: { 'Content-Type': 'application/json' }, + }) + .then((res) => res.json()) + .then(resolve) + .catch(reject); + }); + +const createResponse = (responseData) => + new Promise((resolve, reject) => { + fetch(`${endpoint}/responses`, { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify(responseData), + }) + .then((res) => res.json()) + .then(resolve) + .catch(reject); + }); + +const updateResponse = (id, responseData) => + new Promise((resolve, reject) => { + fetch(`${endpoint}/responses/${id}`, { + method: 'PUT', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify(responseData), + }) + .then((res) => res.json()) + .then(resolve) + .catch(reject); + }); + +const deleteResponse = (id) => + new Promise((resolve, reject) => { + fetch(`${endpoint}/responses/${id}`, { + method: 'DELETE', + headers: { 'Content-Type': 'application/json' }, + }) + .then((res) => res.json()) + .then(resolve) + .catch(reject); + }); + +export { getResponses, getResponsesByQuestion, getResponse, createResponse, updateResponse, deleteResponse }; diff --git a/src/api/trialData.js b/src/api/trialData.js new file mode 100644 index 0000000..2c9a215 --- /dev/null +++ b/src/api/trialData.js @@ -0,0 +1,73 @@ +import { clientCredentials } from '../utils/client'; + +const endpoint = clientCredentials.databaseURL; + +const getTrials = () => + new Promise((resolve, reject) => { + fetch(`${endpoint}/trials`, { + method: 'GET', + headers: { 'Content-Type': 'application/json' }, + }) + .then((res) => res.json()) + .then(resolve) + .catch(reject); + }); + +const getTrialsByCreator = (firebaseKey) => + new Promise((resolve, reject) => { + fetch(`${endpoint}/trials?creator=${firebaseKey}`, { + method: 'GET', + headers: { 'Content-Type': 'application/json' }, + }) + .then((res) => res.json()) + .then(resolve) + .catch(reject); + }); + +const getTrial = (id) => + new Promise((resolve, reject) => { + fetch(`${endpoint}/trials/${id}`, { + method: 'GET', + headers: { 'Content-Type': 'application/json' }, + }) + .then((res) => res.json()) + .then(resolve) + .catch(reject); + }); + +const createTrial = (trialData) => + new Promise((resolve, reject) => { + fetch(`${endpoint}/trials`, { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify(trialData), + }) + .then((res) => res.json()) + .then(resolve) + .catch(reject); + }); + +const updateTrial = (id, trialData) => + new Promise((resolve, reject) => { + fetch(`${endpoint}/trials/${id}`, { + method: 'PUT', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify(trialData), + }) + .then((res) => res.json()) + .then(resolve) + .catch(reject); + }); + +const deleteTrial = (id) => + new Promise((resolve, reject) => { + fetch(`${endpoint}/trials/${id}`, { + method: 'DELETE', + headers: { 'Content-Type': 'application/json' }, + }) + .then((res) => res.json()) + .then(resolve) + .catch(reject); + }); + +export { getTrials, getTrialsByCreator, getTrial, createTrial, updateTrial, deleteTrial }; diff --git a/src/api/trialQuestionData.js b/src/api/trialQuestionData.js new file mode 100644 index 0000000..653c5a5 --- /dev/null +++ b/src/api/trialQuestionData.js @@ -0,0 +1,62 @@ +import { clientCredentials } from '../utils/client'; + +const endpoint = clientCredentials.databaseURL; + +const getTrialQuestionsByUser = (firebaseKey) => + new Promise((resolve, reject) => { + fetch(`${endpoint}/trial-questions?userId=${firebaseKey}`, { + method: 'GET', + headers: { 'Content-Type': 'application/json' }, + }) + .then((res) => res.json()) + .then(resolve) + .catch(reject); + }); + +const getTrialQuestion = (id) => + new Promise((resolve, reject) => { + fetch(`${endpoint}/trial-questions/${id}`, { + method: 'GET', + headers: { 'Content-Type': 'application/json' }, + }) + .then((res) => res.json()) + .then(resolve) + .catch(reject); + }); + +const createTrialQuestion = (trialQuestionData) => + new Promise((resolve, reject) => { + fetch(`${endpoint}/trial-questions`, { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify(trialQuestionData), + }) + .then((res) => res.json()) + .then(resolve) + .catch(reject); + }); + +const updateTrialQuestion = (id, trialQuestionData) => + new Promise((resolve, reject) => { + fetch(`${endpoint}/trial-questions/${id}`, { + method: 'PUT', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify(trialQuestionData), + }) + .then((res) => res.json()) + .then(resolve) + .catch(reject); + }); + +const deleteTrialQuestion = (id) => + new Promise((resolve, reject) => { + fetch(`${endpoint}/trial-questions/${id}`, { + method: 'DELETE', + headers: { 'Content-Type': 'application/json' }, + }) + .then((res) => res.json()) + .then(resolve) + .catch(reject); + }); + +export { getTrialQuestionsByUser, getTrialQuestion, createTrialQuestion, updateTrialQuestion, deleteTrialQuestion }; diff --git a/src/api/user.js b/src/api/user.js new file mode 100644 index 0000000..30c843f --- /dev/null +++ b/src/api/user.js @@ -0,0 +1,62 @@ +import { clientCredentials } from '../utils/client'; + +const endpoint = clientCredentials.databaseURL; + +const getUsers = () => + new Promise((resolve, reject) => { + fetch(`${endpoint}/users`, { + method: 'GET', + headers: { 'Content-Type': 'application/json' }, + }) + .then((res) => res.json()) + .then(resolve) + .catch(reject); + }); + +const getUser = (id) => + new Promise((resolve, reject) => { + fetch(`${endpoint}/users/${id}`, { + method: 'GET', + headers: { 'Content-Type': 'application/json' }, + }) + .then((res) => res.json()) + .then(resolve) + .catch(reject); + }); + +const createUser = (userData) => + new Promise((resolve, reject) => { + fetch(`${endpoint}/users`, { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify(userData), + }) + .then((res) => res.json()) + .then(resolve) + .catch(reject); + }); + +const updateUser = (id, userData) => + new Promise((resolve, reject) => { + fetch(`${endpoint}/users/${id}`, { + method: 'PUT', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify(userData), + }) + .then((res) => res.json()) + .then(resolve) + .catch(reject); + }); + +const deleteUser = (id) => + new Promise((resolve, reject) => { + fetch(`${endpoint}/users/${id}`, { + method: 'DELETE', + headers: { 'Content-Type': 'application/json' }, + }) + .then((res) => res.json()) + .then(resolve) + .catch(reject); + }); + +export { getUsers, getUser, createUser, updateUser, deleteUser };