Skip to content

Commit

Permalink
add: add new routes for contract and contract-modifications
Browse files Browse the repository at this point in the history
  • Loading branch information
fabian-urner committed May 28, 2024
1 parent f610544 commit e8dbf70
Show file tree
Hide file tree
Showing 34 changed files with 317 additions and 69 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package dev.urner.volodb.converter;

import dev.urner.volodb.entity.AddressStatusNotFoundException;
import dev.urner.volodb.entity.Enums.AddressStatus;
import dev.urner.volodb.exception.AddressStatusNotFoundException;
import jakarta.persistence.AttributeConverter;

public class AddressStatusConverter implements AttributeConverter<AddressStatus, Integer> {
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/dev/urner/volodb/dao/ContractModificationDAO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package dev.urner.volodb.dao;

import java.util.List;

import org.springframework.data.repository.ListCrudRepository;
import org.springframework.stereotype.Repository;

import dev.urner.volodb.entity.ContractModification;

@Repository
public interface ContractModificationDAO extends ListCrudRepository<ContractModification, Integer> {

List<ContractModification> findAll();

ContractModification findById(int id);

List<ContractModification> findAllByContractId(int contractId);

}
17 changes: 17 additions & 0 deletions src/main/java/dev/urner/volodb/dao/ContractSalaryDAO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package dev.urner.volodb.dao;

import java.util.List;

import org.springframework.data.repository.ListCrudRepository;
import org.springframework.stereotype.Repository;

import dev.urner.volodb.entity.Salary;

@Repository
public interface ContractSalaryDAO extends ListCrudRepository<Salary, Integer> {

List<Salary> findAll();

Salary findById(int id);

}
59 changes: 59 additions & 0 deletions src/main/java/dev/urner/volodb/entity/ContractModification.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package dev.urner.volodb.entity;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Map;

import dev.urner.volodb.converter.HashMapConverter;

import jakarta.persistence.Column;
import jakarta.persistence.Convert;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;

@Entity
@Table(name = "ContractModification")
@Getter
@Setter
@RequiredArgsConstructor
public class ContractModification {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private int id;

@Column(name = "timestamp")
private LocalDateTime timestamp;

// status (ContractModificationStatus) -> FK
@ManyToOne
@JoinColumn(name = "status")
private ContractModificationStatus status;

// contract -> FK
@Column(name = "contract")
private int contractId;

// type (contractModificationType) -> FK
@ManyToOne
@JoinColumn(name = "type")
private ContractModificationType type;

// into_force_from (Date)
@Column
private LocalDate intoForceFrom;

// value (JSON)
@Column
private String value;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package dev.urner.volodb.entity;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;

@Entity
@Table(name = "ContractModificationStatus")
@Getter
@Setter
@RequiredArgsConstructor
public class ContractModificationStatus {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private int id;

@Column
private String name;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package dev.urner.volodb.entity;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;

@Entity
@Table(name = "ContractModificationType")
@Getter
@Setter
@RequiredArgsConstructor
public class ContractModificationType {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private int id;

@Column
private String name;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;

import dev.urner.volodb.exception.ProjectInvalidFormatException;
import dev.urner.volodb.service.CountryService;

public class ProjectDeserializer extends StdDeserializer {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;

import dev.urner.volodb.entity.Enums.OngoingLegalProceedingsState;
import dev.urner.volodb.exception.VolunteerInvalidFormatException;
import dev.urner.volodb.service.CountryService;
import dev.urner.volodb.service.HealthInsuranceService;
import dev.urner.volodb.service.ReligionService;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.urner.volodb.entity;
package dev.urner.volodb.exception;

public class AddressInvalidFormatException extends RuntimeException {
public AddressInvalidFormatException(String message) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.urner.volodb.entity;
package dev.urner.volodb.exception;

public class AddressStatusNotFoundException extends RuntimeException {
public AddressStatusNotFoundException(String message) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.urner.volodb.entity;
package dev.urner.volodb.exception;

public class ContactTypeNotFoundException extends RuntimeException {
public ContactTypeNotFoundException(String message) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package dev.urner.volodb.exception;

public class ContractModificationNotFoundException extends RuntimeException {
public ContractModificationNotFoundException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package dev.urner.volodb.exception;

public class ContractNotFoundException extends RuntimeException {
public ContractNotFoundException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.urner.volodb.entity;
package dev.urner.volodb.exception;

public class CountryNotFoundException extends RuntimeException {
public CountryNotFoundException(String message) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.urner.volodb.entity;
package dev.urner.volodb.exception;

public class ProjectInvalidFormatException extends RuntimeException {
public ProjectInvalidFormatException(String message) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.urner.volodb.entity;
package dev.urner.volodb.exception;

public class ProjectNotFoundException extends RuntimeException {
public ProjectNotFoundException(String message) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.urner.volodb.entity;
package dev.urner.volodb.exception;

public class UserNotFoundException extends RuntimeException {
public UserNotFoundException(String message) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.urner.volodb.entity;
package dev.urner.volodb.exception;

public class VolunteerInvalidFormatException extends RuntimeException {
public VolunteerInvalidFormatException(String message) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.urner.volodb.entity;
package dev.urner.volodb.exception;

public class VolunteerNotFoundException extends RuntimeException {
public VolunteerNotFoundException(String message) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.urner.volodb.entity;
package dev.urner.volodb.exception;

public class VolunteerNoteInvalidFormatException extends RuntimeException {
public VolunteerNoteInvalidFormatException(String message) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.urner.volodb.entity;
package dev.urner.volodb.exception;

public class VolunteerNoteNotFoundException extends RuntimeException {
public VolunteerNoteNotFoundException(String message) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.auth0.jwt.exceptions.TokenExpiredException;

import dev.urner.volodb.entity.User;
import dev.urner.volodb.entity.UserNotFoundException;
import dev.urner.volodb.exception.UserNotFoundException;
import dev.urner.volodb.model.LoginRequest;
import dev.urner.volodb.model.LoginResponse;
import dev.urner.volodb.security.JwtIssuer;
Expand Down
32 changes: 0 additions & 32 deletions src/main/java/dev/urner/volodb/rest/ContractRestController.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import dev.urner.volodb.entity.CountryNotFoundException;
import dev.urner.volodb.entity.Project;
import dev.urner.volodb.entity.ProjectInvalidFormatException;
import dev.urner.volodb.entity.ProjectNotFoundException;
import dev.urner.volodb.entity.VolunteerInvalidFormatException;
import dev.urner.volodb.exception.CountryNotFoundException;
import dev.urner.volodb.exception.ProjectInvalidFormatException;
import dev.urner.volodb.exception.ProjectNotFoundException;
import dev.urner.volodb.exception.VolunteerInvalidFormatException;
import dev.urner.volodb.service.ProjectService;
import lombok.RequiredArgsConstructor;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import org.springframework.web.bind.annotation.RestController;

import dev.urner.volodb.entity.User;
import dev.urner.volodb.entity.UserNotFoundException;
import dev.urner.volodb.exception.UserNotFoundException;
import dev.urner.volodb.security.UserPrincipal;
import dev.urner.volodb.service.UserService;
import lombok.RequiredArgsConstructor;
Expand Down
30 changes: 26 additions & 4 deletions src/main/java/dev/urner/volodb/rest/VolunteerRestController.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@

import dev.urner.volodb.entity.Address;
import dev.urner.volodb.entity.Contact;
import dev.urner.volodb.entity.Contract;
import dev.urner.volodb.entity.ContractModification;
import dev.urner.volodb.entity.Volunteer;
import dev.urner.volodb.entity.VolunteerDocument;
import dev.urner.volodb.entity.VolunteerInvalidFormatException;
import dev.urner.volodb.entity.VolunteerNotFoundException;
import dev.urner.volodb.entity.VolunteerNote;
import dev.urner.volodb.exception.VolunteerInvalidFormatException;
import dev.urner.volodb.exception.VolunteerNotFoundException;
import dev.urner.volodb.security.UserPrincipal;
import dev.urner.volodb.service.AddressService;
import dev.urner.volodb.service.ContactService;
import dev.urner.volodb.service.ContractService;
import dev.urner.volodb.service.VolunteerDocumentService;
import dev.urner.volodb.service.VolunteerNoteService;
import dev.urner.volodb.service.VolunteerService;
Expand All @@ -29,8 +32,6 @@
import java.util.Map;
import java.util.List;
import java.time.LocalDateTime;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

@RestController
@RequestMapping("/volunteers")
Expand All @@ -42,6 +43,7 @@ public class VolunteerRestController {
private final VolunteerDocumentService volunteerDocumentService;
private final ContactService contactService;
private final AddressService addressService;
private final ContractService contractService;

// expose "/volunteers" and return a list of volunteers
@GetMapping
Expand Down Expand Up @@ -323,4 +325,24 @@ public String deleteByAddressId(@PathVariable int volunteerId, @PathVariable int
return "Address with Id '" + addressId + "' deleted.";
}

// **********************************
// Contracts
// **********************************

// GET all contacts BY VoloID
@GetMapping("/{volunteerId}/contracts")
public List<Contract> getAllContractsFromVolo(@PathVariable int volunteerId) {
return contractService.findAllByVolunteerId(volunteerId);
}

@GetMapping("/{volunteerId}/contracts/relevant")
public Contract getRelevantContractFromVolo(@PathVariable int volunteerId) {
return contractService.findRelevantContractByVolunteerId(volunteerId);
}

@GetMapping("/{volunteerId}/contracts/{contractId}/modifications")
public List<ContractModification> getAllContractModsFromVolo(@PathVariable int volunteerId,
@PathVariable int contractId) {
return contractService.findModifications(volunteerId, contractId);
}
}
Loading

0 comments on commit e8dbf70

Please sign in to comment.