diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx index b6918ac..4bfd675 100644 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -12,6 +12,7 @@ import './styles/App.css'; import CandidateList from './components/CandidateList'; import ApplicationList from './components/ApplicationList'; import Profile from './pages/Profile'; +import config from './config'; function App() { @@ -34,4 +35,4 @@ function App() { ); } -export default App; \ No newline at end of file +export default App; diff --git a/frontend/src/components/ApplicantForm.jsx b/frontend/src/components/ApplicantForm.jsx index 2966bc1..ffecd43 100644 --- a/frontend/src/components/ApplicantForm.jsx +++ b/frontend/src/components/ApplicantForm.jsx @@ -3,6 +3,10 @@ import React, { useState, useEffect } from 'react'; import { getApplicationByJobId, getCandidateByUserId } from "../crud" import "../styles/ApplicantForm.css" +import config from '../config.js'; +const apiServer = config.apiServer; + +//const apiServer="http://34.209.31.30:8080"; const ApplicantForm = ({ job }) => { const [applications, setApplications] = useState([]); @@ -48,7 +52,7 @@ const ApplicantForm = ({ job }) => { "application_status": "Accepted" }; - fetch(`http://localhost:8080/applications/${application.id}`, { + fetch(apiServer+`/applications/${application.id}`, { method: "PUT", headers: { 'Content-Type': 'application/json' @@ -70,7 +74,7 @@ const ApplicantForm = ({ job }) => { "additional_information": job.additional_information, "listing_status": "Closed" } - fetch(`http://localhost:8080/jobs/${job.id}`, { + fetch(apiServer+`/jobs/${job.id}`, { method: "PUT", headers: { 'Content-Type': 'application/json' @@ -95,7 +99,7 @@ const ApplicantForm = ({ job }) => { "application_status": "Denied" }; - fetch(`http://localhost:8080/applications/${application.id}`, { + fetch(apiServer+`/applications/${application.id}`, { method: "PUT", headers: { 'Content-Type': 'application/json' @@ -117,7 +121,7 @@ const ApplicantForm = ({ job }) => { "additional_information": job.additional_information, "listing_status": "Closed" } - fetch(`http://localhost:8080/jobs/${job.id}`, { + fetch(apiServer+`/jobs/${job.id}`, { method: "PUT", headers: { 'Content-Type': 'application/json' diff --git a/frontend/src/components/ApplicationList.jsx b/frontend/src/components/ApplicationList.jsx index 872078c..c2f33d1 100644 --- a/frontend/src/components/ApplicationList.jsx +++ b/frontend/src/components/ApplicationList.jsx @@ -3,6 +3,11 @@ import '../styles/ApplicationList.css'; import { getCookie } from '../utils/auth'; import { getJobById } from '../crud.js'; +import config from '../config.js'; +const apiServer = config.apiServer; + +//const apiServer="http://34.209.31.30:8080"; + const ApplicationList = ({ jobId, managerId }) => { const [applications, setApplications] = useState([]); const [loading, setLoading] = useState(true); @@ -17,7 +22,7 @@ const ApplicationList = ({ jobId, managerId }) => { throw new Error('User ID not found in cookie.'); } - const response = await fetch(`http://localhost:8080/applications/byUser/${userId}`); + const response = await fetch(apiServer+`/applications/byUser/${userId}`); if (!response.ok) { throw new Error('Failed to fetch applications.'); } diff --git a/frontend/src/components/SignupForm.jsx b/frontend/src/components/SignupForm.jsx index 8f91601..2eeceb7 100644 --- a/frontend/src/components/SignupForm.jsx +++ b/frontend/src/components/SignupForm.jsx @@ -7,6 +7,10 @@ import { verifySignupCredentials, getCookie, clearAllCookies } from '../utils/au import {getLoggedInUser} from '../crud'; import '../styles/LoginSignup.css'; +import config from '../config.js'; +const apiServer = config.apiServer; +//const apiServer="http://34.209.31.30:8080"; + export default function SignupForm(props) { const navigate = useNavigate(); @@ -30,7 +34,7 @@ export default function SignupForm(props) { }; - fetch('http://localhost:8080/users', { + fetch(apiServer+'/users', { method: "POST", headers: { 'Content-Type': 'application/json' @@ -45,7 +49,7 @@ export default function SignupForm(props) { }) .then(userResponse => { - return fetch('http://localhost:8080/candidates', { + return fetch(apiServer+'/candidates', { method: "POST", headers: { 'Content-Type': 'application/json' @@ -147,4 +151,4 @@ export default function SignupForm(props) {
); -} \ No newline at end of file +} diff --git a/frontend/src/config.js b/frontend/src/config.js new file mode 100644 index 0000000..e6dd6df --- /dev/null +++ b/frontend/src/config.js @@ -0,0 +1,4 @@ +const config = { + apiServer: 'http://34.209.31.30:8080' +}; +export default config; diff --git a/frontend/src/crud.js b/frontend/src/crud.js index 59def42..1fb3d31 100644 --- a/frontend/src/crud.js +++ b/frontend/src/crud.js @@ -1,6 +1,28 @@ +// apiServer="http://34.209.31.30:8080/" should be defined elsewhere, but I put it in main.jsx for now +//const apiServer="http://34.209.31.30:8080"; +import config from './config.js'; +const apiServer = config.apiServer; + export async function getAllUsers() { - return fetch('http://localhost:8080/users') + return await fetch(apiServer+'/users') + .then(response => { + return response.text(); + }) + .then((data) => { + return new Promise((resolve, reject) => { + resolve(data ? JSON.parse(data) : []); + reject(error); + }); + }) + .catch((error) => { + console.log("Error fetching all users", error); + }); + //const users = await response.json(); + //console.log(users); + //return users; + /* + return fetch(apiServer+'/users') .then((res) => { if(!res.ok) { throw new Error("failed to fetch"); @@ -11,16 +33,23 @@ export async function getAllUsers() { .catch((error) => { console.log("Error fetching all users", error); }) + */ } export async function getLoggedInUser(username, password) { try { - const response = await fetch('http://localhost:8080/users'); + /* + const response = await fetch(apiServer+'/users'); if (!response.ok) { throw new Error('Failed to fetch users'); } - const users = await response.json(); + const users = await getAllUsers(); + */ + let users =null ; + await getAllUsers().then(u => { + users = u; + }); const user = users.find(u => u.username === username && u.password === password); if (user === undefined) return null; @@ -33,7 +62,7 @@ export async function getLoggedInUser(username, password) { } export async function getUserById(id) { - return fetch(`http://localhost:8080/users/${id}`) + return fetch(`http://34.209.31.30:8080/users/${id}`) .then( (res) => { if (!res.ok) { throw new Error("Failed to fetch user") @@ -47,7 +76,7 @@ export async function getUserById(id) { } export async function getAllApplications() { - return fetch('http://localhost:8080/applications') + return fetch(apiServer+'/applications') .then((res) => { if(!res.ok) { throw new Error("failed to fetch"); @@ -65,7 +94,7 @@ export async function getApplicationById(id) { } export async function getApplicationByJobId(jobId) { - return fetch(`http://localhost:8080/applications/byJob/${jobId}`) + return fetch(`http://34.209.31.30:8080/applications/byJob/${jobId}`) .then((res) => { if(!res.ok) { throw new Error("failed to fetch"); @@ -79,7 +108,7 @@ export async function getApplicationByJobId(jobId) { } export async function getApplicationsByUserId(userId) { - return fetch(`http://localhost:8080/applications/byUser/${userId}`) + return fetch(`http://34.209.31.30:8080/applications/byUser/${userId}`) .then((res) => { if(!res.ok) { throw new Error("failed to fetch"); @@ -93,7 +122,7 @@ export async function getApplicationsByUserId(userId) { } export async function postApplication(application) { - return fetch('http://localhost:8080/applications', { + return fetch(apiServer+'/applications', { method: "POST", headers: { 'Content-Type': 'application/json' @@ -103,7 +132,7 @@ export async function postApplication(application) { } export async function getCandidateByUserId(userId) { - return fetch(`http://localhost:8080/candidates/byUser/${userId}`) + return fetch(`http://34.209.31.30:8080/candidates/byUser/${userId}`) .then((res) => { if(!res.ok) { throw new Error("failed to fetch"); @@ -117,7 +146,7 @@ export async function getCandidateByUserId(userId) { } export async function updateCandidate(candidate, id) { - return fetch(`http://localhost:8080/candidates/${id}`, { + return fetch(`http://34.209.31.30:8080/candidates/${id}`, { method: "PUT", headers: { 'Content-Type': 'application/json' @@ -127,7 +156,7 @@ export async function updateCandidate(candidate, id) { } export async function getCandidateById(id) { - return fetch(`http://localhost:8080/candidates/${id}`) + return fetch(`http://34.209.31.30:8080/candidates/${id}`) .then((res) => { if(!res.ok) { throw new Error("failed to fetch"); @@ -141,7 +170,7 @@ export async function getCandidateById(id) { } export async function getManagerByUserId(userId) { - return fetch(`http://localhost:8080/managers/byUser/${userId}`) + return fetch(`http://34.209.31.30:8080/managers/byUser/${userId}`) .then((res) => { if(!res.ok) { throw new Error("failed to fetch"); @@ -155,7 +184,7 @@ export async function getManagerByUserId(userId) { } export async function getCandidatesByJobId(jobId) { - return fetch(`http://localhost:8080/candidates/byJob/${jobId}`) + return fetch(`http://34.209.31.30:8080/candidates/byJob/${jobId}`) .then((res) => { if (!res.ok) { throw new Error("Failed to fetch candidates by job ID"); @@ -168,7 +197,7 @@ export async function getCandidatesByJobId(jobId) { } export async function getAllJobs() { - return fetch('http://localhost:8080/jobs') + return fetch(apiServer+'/jobs') .then((res) => { if(!res.ok) { throw new Error("failed to fetch"); @@ -182,7 +211,7 @@ export async function getAllJobs() { } export async function getJobById(id) { - return fetch(`http://localhost:8080/jobs/${id}`) + return fetch(`http://34.209.31.30:8080/jobs/${id}`) .then( (res) => { if (!res.ok) { throw new Error("Failed to fetch user") @@ -208,7 +237,7 @@ export async function getJobsByManagerId(managerId) { }; export async function getAllManagers() { - return fetch('http://localhost:8080/managers') + return fetch(apiServer+'/managers') .then((res) => { if(!res.ok) { throw new Error("failed to fetch"); @@ -222,7 +251,7 @@ export async function getAllManagers() { } export async function getAllCandidates() { - return fetch('http://localhost:8080/candidates') + return fetch(apiServer+'/candidates') .then((res) => { if(!res.ok) { throw new Error("failed to fetch"); @@ -233,4 +262,5 @@ export async function getAllCandidates() { .catch((error) => { console.log("Error fetching all candidates", error); }) -} \ No newline at end of file +} + diff --git a/frontend/src/main.jsx b/frontend/src/main.jsx index 89f91e5..68b9339 100644 --- a/frontend/src/main.jsx +++ b/frontend/src/main.jsx @@ -3,6 +3,7 @@ import { createRoot } from 'react-dom/client' import App from './App.jsx' import './index.css' + createRoot(document.getElementById('root')).render(