Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion frontend/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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() {

Expand All @@ -34,4 +35,4 @@ function App() {
);
}

export default App;
export default App;
12 changes: 8 additions & 4 deletions frontend/src/components/ApplicantForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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([]);
Expand Down Expand Up @@ -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'
Expand All @@ -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'
Expand All @@ -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'
Expand All @@ -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'
Expand Down
7 changes: 6 additions & 1 deletion frontend/src/components/ApplicationList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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.');
}
Expand Down
10 changes: 7 additions & 3 deletions frontend/src/components/SignupForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -30,7 +34,7 @@ export default function SignupForm(props) {
};


fetch('http://localhost:8080/users', {
fetch(apiServer+'/users', {
method: "POST",
headers: {
'Content-Type': 'application/json'
Expand All @@ -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'
Expand Down Expand Up @@ -147,4 +151,4 @@ export default function SignupForm(props) {
</p>
</div>
);
}
}
4 changes: 4 additions & 0 deletions frontend/src/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const config = {
apiServer: 'http://34.209.31.30:8080'
};
export default config;
66 changes: 48 additions & 18 deletions frontend/src/crud.js
Original file line number Diff line number Diff line change
@@ -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");
Expand All @@ -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;
Expand All @@ -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")
Expand All @@ -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");
Expand All @@ -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");
Expand All @@ -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");
Expand All @@ -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'
Expand All @@ -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");
Expand All @@ -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'
Expand All @@ -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");
Expand All @@ -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");
Expand All @@ -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");
Expand All @@ -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");
Expand All @@ -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")
Expand All @@ -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");
Expand All @@ -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");
Expand All @@ -233,4 +262,5 @@ export async function getAllCandidates() {
.catch((error) => {
console.log("Error fetching all candidates", error);
})
}
}

1 change: 1 addition & 0 deletions frontend/src/main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { createRoot } from 'react-dom/client'
import App from './App.jsx'
import './index.css'


createRoot(document.getElementById('root')).render(
<StrictMode>
<App />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
@Configuration
public class CorsConfiguration implements WebMvcConfigurer {

// TODO - move the allowedOrigins to a config file - hardcoding here is bad
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("http://localhost:5173")
.allowedOrigins("http://34.209.31.30:5173")
.allowedMethods("*")
.allowedHeaders("*")
.allowCredentials(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import org.springframework.http.HttpStatus;

@RestController
// Moved this to the parent CorsConfiguration
// @CrossOrigin(origins="http://34.209.31.30:5173")
@RequestMapping("/applications")
public class ApplicationController {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import org.springframework.http.HttpStatus;

@RestController
// Moved this to the parent CorsConfiguration
// @CrossOrigin(origins="http://34.209.31.30:5173")
@RequestMapping("/candidates")
public class CandidateController {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import org.springframework.http.HttpStatus;

@RestController
// Moved this to the parent CorsConfiguration
// @CrossOrigin(origins="http://34.209.31.30:5173")
@RequestMapping("/jobs")
public class JobController {

Expand Down Expand Up @@ -58,4 +60,4 @@ public ResponseEntity<Job> deleteJob(@PathVariable Long id) {
jobRepository.delete(job);
return ResponseEntity.noContent().build();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import org.springframework.http.HttpStatus;

@RestController
// Moved this to the parent CorsConfiguration
// @CrossOrigin(origins="http://34.209.31.30:5173")
@RequestMapping("/managers")
public class ManagerController {

Expand Down
Loading