Skip to content

Development: Add basic server structure for job module #74

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 25, 2025
Merged
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
5 changes: 0 additions & 5 deletions src/main/java/de/tum/cit/aet/job/api/SomeController.java

This file was deleted.

20 changes: 20 additions & 0 deletions src/main/java/de/tum/cit/aet/job/dto/JobCardDTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package de.tum.cit.aet.job.dto;

import com.fasterxml.jackson.annotation.JsonInclude;
import de.tum.cit.aet.job.constants.State;
import java.time.Instant;
import java.util.UUID;

@JsonInclude(JsonInclude.Include.NON_EMPTY)
public record JobCardDTO(
UUID id,
String title,
String fieldOfStudies,
String location,
UUID professorId,
int workload,
Instant startDate,
String description,
State state,
Instant createdAt
) {}
33 changes: 33 additions & 0 deletions src/main/java/de/tum/cit/aet/job/dto/JobDetailDTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package de.tum.cit.aet.job.dto;

import com.fasterxml.jackson.annotation.JsonInclude;
import java.time.Instant;
import java.util.UUID;

@JsonInclude(JsonInclude.Include.NON_EMPTY)
public record JobDetailDTO(
String title,
String researchArea,
String fieldOfStudies,
UUID professorId,
String location,
Instant startDate,
Instant applicationDeadline,
String employmentType,
int workload,
int contractDuration,
String fundingType,
String description,
String tasks,
String applicationRequirements,
String qualifications,
String introduction,
String aboutUs,
String weOffer,
String contactName,
String contactEmail,
String contactPhoneNumber,
String contactWebsite
// TODO: Adjust this to a List of CustomFields
// CustomField customFields
) {}
5 changes: 5 additions & 0 deletions src/main/java/de/tum/cit/aet/job/dto/JobFormDTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package de.tum.cit.aet.job.dto;

public record JobFormDTO() {
// Will be implemented
}
22 changes: 21 additions & 1 deletion src/main/java/de/tum/cit/aet/job/repository/JobRepository.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,32 @@
package de.tum.cit.aet.job.repository;

import de.tum.cit.aet.job.constants.State;
import de.tum.cit.aet.job.domain.Job;
import de.tum.cit.aet.job.dto.JobCardDTO;
import java.util.List;
import java.util.UUID;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

/**
* Spring Data JPA repository for the {@link Job} entity.
*/
@Repository
public interface JobRepository extends JpaRepository<Job, UUID> {}
public interface JobRepository extends JpaRepository<Job, UUID> {
/**
* Finds all jobs with the given state and returns them as {@link JobCardDTO} projections.
*
* @param state the state of the jobs to filter by (e.g., OPEN, DRAFT).
* @return a list of job DTOs matching the given state.
*/
List<JobCardDTO> findAvailableJobsByState(@Param("state") State state);

/**
* Retrieves all jobs posted by a specific professor as {@link JobCardDTO} projections.
*
* @param professorId the UUID of the professor (user) who created the job postings.
* @return a list of job DTOs created by the given professor.
*/
List<JobCardDTO> findAllJobsByProfessor(@Param("professorId") UUID professorId);
}
102 changes: 102 additions & 0 deletions src/main/java/de/tum/cit/aet/job/service/JobService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package de.tum.cit.aet.job.service;

import de.tum.cit.aet.job.constants.State;
import de.tum.cit.aet.job.domain.Job;
import de.tum.cit.aet.job.dto.JobCardDTO;
import de.tum.cit.aet.job.dto.JobDetailDTO;
import de.tum.cit.aet.job.repository.JobRepository;
import jakarta.persistence.EntityNotFoundException;
import java.time.Instant;
import java.util.List;
import java.util.UUID;
import org.springframework.stereotype.Service;

@Service
public class JobService {

private final JobRepository jobRepository;

//private final UserRepository userRepository;

public JobService(JobRepository jobRepository) {
this.jobRepository = jobRepository;
//this.userRepository = userRepository;
}

/**
* Returns a list of open jobs (available for applications).
*
* @param filter optional filter criteria
* @param sorting optional sorting parameter
* @return list of available job cards
*/
public List<JobCardDTO> getAvailableJobs(String filter, String sorting) {
return jobRepository.findAvailableJobsByState(State.OPEN);
}

/**
* Creates a new job based on the form data.
*
* @param dto the job details used to create the job
*/
public void createJob(JobDetailDTO dto) {
Job job = new Job();
updateEntity(job, dto);
jobRepository.save(job);
}

/**
* Updates an existing job with new values.
*
* @param jobId the ID of the job to update
* @param dto the updated job details
* @return the updated job card DTO
*/
public JobCardDTO updateJob(UUID jobId, JobDetailDTO dto) {
Job job = jobRepository.findById(jobId).orElseThrow(() -> new EntityNotFoundException("Job not found with ID: " + jobId));
updateEntity(job, dto);
jobRepository.save(job);
return toDto(job);
}

/**
* Deletes a job posting by ID.
*
* @param jobId the ID of the job to delete
*/
public void deleteJob(UUID jobId) {
jobRepository.deleteById(jobId);
}

/**
* Returns all jobs created by the given professor.
*
* @param professorId the ID of the professor
* @return list of job cards created by the professor
*/
public List<JobCardDTO> getJobsByProfessor(UUID professorId) {
return jobRepository.findAllJobsByProfessor(professorId);
}

/**
* Retrieves full details of a job posting.
*
* @param jobId the ID of the job
* @return the job card DTO with detailed info
*/
public JobCardDTO getJobDetails(UUID jobId) {
Job job = jobRepository.findById(jobId).orElseThrow(() -> new EntityNotFoundException("Job not found with ID: " + jobId));
return toDto(job);
}

// === Mapping Helpers ===

private void updateEntity(Job job, JobDetailDTO dto) {
// TODO: implement field mappings
}

private JobCardDTO toDto(Job job) {
// Placeholder for the detailed implementation
return new JobCardDTO(UUID.randomUUID(), "", "", "", UUID.randomUUID(), 0, Instant.now(), "", State.OPEN, Instant.now());
}
}
5 changes: 0 additions & 5 deletions src/main/java/de/tum/cit/aet/job/service/SomeService.java

This file was deleted.

98 changes: 98 additions & 0 deletions src/main/java/de/tum/cit/aet/job/web/JobResource.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package de.tum.cit.aet.job.web;

import de.tum.cit.aet.job.dto.JobCardDTO;
import de.tum.cit.aet.job.dto.JobDetailDTO;
import de.tum.cit.aet.job.service.JobService;
import java.util.List;
import java.util.UUID;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
* REST controller for managing job postings.
* Provides endpoints for creating, updating, deleting, and retrieving jobs.
*/
@RestController
@RequestMapping("/api/jobs")
public class JobResource {

private final JobService jobService;

public JobResource(JobService jobService) {
this.jobService = jobService;
}

/**
* {@code GET /api/jobs/available} : Get all available (open) jobs.
*
* @param filter Optional filter string for job search.
* @param sorting Optional sorting parameter for job results.
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and the list of available jobs.
*/
@GetMapping("/available")
public ResponseEntity<List<JobCardDTO>> getAvailableJobs(
@RequestParam(required = false) String filter,
@RequestParam(required = false) String sorting
) {
return ResponseEntity.ok(jobService.getAvailableJobs(filter, sorting));
}

/**
* {@code POST /api/jobs} : Create a new job posting.
*
* @param jobForm the job posting data.
* @return the {@link ResponseEntity} with status {@code 201 (Created)}.
*/
@PostMapping("/create")
public ResponseEntity<Void> createJob(@RequestBody JobDetailDTO jobForm) {
jobService.createJob(jobForm);
return ResponseEntity.status(HttpStatus.CREATED).build();
}

/**
* {@code PUT /api/jobs/jobform/{jobId}} : Update an existing job posting.
*
* @param jobId the ID of the job to update.
* @param jobForm the updated job posting data.
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and the updated job.
*/
@PutMapping("/jobform/{jobId}")
public ResponseEntity<JobCardDTO> updateJob(@PathVariable UUID jobId, @RequestBody JobDetailDTO jobForm) {
return ResponseEntity.ok(jobService.updateJob(jobId, jobForm));
}

/**
* {@code DELETE /api/jobs/{jobId}} : Delete a job posting.
*
* @param jobId the ID of the job to delete.
* @return the {@link ResponseEntity} with status {@code 204 (No Content)}.
*/
@DeleteMapping("/{jobId}")
public ResponseEntity<Void> deleteJob(@PathVariable UUID jobId) {
jobService.deleteJob(jobId);
return ResponseEntity.noContent().build();
}

/**
* {@code GET /api/jobs/professor/{userId}} : Get all jobs posted by a specific professor.
*
* @param userId the ID of the professor (user).
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and the list of jobs.
*/
@GetMapping("/professor/{userId}")
public ResponseEntity<List<JobCardDTO>> getJobsByProfessor(@PathVariable UUID userId) {
return ResponseEntity.ok(jobService.getJobsByProfessor(userId));
}

/**
* {@code GET /api/jobs/{jobId}/details} : Get full details of a specific job.
*
* @param jobId the ID of the job.
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and the job details.
*/
@GetMapping("/{jobId}/details")
public ResponseEntity<JobCardDTO> getJobDetails(@PathVariable UUID jobId) {
return ResponseEntity.ok(jobService.getJobDetails(jobId));
}
}
Loading