Created
April 10, 2021 06:23
-
-
Save kislayverma/a0575599d5f164091b9aa8b4f2ad5959 to your computer and use it in GitHub Desktop.
Generic update API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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