Skip to content

Commit

Permalink
Merge pull request #3 from Neo-Zenith/server-dev
Browse files Browse the repository at this point in the history
Added unit test
  • Loading branch information
RowenTey committed Apr 11, 2024
2 parents 1856e93 + 2f9d675 commit a82f74c
Show file tree
Hide file tree
Showing 32 changed files with 411 additions and 198 deletions.
Binary file removed extension/assets/icon.png
Binary file not shown.
Binary file added extension/assets/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 8 additions & 8 deletions extension/js/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ function createUpdateBtn(parentElement, formContainer, application) {
getToken()
.then((token) => {
return fetch(
`http://172.171.242.107:8080/api/v1/applications/${application.id}`,
`http://172.171.242.107:80/api/v1/applications/${application.id}`,
{
method: "PUT",
headers: {
Expand All @@ -173,9 +173,9 @@ function createUpdateBtn(parentElement, formContainer, application) {
submitButton.innerText = "Update";
submitButton.disabled = false;
displayToast("Application updated successfully");
// setTimeout(() => {
// window.open("../templates/popup.html", "_self");
// }, 1000);
setTimeout(() => {
window.open("../templates/popup.html", "_self");
}, 1000);
})
.catch((error) => {
submitButton.classList.remove("loading");
Expand All @@ -200,7 +200,7 @@ function createDeleteBtn(parentElement, application) {
getToken()
.then((token) => {
return fetch(
`http://172.171.242.107:8080/api/v1/applications/${application.id}`,
`http://172.171.242.107:80/api/v1/applications/${application.id}`,
{
method: "DELETE",
headers: {
Expand All @@ -215,9 +215,9 @@ function createDeleteBtn(parentElement, application) {
deleteBtn.innerText = "Delete";
deleteBtn.disabled = false;
displayToast("Application deleted successfully");
// setTimeout(() => {
// window.open("../templates/popup.html", "_self");
// }, 1000);
setTimeout(() => {
window.open("../templates/popup.html", "_self");
}, 1000);
})
.catch((error) => {
deleteBtn.classList.remove("loading");
Expand Down
2 changes: 1 addition & 1 deletion extension/js/applications.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ document.addEventListener("DOMContentLoaded", function () {
console.log("payload:", payload);

return fetch(
`http://172.171.242.107:8080/api/v1/applications?userId=${payload.userId}`,
`http://172.171.242.107:80/api/v1/applications?userId=${payload.userId}`,
{
headers: {
Authorization: `Bearer ${token}`,
Expand Down
31 changes: 1 addition & 30 deletions extension/js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
console.log("[Extension] Saving job...");
getToken()
.then((token) => {
fetch("http://172.171.242.107:8080/api/v1/applications", {
fetch("http://172.171.242.107:80/api/v1/applications", {
method: "POST",
headers: {
"Content-Type": "application/json",
Expand All @@ -28,35 +28,6 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
// Will respond asynchronously.
return true;
}
// else if (request.type === "UPDATE_JOB") {
// console.log("[Extension] Updating job...");
// getToken()
// .then((token) => {
// fetch("http://172.171.242.107:8080/api/v1/applications", {
// method: "PATCH",
// headers: {
// "Content-Type": "application/json",
// Authorization: `Bearer ${token}`,
// },
// body: JSON.stringify(request.payload),
// })
// .then((response) => response.json())
// .then((data) => {
// console.log(data);
// sendResponse({ success: true });
// })
// .catch((error) => {
// throw error;
// });
// })
// .catch((error) => {
// console.log(error);
// sendResponse({ success: false });
// });

// // Will respond asynchronously.
// return true;
// }
});

async function getToken() {
Expand Down
23 changes: 5 additions & 18 deletions extension/js/content.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
let isLoggedIn = false;

(async () => {
console.log("[Extension] LinkedIn Job Saver is active!");
console.log("[Extension] JobWise is active!");

getToken()
.then(() => {
displayToast("LinkedIn Job Saver is active!");
displayToast("JobWise is active!");
isLoggedIn = true;
})
.catch(() => {
displayToast("Please login to save jobs!");
displayToast("Please login to save jobs!", "red");
});
})();

document.addEventListener("click", async function (event) {
console.log("[Extension] Clicked", isApply(event));
if (isLoggedIn && isApply(event)) {
console.log("[Extension] Clicked on apply button!");
displayToast("Saving job application...");
const jobDetails = await extractJobDetails();
const payload = {
...jobDetails,
Expand All @@ -39,21 +40,6 @@ document.addEventListener("click", async function (event) {
}
);
}
// else if (isSubmitApplication(event)) {
// payload = { status: "Applied" };
// console.log("[Extension] Updating job...");
// chrome.runtime.sendMessage(
// { type: "UPDATE_JOB", payload: payload },
// function (response) {
// if (response.success) {
// console.log("[Extension] Job updated successfully");
// displayToast("Job application updated!");
// } else {
// console.log("[Extension] Failed to update job");
// }
// }
// );
// }
});

async function getToken() {
Expand Down Expand Up @@ -106,6 +92,7 @@ function displayToast(message, color = "rgba(0, 86, 179, 0.7)") {
// Fade out animation after 3 seconds
setTimeout(() => {
modalDiv.style.opacity = "0";
modalDiv.remove();
}, 3000);
}

Expand Down
2 changes: 1 addition & 1 deletion extension/js/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ document.getElementById("loginForm").addEventListener("submit", (event) => {
btn.innerText = "";
btn.classList.add("loading");

fetch("http://172.171.242.107:8080/api/v1/auth/login", {
fetch("http://172.171.242.107:80/api/v1/auth/login", {
method: "POST",
headers: {
"Content-Type": "application/json",
Expand Down
7 changes: 6 additions & 1 deletion extension/manifest.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
{
"manifest_version": 3,
"name": "Job Application Tracker",
"name": "JobWise",
"version": "1.0",
"description": "This extension will help you track your job applications on LinkedIn.",
"permissions": ["activeTab", "alarms", "storage", "notifications"],
"icons": {
"16": "assets/logo.png",
"48": "assets/logo.png",
"128": "assets/logo.png"
},
"background": {
"service_worker": "js/background.js"
},
Expand Down
2 changes: 1 addition & 1 deletion extension/templates/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<body id="root">
<div class="container" id="container">
<h1>Job Application Tracker</h1>
<h1>JobWise</h1>
<p id="username"></p>
<div id="actionBtns" class="col"></div>
</div>
Expand Down
5 changes: 0 additions & 5 deletions server/.env

This file was deleted.

5 changes: 5 additions & 0 deletions server/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
DB_URL=
DB_USERNAME=
DB_PASSWORD=
GEMINI_API_KEY=
JWT_SECRET=
1 change: 1 addition & 0 deletions server/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ resumes/
resume.*
*.pem
*.env
cmd.txt

!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
Expand Down
4 changes: 2 additions & 2 deletions server/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# Start with a base image containing Java runtime
FROM openjdk:17-jdk-alpine

# Make port 8080 available to the world outside this container
Expand All @@ -11,4 +10,5 @@ ARG JAR_FILE=target/application-tracker-server-0.0.1-SNAPSHOT.jar
ADD ${JAR_FILE} application-tracker-server-0.0.1-SNAPSHOT.jar

# Run the jar file
ENTRYPOINT ["java","-jar","/application-tracker-server-0.0.1-SNAPSHOT.jar"]
ENTRYPOINT ["java","-jar","/application-tracker-server-0.0.1-SNAPSHOT.jar"]

13 changes: 13 additions & 0 deletions server/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Nginx setup

1. Install nginx

```bash
sudo apt install
```

2. Go in to 'etc/nginx/conf.d' directory

```bash
cd ~/etc/nginx/conf.d
```
27 changes: 0 additions & 27 deletions server/TESTS.md

This file was deleted.

1 change: 0 additions & 1 deletion server/cmd.txt

This file was deleted.

21 changes: 21 additions & 0 deletions server/nginx.default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Define upstream block with the two web servers
upstream backend_servers {
server 172.171.242.107:8080; # IP address and port of the first web server
server 20.239.172.33:8080; # IP address and port of the second web server
}

# HTTP server block
server {
listen 80; # Listen on port 80

# Define location block to handle requests
location / {
proxy_pass http://backend_servers; # Pass requests to the upstream servers
proxy_redirect off; # Disable automatic redirects
proxy_set_header Host $host; # Set the Host header to the original request's host
proxy_set_header X-Real-IP $remote_addr; # Set the X-Real-IP header to the client's IP address
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; # Set the X-Forwarded-For header to include the client's IP address
proxy_set_header X-Forwarded-Proto $scheme; # Set the X-Forwarded-Proto header to the original request's scheme (HTTP or HTTPS)
}
}

7 changes: 3 additions & 4 deletions server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,10 @@
<scope>test</scope>
</dependency>

<!-- Testing -->
<!-- Spring Security Test -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.example.applicationtrackerserver;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
public class ApplicationTrackerServerApplication {

public static void main(String[] args) {
SpringApplication.run(ApplicationTrackerServerApplication.class, args);
}
Expand All @@ -20,5 +20,4 @@ public String sayHello(jakarta.servlet.http.HttpServletRequest request) {
return "Hello, " + ip + "!";
}
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.applicationtrackerserver.controllers;

import com.example.applicationtrackerserver.enums.ApplicationStatus;
import com.example.applicationtrackerserver.exceptions.ApplicationExceptions.ApplicationNotFoundException;
import com.example.applicationtrackerserver.exceptions.UserExceptions.UserNotFoundException;
import com.example.applicationtrackerserver.models.Application;
Expand Down Expand Up @@ -71,11 +72,11 @@ public List<Application> getApplications(
@RequestParam(value = "userId", required = false) Long userId,
@RequestParam(value = "status", required = false) String status) throws UserNotFoundException {
if (userId != null && status != null) {
return applicationService.getApplicationsByUserIdAndStatus(userId, status);
return applicationService.getApplicationsByUserIdAndStatus(userId, ApplicationStatus.fromString(status));
} else if (userId != null) {
return applicationService.getApplicationsByUserId(userId);
} else if (status != null) {
return applicationService.getApplicationsByStatus(status);
return applicationService.getApplicationsByStatus(ApplicationStatus.fromString(status));
}
return applicationService.getAllApplications();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.springframework.stereotype.Repository;

import com.example.applicationtrackerserver.enums.ApplicationStatus;
import com.example.applicationtrackerserver.models.Application;
import com.example.applicationtrackerserver.models.User;

Expand All @@ -18,9 +19,9 @@
public interface ApplicationRepository extends JpaRepository<Application, Long> {
List<Application> findByUser(User user);

List<Application> findByStatus(String status);
List<Application> findByStatus(ApplicationStatus status);

List<Application> findByUserAndStatus(User user, String status);
List<Application> findByUserAndStatus(User user, ApplicationStatus status);

public interface DateCount {
LocalDate getDate();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.applicationtrackerserver.services;

import com.example.applicationtrackerserver.enums.ApplicationStatus;
import com.example.applicationtrackerserver.exceptions.ApplicationExceptions.ApplicationNotFoundException;
import com.example.applicationtrackerserver.exceptions.UserExceptions.UserNotFoundException;
import com.example.applicationtrackerserver.models.Application;
Expand Down Expand Up @@ -41,11 +42,12 @@ public Application getApplicationById(Long id) throws ApplicationNotFoundExcepti
.orElseThrow(() -> new ApplicationNotFoundException("Application wtih ID " + id + " not found"));
}

public List<Application> getApplicationsByStatus(String status) {
public List<Application> getApplicationsByStatus(ApplicationStatus status) {
return applicationRepository.findByStatus(status);
}

public List<Application> getApplicationsByUserIdAndStatus(long userId, String status) throws UserNotFoundException {
public List<Application> getApplicationsByUserIdAndStatus(long userId, ApplicationStatus status)
throws UserNotFoundException {
User user = userService.getUserById(userId);
return applicationRepository.findByUserAndStatus(user, status);
}
Expand Down
Loading

0 comments on commit a82f74c

Please sign in to comment.