Skip to content

Commit

Permalink
Merge pull request #49 from yngwi/master
Browse files Browse the repository at this point in the history
Move date range validation to event repository
  • Loading branch information
yngwi authored Oct 25, 2021
2 parents d0cced8 + cdb51f6 commit fbfeff0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</parent>
<groupId>eu.nampi</groupId>
<artifactId>backend</artifactId>
<version>0.4.0</version>
<version>0.4.1</version>
<name>nampi-backend</name>
<description>The NAMPI backend</description>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ public DateRange convert(String string) {
if (start.isPresent() && end.isPresent()) {
var startVal = start.get();
var endVal = end.get();
if (startVal.isAfter(endVal)) {
throw new IllegalArgumentException(
String.format("Start date '%s' is not allowed to be after '%s'", startVal, endVal));
}
if (startVal.equals(endVal)) {
end = Optional.empty();
isRange = false;
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/eu/nampi/backend/repository/EventRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,16 @@ private void validatePayload(Lang lang, List<Resource> types,
HydraInsertBuilder builder = hydraBuilderFactory.insertBuilder(lang, ENDPOINT_NAME, types,
labels, comments, texts, new ArrayList<>());
builder.validateSubresources(Core.event, types);
// Date
optionalDate
.ifPresent(date -> date.getStart().ifPresent(start -> date.getEnd().ifPresent(end -> {
if (start.isAfter(end)) {
throw new IllegalArgumentException(
String.format("Start date '%s' is not allowed to be after '%s'",
start.format(DateTimeFormatter.ISO_DATE),
end.format(DateTimeFormatter.ISO_DATE)));
}
})));
// Event main participant
builder.validateType(Core.person, mainParticipant.getObject());
mainParticipant.getPredicate().ifPresent(predicate -> {
Expand Down

0 comments on commit fbfeff0

Please sign in to comment.