Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Generic update API
public class Booking {
String uniqueId;
User guest;
User host;
Date bookingTime;
Date confirmationTime;
Date cancellationTime;
Status status; //PENDING, CONFIRMED, CANCELLED_BY_GUEST, CANCELLED_BY_HOST
User lastUpdatedBy;
}
public class BookingUpdateRequest {
Date updateTime;
Booking updatedBooking;
}
// In Booking Service
public void updateBooking(BookingUpdateRequest request) {
Booking originalBooking = readFromDB(request.updatedBooking.uniqueId);
if ((originalBooking.status == PENDING || originalBooking.status == CONFIRMED) &&
(request.updatedBooking.status == CANCELLED_BY_GUEST)) {
originalBooking.lastUpdatedBy = originalBooking.guest;
originalBooking.cancellationTime = request.updateTime
// Trigger notification to host
// Trigger refund if payment was taken
} else if ((originalBooking.status == PENDING || originalBooking.status == CONFIRMED) &&
(request.updatedBooking.status == CANCELLED_BY_HOST)) {
originalBooking.lastUpdatedBy = originalBooking.host;
// Trigger notification to guest
// Trigger refund if payment was taken
}
// else if ........ more conditions to handle other combinations of new/old variables
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment