Skip to content

Commit

Permalink
https://jira.fingo.info/browse/IJ-284 add posibility to modify rows i…
Browse files Browse the repository at this point in the history
…n table ( base number of days, days to add)
  • Loading branch information
Dawid Dudek committed Dec 19, 2022
1 parent a582c64 commit f54a70a
Show file tree
Hide file tree
Showing 16 changed files with 517 additions and 179 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import info.fingo.urlopia.api.v2.automatic.vacation.days.model.AutomaticVacationDayDTO;
import info.fingo.urlopia.api.v2.automatic.vacation.days.model.UpdateUserConfig;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.*;

import javax.annotation.security.RolesAllowed;
Expand All @@ -16,8 +17,8 @@ public class AutomaticVacationDayController {

@GetMapping()
@RolesAllowed({"ROLES_ADMIN"})
public List<AutomaticVacationDayDTO> getAll(){
return automaticVacationDayService.getAll();
public List<AutomaticVacationDayDTO> getAll(Pageable pageable){
return automaticVacationDayService.getAll(pageable);
}

@PatchMapping()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import org.springframework.data.domain.Pageable;
import java.time.LocalDateTime;
import java.util.List;

Expand All @@ -30,8 +31,8 @@ public AutomaticVacationDayDTO update(UpdateUserConfig updateUserConfig) {
return AutomaticVacationDayDTO.from(updated);
}

public List<AutomaticVacationDayDTO> getAll() {
return automaticVacationDaysRepository.findAll()
public List<AutomaticVacationDayDTO> getAll(Pageable pageable) {
return automaticVacationDaysRepository.findAll(pageable)
.stream()
.map(this::countProposition)
.map(AutomaticVacationDayDTO::from)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class AddDaysScheduler {

private final AutomaticVacationDayService automaticVacationDayService;

@Scheduled(cron = "0 5 0 1 1 ?") //1 january 00:05:00
@Scheduled(cron = "${urlopia.automatic.days.add.cron}")
public void addNewYearHours() {
log.info("Automatic add of hours for new year started");
automaticVacationDayService.addHoursForNewYear();
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/info/fingo/urlopia/history/HistoryLogInput.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package info.fingo.urlopia.history;

import info.fingo.urlopia.UrlopiaApplication;
import info.fingo.urlopia.api.v2.automatic.vacation.days.model.AutomaticVacationDay;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class HistoryLogInput {
private static final String AUTOMATIC_ADD_MESSAGE_TEMPLATE = "Automatycznie dodano dni urlopowe dnia: %s";
private static final String AUTOMATIC_ADD_MESSAGE_TEMPLATE = "Automatycznie dodano dni urlopowe dnia: %s na rok %s";
private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern(UrlopiaApplication.DATE_TIME_FORMAT);
private Float hours;
private String comment;

Expand Down Expand Up @@ -38,7 +41,9 @@ public void setComment(String comment) {
public static HistoryLogInput from(AutomaticVacationDay automaticVacationDay){
var input = new HistoryLogInput();
input.setHours(automaticVacationDay.getNextYearHoursProposition().floatValue());
input.setComment(AUTOMATIC_ADD_MESSAGE_TEMPLATE.formatted(LocalDateTime.now()));
var additionDate = LocalDateTime.now();
var formattedLocalDateTime = DATE_TIME_FORMATTER.format(additionDate);
input.setComment(AUTOMATIC_ADD_MESSAGE_TEMPLATE.formatted(formattedLocalDateTime, additionDate.getYear()));
return input;
}
}
6 changes: 5 additions & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,8 @@ management.endpoints.web.exposure.include=health
proxy-token=

# presence confirmation
urlopia.presence.confirmation.considered.months = 2
urlopia.presence.confirmation.considered.months = 2

#automatic days add
# 1 january 00:05:00
urlopia.automatic.days.add.cron = 0 5 0 1 1 ?
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ import info.fingo.urlopia.api.v2.automatic.vacation.days.model.AutomaticVacation
import info.fingo.urlopia.api.v2.automatic.vacation.days.model.UpdateUserConfig
import info.fingo.urlopia.history.HistoryLogInput
import info.fingo.urlopia.history.HistoryLogService
import org.springframework.data.domain.PageImpl
import spock.lang.Specification
import info.fingo.urlopia.user.User
import org.springframework.data.domain.Pageable


class AutomaticVacationDayServiceSpec extends Specification{

Expand Down Expand Up @@ -67,11 +70,11 @@ class AutomaticVacationDayServiceSpec extends Specification{
}
def vacationDays = new AutomaticVacationDay(user, 26, 0)

automaticVacationDaysRepository.findAll() >> [vacationDays]
automaticVacationDaysRepository.findAll(_ as Pageable) >> new PageImpl<AutomaticVacationDay>([vacationDays])
automaticVacationDaysRepository.save(_ as AutomaticVacationDay) >> {AutomaticVacationDay automaticVacationDay -> automaticVacationDay}

when:
def result = automaticVacationDayService.getAll()
def result = automaticVacationDayService.getAll(Mock(Pageable))

then:
result.get(0).nextYearProposition() == 0
Expand All @@ -83,11 +86,11 @@ class AutomaticVacationDayServiceSpec extends Specification{
getId() >> 1L
}
def vacationDays = new AutomaticVacationDay(user, 26, 0)
automaticVacationDaysRepository.findAll() >> [vacationDays]
automaticVacationDaysRepository.findAll(_ as Pageable) >> new PageImpl<AutomaticVacationDay>([vacationDays])
automaticVacationDaysRepository.save(_ as AutomaticVacationDay) >> {AutomaticVacationDay automaticVacationDay -> automaticVacationDay}

when:
def result = automaticVacationDayService.getAll()
def result = automaticVacationDayService.getAll(Mock(Pageable))

then:
result.get(0).nextYearProposition() == 26 * 8
Expand Down
Loading

0 comments on commit f54a70a

Please sign in to comment.