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
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package app.linkedout.backend_v2.controllers;

import app.linkedout.backend_v2.models.File;
import app.linkedout.backend_v2.services.FileService;
import app.linkedout.backend_v2.services.SessionService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(path = "api/v1/files")
public class FileController {

private final FileService fileService ;
private final SessionService sessionService;
public FileController(FileService fileService, SessionService sessionService) {
this.fileService = fileService;
this.sessionService = sessionService;
}

@GetMapping("/{user_ID}/{content_type}")
public List<File> getFileByUserIdAndType(@PathVariable("user_ID") Integer user_ID, @PathVariable("content_type") String contentType) throws Exception {
return fileService.getFilesByUserIdAndType(user_ID, contentType);
}

@PostMapping
public void insertFile(@RequestBody File file) throws Exception {
int user_id = sessionService.getCurrentUserId();
fileService.insertFile(file, user_id);
}

@PutMapping()
public void updateFile(@RequestBody File file)
{
fileService.updateFile(file);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@

import app.linkedout.backend_v2.models.JobPost;
import app.linkedout.backend_v2.models.JobPostAndCompany;
import app.linkedout.backend_v2.models.Person;
import app.linkedout.backend_v2.services.JobPostService;
import org.springframework.web.bind.annotation.*;

import java.sql.Date;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -45,7 +51,15 @@ public List<JobPostAndCompany> getFilteredJobPosts(@RequestBody Map<String, Stri
String position = filterParams.get("position");
String workplace = filterParams.get("workplace");
String location = filterParams.get("location");
return jobPostService.filterJobPosts(content, job_title, position, workplace, location);
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
Date start_date, end_date;
try {
start_date = new Date(dateFormat.parse(filterParams.get("start_date")).getTime());
end_date = new Date(dateFormat.parse(filterParams.get("end_date")).getTime());
} catch (ParseException e) {
throw new RuntimeException(e);
}
return jobPostService.filterJobPosts(content, job_title, position, workplace, location, start_date, end_date);
}

@GetMapping("/applied/{user_ID}")
Expand All @@ -57,4 +71,9 @@ public List<JobPostAndCompany> getAppliedJobs(@PathVariable("user_ID") Integer u
public void applyForJob(@PathVariable("user_ID") Integer user_ID,@PathVariable("post_ID") Integer post_ID) {
jobPostService.apply(user_ID, post_ID);
}

@GetMapping("/applicants/{post_ID}")
public List<Person> getApplicantsOfPost(@PathVariable("post_ID") Integer post_ID) {
return jobPostService.getApplicantsOfPost(post_ID);
}
}
11 changes: 11 additions & 0 deletions backend/src/main/java/app/linkedout/backend_v2/dao/FileDao.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package app.linkedout.backend_v2.dao;

import app.linkedout.backend_v2.models.File;

import java.util.List;

public interface FileDao {
List<File> getFilesByUserIdAndType(int user_id, String content_type);
int insertFile(File file, int user_id);
int updateFile(File file);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import app.linkedout.backend_v2.models.JobPost;
import app.linkedout.backend_v2.models.JobPostAndCompany;
import app.linkedout.backend_v2.models.Person;

import java.sql.Date;
import java.util.List;
import java.util.Optional;

Expand All @@ -11,7 +13,8 @@ public interface JobPostDao {
int insertJobPost(JobPost jobPost);
int deleteJobPost(int id);
Optional<JobPostAndCompany> getJobPostDetails(int id);
List<JobPostAndCompany> filterJobs(String content, String job_title, String position, String workplace, String location);
List<JobPostAndCompany> filterJobs(String content, String job_title, String position, String workplace, String location, Date start_date, Date end_date);
List<JobPostAndCompany> getAppliedJobs(int id);
int apply(int user_id, int post_id);
List<Person> getApplicantsOfPost(int post_id);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package app.linkedout.backend_v2.models;

import java.sql.Date;

public record File (Integer file_id, Integer user_id, String content, String fileName, String fileType, Date uploadTime, String contentType) {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package app.linkedout.backend_v2.repositories;

import app.linkedout.backend_v2.dao.ExperienceDao;
import app.linkedout.backend_v2.dao.FileDao;
import app.linkedout.backend_v2.models.Company;
import app.linkedout.backend_v2.models.Experience;
import app.linkedout.backend_v2.models.ExperienceAndCompany;
import app.linkedout.backend_v2.models.File;
import app.linkedout.backend_v2.repositories.rowMappers.CompanyRowMapper;
import app.linkedout.backend_v2.repositories.rowMappers.ExperienceAndCompanyRowMapper;
import app.linkedout.backend_v2.repositories.rowMappers.ExperienceRowMapper;
import app.linkedout.backend_v2.repositories.rowMappers.FileRowMapper;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public class FileRepository implements FileDao {

private final JdbcTemplate jdbcTemplate;

public FileRepository(JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
}

@Override
public List<File> getFilesByUserIdAndType(int user_id, String content_type) {
var sql = """
SELECT *
FROM File
WHERE user_id = ? AND contentType = ?
""";
return jdbcTemplate.query(sql, new FileRowMapper(), user_id, content_type);
}

@Override
public int insertFile(File file, int user_id) {
var sql = """
INSERT INTO File (file_id, user_id, content, fileName, fileType, uploadTime, contentType)
VALUES (?, ?, ?, ?, ?, ?, ?);
""";
return jdbcTemplate.update(sql, file.file_id(), user_id, file.content(), file.fileName(), file.fileType(), file.uploadTime(), file.contentType());

}

@Override
public int updateFile(File file)
{
var sql = """
UPDATE File
SET file_id = ?, content = ?, fileName = ?, fileType = ?, uploadTime = ?, contentType = ?
WHERE user_id = ? AND content_type = ?;
""";
return jdbcTemplate.update(sql, file.file_id(), file.content(), file.fileName(), file.fileType(), file.uploadTime(), file.contentType(), file.user_id(), file.contentType());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
import app.linkedout.backend_v2.dao.JobPostDao;
import app.linkedout.backend_v2.models.JobPost;
import app.linkedout.backend_v2.models.JobPostAndCompany;
import app.linkedout.backend_v2.models.Person;
import app.linkedout.backend_v2.repositories.rowMappers.JobPostAndCompanyRowMapper;
import app.linkedout.backend_v2.repositories.rowMappers.JobPostRowMapper;
import app.linkedout.backend_v2.repositories.rowMappers.PersonRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.SqlParameterValue;
import org.springframework.stereotype.Repository;


import java.sql.Types;
import java.sql.Date;
import java.util.List;
import java.util.Optional;

Expand Down Expand Up @@ -69,19 +72,20 @@ public Optional<JobPostAndCompany> getJobPostDetails(int id) {
}

@Override
public List<JobPostAndCompany> filterJobs(String content, String job_title, String position, String workplace, String location) {
public List<JobPostAndCompany> filterJobs(String content, String job_title, String position, String workplace, String location, Date start_date, Date end_date) {
var sql = """
SELECT *
FROM JobPost AS jp JOIN Company AS c ON jp.company_ID = c.company_ID
WHERE (content LIKE CONCAT('%', ?, '%') OR job_title LIKE CONCAT('%', ?, '%') OR name LIKE CONCAT('%', ?, '%')) AND position LIKE CONCAT('%', ?, '%') AND workplace LIKE CONCAT('%', ?, '%') AND location LIKE CONCAT('%', ?, '%') AND date > CURRENT_DATE;
WHERE (content LIKE CONCAT('%', ?, '%') OR job_title LIKE CONCAT('%', ?, '%') OR name LIKE CONCAT('%', ?, '%')) AND position LIKE CONCAT('%', ?, '%') AND workplace LIKE CONCAT('%', ?, '%') AND location LIKE CONCAT('%', ?, '%') AND (date BETWEEN ? AND ?);
""";
//return jdbcTemplate.query(sql, new JobPostAndCompanyRowMapper(), content, job_title, content, position, workplace, location);
return jdbcTemplate.query(sql, new JobPostAndCompanyRowMapper(), new SqlParameterValue(Types.VARCHAR, content),
new SqlParameterValue(Types.VARCHAR, job_title),
new SqlParameterValue(Types.VARCHAR, content),
new SqlParameterValue(Types.VARCHAR, position),
new SqlParameterValue(Types.VARCHAR, workplace),
new SqlParameterValue(Types.VARCHAR, location));
new SqlParameterValue(Types.VARCHAR, location),
new SqlParameterValue(Types.DATE, start_date),
new SqlParameterValue(Types.DATE, end_date));
}

@Override
Expand All @@ -102,4 +106,14 @@ INSERT INTO Applies (user_ID, post_ID)
""";
return jdbcTemplate.update(sql, user_id, post_id);
}

@Override
public List<Person> getApplicantsOfPost(int post_id) {
var sql = """
SELECT *
FROM Person
WHERE id IN (SELECT user_ID FROM Applies WHERE post_ID = ?)
""";
return jdbcTemplate.query(sql, new PersonRowMapper(), post_id);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package app.linkedout.backend_v2.repositories.rowMappers;

import app.linkedout.backend_v2.models.File;

import org.springframework.jdbc.core.RowMapper;

import java.sql.ResultSet;
import java.sql.SQLException;

public class FileRowMapper implements RowMapper<File> {
@Override
public File mapRow(ResultSet rs, int rowNum) throws SQLException {
return new File(
rs.getInt("file_id"),
rs.getInt("user_id"),
rs.getString("content"),
rs.getString("fileName"),
rs.getString("fileType"),
rs.getDate("uploadTime"),
rs.getString("contentType")
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package app.linkedout.backend_v2.services;

import app.linkedout.backend_v2.dao.FileDao;
import app.linkedout.backend_v2.dao.InterestDao;
import app.linkedout.backend_v2.models.File;
import app.linkedout.backend_v2.models.Interest;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FileService {
private final FileDao fileDao;

public FileService(FileDao fileDao) {
this.fileDao = fileDao;
}

public List<File> getFilesByUserIdAndType(int user_id, String content_type) {
return fileDao.getFilesByUserIdAndType(user_id, content_type);
}
public int insertFile(File file, int user_id) {
return fileDao.insertFile(file, user_id);
}
public int updateFile(File file)
{
return fileDao.updateFile(file);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import app.linkedout.backend_v2.models.CareerExpert;
import app.linkedout.backend_v2.models.JobPost;
import app.linkedout.backend_v2.models.JobPostAndCompany;
import app.linkedout.backend_v2.models.Person;
import org.springframework.stereotype.Service;

import java.sql.Date;
import java.util.List;

import javax.el.PropertyNotFoundException;
Expand Down Expand Up @@ -35,8 +37,8 @@ public JobPostAndCompany getJobPostDetails(int id) {
return jobPostDao.getJobPostDetails(id).orElseThrow(PropertyNotFoundException::new);
}

public List<JobPostAndCompany> filterJobPosts(String content, String job_title, String position, String workplace, String location) {
return jobPostDao.filterJobs(content, job_title, position, workplace, location);
public List<JobPostAndCompany> filterJobPosts(String content, String job_title, String position, String workplace, String location, Date start_date, Date end_date) {
return jobPostDao.filterJobs(content, job_title, position, workplace, location, start_date, end_date);
}

public void apply(int user_id, int post_id) {
Expand All @@ -47,4 +49,7 @@ public List<JobPostAndCompany> getAppliedJobs(int id) {
return jobPostDao.getAppliedJobs(id);
}

public List<Person> getApplicantsOfPost(int post_id) {
return jobPostDao.getApplicantsOfPost(post_id);
}
}
13 changes: 13 additions & 0 deletions backend/src/main/resources/db/migration/R__Jobposts.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@ CREATE TABLE IF NOT EXISTS Company (
company_picture bytea,
PRIMARY KEY (company_ID)
);

CREATE TABLE IF NOT EXISTS File (
file_ID BIGSERIAL NOT NULL,
user_ID BIGSERIAL NOT NULL,
content VARCHAR,
fileName VARCHAR,
fileType VARCHAR,
uploadTime DATE,
contentType VARCHAR,
PRIMARY KEY (file_ID),
FOREIGN KEY (user_ID) REFERENCES Person(id)
);

CREATE TABLE IF NOT EXISTS Experience (
exp_ID BIGSERIAL NOT NULL,
user_ID BIGSERIAL NOT NULL,
Expand Down