Skip to content

Commit

Permalink
feat: sickdays patachable
Browse files Browse the repository at this point in the history
  • Loading branch information
fabian-urner committed Jul 6, 2024
1 parent ded8879 commit 70cba3e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -340,20 +340,28 @@ public String deleteByAddressId(@PathVariable int volunteerId, @PathVariable int
// Contracts
// **********************************

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

// GET relevant contract from volo BY VoloID
@GetMapping("/{volunteerId}/contracts/relevant")
public Contract getRelevantContractFromVolo(@PathVariable int volunteerId) {
return contractService.findRelevantContractByVolunteerId(volunteerId);
}

// GET all contract-modifications from BY VoloID and ContractID
@GetMapping("/{volunteerId}/contracts/{contractId}/modifications")
public List<ContractModification> getAllContractModsFromVolo(@PathVariable int volunteerId,
@PathVariable int contractId) {
return contractService.findModifications(volunteerId, contractId);
}

@PatchMapping("/{volunteerId}/contracts/{contractId}/sickdays")
public Contract patchContractSickDays(@PathVariable int volunteerId, @PathVariable int contractId,
@RequestBody Map<String, Object> fields) {
return contractService.setSickDays(volunteerId, contractId, fields);
}
}
24 changes: 24 additions & 0 deletions src/main/java/dev/urner/volodb/service/ContractService.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,23 @@

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

import org.springframework.stereotype.Service;

import dev.urner.volodb.dao.ContractDAO;
import dev.urner.volodb.dao.ContractModificationDAO;
import dev.urner.volodb.dao.ContractSalaryDAO;
import dev.urner.volodb.entity.Address;
import dev.urner.volodb.entity.Contract;
import dev.urner.volodb.entity.ContractModification;
import dev.urner.volodb.entity.Country;
import dev.urner.volodb.entity.Enums.AddressStatus;
import dev.urner.volodb.exception.ContractModificationNotFoundException;
import dev.urner.volodb.exception.ContractNotFoundException;
import dev.urner.volodb.exception.VolunteerInvalidFormatException;
import lombok.RequiredArgsConstructor;
import lombok.val;

@Service
@RequiredArgsConstructor
Expand Down Expand Up @@ -119,4 +125,22 @@ private Contract modifyContract(Contract contract) {
return contract;
}

public Contract setSickDays(int volunteerId, int contractId, Map<String, Object> fields) {
Contract dbContract = contractDAO.findById(contractId);

if (dbContract.equals(null) || dbContract.getVolunteer().getId() != volunteerId)
throw new VolunteerInvalidFormatException("No Contract with id " + contractId + " for Volunteer.");

fields.forEach((key, value) -> {

if (key.toLowerCase().equals("sickdays")) {
if (!value.equals(null) && !value.equals("") && Integer.parseInt(value.toString()) >= 0)
dbContract.setSickDays(Integer.parseInt(value.toString()));
}

});

return contractDAO.save(dbContract);
}

}

0 comments on commit 70cba3e

Please sign in to comment.