Skip to content

Commit

Permalink
Hotfix substitutes
Browse files Browse the repository at this point in the history
  • Loading branch information
PAException committed Nov 27, 2023
1 parent 1a9fa51 commit 8a5fe4f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import static io.github.paexception.engelsburg.api.util.Constants.Substitute.NAME_KEY;

Expand Down Expand Up @@ -113,8 +114,12 @@ public Result<GetSubstitutesResponseDTO> getSubstitutes(String classNameFilter,
List<SubstituteModel> substitutes = new ArrayList<>();
if (teacher.isEmpty() && classes.isEmpty()) {
substitutes = this.substituteRepository.findAllByDateGreaterThanEqual(date);
} else {
substitutes = this.substituteRepository.findAllByDateGreaterThanEqualAndClassNameIsNull(date);
}

if (!classes.isEmpty()) {
classes = classes.stream().flatMap(className -> NotificationService.splitClasses(className).stream()).collect(Collectors.toList());
substitutes.addAll(this.substituteRepository.findAllByDateGreaterThanEqualAndClassNameIn(date, classes));
}
if (!teacher.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,16 @@
import org.springframework.stereotype.Repository;
import java.sql.Date;
import java.util.List;
import java.util.Optional;

@Repository
public interface SubstituteRepository extends JpaRepository<SubstituteModel, Integer> {

/**
* Converts the class to a like parameter.
* 9c --> 9%c%
* 10c --> 10%c%
* should not be used vor E1 - Q4
* @param className to convert
* @return parsed parameter
*/
static String likeClassName(String className) {
if (className.length() == 2) return className.charAt(0) + "%" + className.charAt(1) + "%";
else return className.substring(0, 2) + "%" + className.charAt(2) + "%";
}

List<SubstituteModel> findAllByDate(Date date);

Optional<SubstituteModel> findByDateAndLessonAndTeacher(Date date, int lesson, String teacher);

default Optional<SubstituteModel> findByDateAndLessonAndClassNameLike(Date date, int lesson, String className) {
return this.findByDateAndLessonAndClassNameIsLike(date, lesson, likeClassName(className));
}

Optional<SubstituteModel> findByDateAndLessonAndClassNameIsLike(Date date, int lesson, String className);

Optional<SubstituteModel> findByDateAndLessonAndSubject(Date date, int lesson, String subject);

List<SubstituteModel> findAllByDateGreaterThanEqual(Date date);

List<SubstituteModel> findAllByDateGreaterThanEqualAndClassNameIsNull(Date date);

List<SubstituteModel> findAllByDateGreaterThanEqualAndClassNameIn(Date date, List<String> classes);

List<SubstituteModel> findAllByDateGreaterThanEqualAndTeacherInOrDateGreaterThanEqualAndSubstituteTeacherIn(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public boolean sameBase(SubstituteDTO dto) {
if (lesson != dto.lesson) return false;
if (!Objects.equals(className, dto.className)) return false;

if (!Character.isDigit(className.charAt(0))) { //Only for E1 - Q4
if (className != null && !Character.isDigit(className.charAt(0))) { //Only for E1 - Q4
return Objects.equals(teacher, dto.teacher);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class NotificationService implements LoggingComponent {
* @param className to split
* @return list of classNames
*/
private static List<String> splitClasses(String className) {
public static List<String> splitClasses(String className) {
if (className.length() <= 2 || (Character.isDigit(className.charAt(1)) && className.length() == 3)) {
return List.of(className);
} else { //5ab or 5ab6ab or E2Q2Q4
Expand Down Expand Up @@ -129,7 +129,7 @@ private static String getSubstituteTitle(SubstituteNotificationDTO substitute, b
} else if (DateUtils.isSameDay(substitute.getDate(), Date.from(Instant.now().plus(Duration.ofDays(1))))) {
relationalDay = "morgen";
} else {
relationalDay = "den " + DateTimeFormatter.ofPattern("dd.MM.").format(substitute.getDate().toInstant());
relationalDay = "den " + DateTimeFormatter.ofPattern("dd.MM.").format(substitute.getDate().toLocalDate());
}

return actuality + " Vertretung für " + relationalDay;
Expand Down

0 comments on commit 8a5fe4f

Please sign in to comment.