Skip to content
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
2 changes: 1 addition & 1 deletion app/travels/webapp/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</style>
<script
id="sap-ui-bootstrap"
src="https://ui5.sap.com/1.136.8/resources/sap-ui-core.js"
src="https://ui5.sap.com/1.136.12/resources/sap-ui-core.js"
data-sap-ui-theme="sap_horizon"
data-sap-ui-oninit="module:sap/ui/core/ComponentSupport"
data-sap-ui-resourceroots='{ "sap.capire.travels": "." }'
Expand Down
23 changes: 0 additions & 23 deletions db/constraints.cds

This file was deleted.

2 changes: 1 addition & 1 deletion db/schema.cds
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ using {


entity Travels : managed {
key ID : Integer default 0 @readonly;
key ID : Integer default 0;
Description : String(1024);
BeginDate : Date default $now;
EndDate : Date default $now;
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,4 @@
</plugin>
</plugins>
</build>
</project>
</project>
5 changes: 5 additions & 0 deletions srv/src/main/resources/messages.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ASSERT_ENDDATE_AFTER_BEGINDATE=End date must be after begin date
ASSERT_BOOKINGS_IN_TRAVEL_PERIOD=All bookings must be within the travel period
ASSERT_BOOKING_CURRENCY_MATCHES_TRAVEL=All bookings must use the same currency as the travel
ASSERT_FLIGHT_PRICE_POSITIVE=Flight price must be a positive value
ASSERT_BOOKING_FEE_NON_NEGATIVE=Booking fee cannot be negative
5 changes: 5 additions & 0 deletions srv/src/main/resources/messages_de.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ASSERT_ENDDATE_AFTER_BEGINDATE=Enddatum muss nach dem Anfangsdatum liegen
ASSERT_BOOKINGS_IN_TRAVEL_PERIOD=Alle Buchungen müssen innerhalb des Reisezeitraums liegen
ASSERT_BOOKING_CURRENCY_MATCHES_TRAVEL=Alle Buchungen müssen dieselbe Währung wie die Reise verwenden
ASSERT_FLIGHT_PRICE_POSITIVE=Der Flugpreis muss ein positiver Wert sein
ASSERT_BOOKING_FEE_NON_NEGATIVE=Buchungsgebühr kann nicht negativ sein
5 changes: 5 additions & 0 deletions srv/src/main/resources/messages_fr.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ASSERT_ENDDATE_AFTER_BEGINDATE=La date de fin doit être postérieure à la date de début
ASSERT_BOOKINGS_IN_TRAVEL_PERIOD=Toutes les réservations doivent être dans la période de voyage
ASSERT_BOOKING_CURRENCY_MATCHES_TRAVEL=Toutes les réservations doivent utiliser la même devise que le voyage
ASSERT_FLIGHT_PRICE_POSITIVE=Le prix du vol doit être une valeur positive
ASSERT_BOOKING_FEE_NON_NEGATIVE=Les frais de réservation ne peuvent pas être négatifs
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,11 @@ void shouldCreateAndRetrieveTravelWithBookingsSuccessfully() throws Exception {
booking.setFlightId("GA0322");
booking.setFlightDate(LocalDate.of(2024, 6, 2));
booking.setFlightPrice(BigDecimal.valueOf(1103));
booking.setCurrencyCode("EUR");
Bookings.Supplements supplement = Bookings.Supplements.create();
supplement.setBookedId("bv-0001");
supplement.setPrice(new BigDecimal("2.30"));
supplement.setCurrencyCode("EUR");
booking.setSupplements(List.of(supplement));
travel.setBookings(List.of(booking));

Expand Down
54 changes: 54 additions & 0 deletions srv/travel-constraints.cds
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using { TravelService } from './travel-service';


annotate TravelService.Travels with {

Description @assert: (case
when length(Description) < 3 then 'Description too short'
end);

Agency @assert: (case
when not exists Agency then 'Agency does not exist'
end);

Customer @assert: (case
when Customer is null then 'Customer must be specified'
when not exists Customer then 'Customer does not exist'
end);

EndDate @assert: (case
when EndDate < BeginDate then error('ASSERT_ENDDATE_AFTER_BEGINDATE', null, (BeginDate, EndDate))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the JS variant, an additional check is used :

 when exists Bookings [Flight.date < Travel.BeginDate] then 'ASSERT_BOOKINGS_IN_TRAVEL_PERIOD'

However, the JS variant does the check again on the Travel entity (https://github.com/capire/xtravels/blob/e89c2df28511de82a35e9da5433182d283388d9f/srv/travel-constraints.cds#L22C4-L22C98).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic is covered by the assertion on Flight.date. I wouldn't duplicate these errors, as it leads to multiple errors with the same reason. I'd rather refer to the BeginDate/EndDate as additional targets, but I don't think this is necessary here.

end);

BookingFee @assert: (case
when BookingFee < 0 then 'ASSERT_BOOKING_FEE_NON_NEGATIVE'
end);

};


annotate TravelService.Bookings with {

Flight {
date @assert: (case
when date not between $self.Travel.BeginDate and $self.Travel.EndDate then 'ASSERT_BOOKINGS_IN_TRAVEL_PERIOD'
end);
}

FlightPrice @assert: (case
when FlightPrice < 0 then 'ASSERT_FLIGHT_PRICE_POSITIVE'
end);

Currency {
code @assert: (case
when code != $self.Travel.Currency.code then 'ASSERT_BOOKING_CURRENCY_MATCHES_TRAVEL'
end);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

taken from the JS variant:

Suggested change
BookingDate @assert: (case
when BookingDate > Travel.EndDate then 'ASSERT_NO_BOOKINGS_AFTER_TRAVEL'
end);

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd leave this out for now. The BookingDate is defaulted to "today". This makes it very impractical to play around with the application when creating new bookings, as all test data is in the past. We can maybe add it later on, but I don't think it shows any additional feature, so I would leave it out for practical reasons.

};


annotate TravelService.Travels with @Capabilities.FilterRestrictions.FilterExpressionRestrictions: [
{ Property: 'BeginDate', AllowedExpressions : 'SingleRange' },
{ Property: 'EndDate', AllowedExpressions : 'SingleRange' }
];