Skip to content
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

Bugfix notification service, added timestamp for substitutes #108

Merged
merged 3 commits into from
Nov 1, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,6 @@ public List<String> getTimetableTokens(SubstituteNotificationDTO dto) {
@Transactional
public void deleteInvalidTokens(List<String> invalidTokens) {
//Delete all invalid tokens
this.tokenRepository.deleteAllByTokenIn(invalidTokens);
if (!invalidTokens.isEmpty()) this.tokenRepository.deleteAllByTokenIn(invalidTokens);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@
@AllArgsConstructor
public class SubstituteController {

private static long timestamp = 0;

private final SubstituteRepository substituteRepository;
private final NotificationService notificationService;


/**
* Checks if a string is not blank, empty or null.
*
Expand Down Expand Up @@ -75,6 +78,8 @@ private static SubstituteModel createSubstitute(int substituteId, SubstituteDTO
*/
@Transactional
public void updateSubstitutes(List<SubstituteDTO> fetchedDTOs, Date date) {
timestamp = System.currentTimeMillis();

List<SubstituteDTO> current = new ArrayList<>();
for (SubstituteModel substitute : this.substituteRepository.findAllByDate(date)) {
current.add(substitute.toResponseDTO());
Expand Down Expand Up @@ -137,6 +142,6 @@ public Result<GetSubstitutesResponseDTO> getSubstitutes(String classNameFilter,
//Map substitutes to response dtos and return them
List<SubstituteDTO> dtos = new ArrayList<>();
for (SubstituteModel substitute : substitutes) dtos.add(substitute.toResponseDTO());
return Result.of(new GetSubstitutesResponseDTO(dtos));
return Result.of(new GetSubstitutesResponseDTO(dtos, timestamp));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
public class GetSubstitutesResponseDTO {

private List<SubstituteDTO> substitutes;
private long timestamp;

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import io.github.paexception.engelsburg.api.service.scheduled.SubstituteUpdateService;

import org.junit.jupiter.api.Test;
import io.github.paexception.engelsburg.api.endpoint.dto.SubstituteDTO;
import java.sql.Date;
import java.util.Objects;

import java.sql.Date;
import java.util.Objects;
Expand All @@ -14,7 +17,7 @@ public class SubstituteParseTest {
public void testSubstituteParse() {
new SubstituteUpdateService(null, null, null).updateSubstitutes();
}

@Test
public void substituteDTOEqualTest() {
//Correct 5a - 10e
Expand Down
Loading