From cec831ad1ceb25d21cd1e53d7e0fbec2180a9f6d Mon Sep 17 00:00:00 2001
From: EC2 Default User
Date: Fri, 6 Sep 2024 22:46:18 +0000
Subject: [PATCH] Major changes: talent-api * Modified CorsConfiguration to
include the AWS backend server - the value is hardcoded and really needs to
be pulled out into a config file (TODO - next Sprint)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
FrontEnd:
* ./config.js has the API Server “global” variable in it now
* crud.js, components/*Form.jsx and *List.jsx were updated to include the config.js and use the apiServer variable; hard-coded references to localhost were replaced with the apiServer variable
---
frontend/src/App.jsx | 3 +-
frontend/src/components/ApplicantForm.jsx | 12 ++--
frontend/src/components/ApplicationList.jsx | 7 +-
frontend/src/components/SignupForm.jsx | 10 ++-
frontend/src/config.js | 4 ++
frontend/src/crud.js | 66 ++++++++++++++-----
frontend/src/main.jsx | 1 +
.../example/talent_api/CorsConfiguration.java | 2 +
.../applications/ApplicationController.java | 2 +
.../candidates/CandidateController.java | 2 +
.../talent_api/jobs/JobController.java | 4 +-
.../managers/ManagerController.java | 2 +
.../talent_api/users/UserController.java | 5 +-
.../src/main/resources/application.properties | 8 ++-
14 files changed, 96 insertions(+), 32 deletions(-)
create mode 100644 frontend/src/config.js
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(
diff --git a/talent-api/src/main/java/com/example/talent_api/CorsConfiguration.java b/talent-api/src/main/java/com/example/talent_api/CorsConfiguration.java
index ed0b18d..3d6866d 100644
--- a/talent-api/src/main/java/com/example/talent_api/CorsConfiguration.java
+++ b/talent-api/src/main/java/com/example/talent_api/CorsConfiguration.java
@@ -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);
diff --git a/talent-api/src/main/java/com/example/talent_api/applications/ApplicationController.java b/talent-api/src/main/java/com/example/talent_api/applications/ApplicationController.java
index 0846f6a..4228efe 100644
--- a/talent-api/src/main/java/com/example/talent_api/applications/ApplicationController.java
+++ b/talent-api/src/main/java/com/example/talent_api/applications/ApplicationController.java
@@ -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 {
diff --git a/talent-api/src/main/java/com/example/talent_api/candidates/CandidateController.java b/talent-api/src/main/java/com/example/talent_api/candidates/CandidateController.java
index 5bbfd78..50a20f3 100644
--- a/talent-api/src/main/java/com/example/talent_api/candidates/CandidateController.java
+++ b/talent-api/src/main/java/com/example/talent_api/candidates/CandidateController.java
@@ -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 {
diff --git a/talent-api/src/main/java/com/example/talent_api/jobs/JobController.java b/talent-api/src/main/java/com/example/talent_api/jobs/JobController.java
index bdc00d9..e324e10 100644
--- a/talent-api/src/main/java/com/example/talent_api/jobs/JobController.java
+++ b/talent-api/src/main/java/com/example/talent_api/jobs/JobController.java
@@ -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 {
@@ -58,4 +60,4 @@ public ResponseEntity deleteJob(@PathVariable Long id) {
jobRepository.delete(job);
return ResponseEntity.noContent().build();
}
-}
\ No newline at end of file
+}
diff --git a/talent-api/src/main/java/com/example/talent_api/managers/ManagerController.java b/talent-api/src/main/java/com/example/talent_api/managers/ManagerController.java
index ffd7ee1..328a4c7 100644
--- a/talent-api/src/main/java/com/example/talent_api/managers/ManagerController.java
+++ b/talent-api/src/main/java/com/example/talent_api/managers/ManagerController.java
@@ -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 {
diff --git a/talent-api/src/main/java/com/example/talent_api/users/UserController.java b/talent-api/src/main/java/com/example/talent_api/users/UserController.java
index b098d70..250a1fe 100644
--- a/talent-api/src/main/java/com/example/talent_api/users/UserController.java
+++ b/talent-api/src/main/java/com/example/talent_api/users/UserController.java
@@ -11,6 +11,8 @@
import org.springframework.http.HttpStatus;
@RestController
+// Moved this to the parent CorsConfiguration
+// @CrossOrigin(origins="http://34.209.31.30:5173")
@RequestMapping("/users")
public class UserController {
@@ -21,6 +23,7 @@ public class UserController {
private UserDataService userService;
@GetMapping
+ @CrossOrigin(origins="http://34.209.31.30:5173")
public List getUsers() {
return userRepository.findAll();
}
@@ -63,4 +66,4 @@ public ResponseEntity deleteUser(@PathVariable Long id) {
userRepository.delete(user);
return ResponseEntity.noContent().build();
}
-}
\ No newline at end of file
+}
diff --git a/talent-api/src/main/resources/application.properties b/talent-api/src/main/resources/application.properties
index 89a6a0d..6831c31 100644
--- a/talent-api/src/main/resources/application.properties
+++ b/talent-api/src/main/resources/application.properties
@@ -1,5 +1,7 @@
spring.application.name=talent-api
-spring.datasource.url=jdbc:mysql://localhost:3306/talent
-spring.datasource.username=dbuser
-spring.datasource.password=passpass
+spring.datasource.url=jdbc:mysql://100.20.166.32:3306/talent
+spring.datasource.username=admin
+spring.datasource.password=passw0rd
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
+spring.jpa.database-platform=org.hibernate.dialect.MariaDBDialect
+