-
Notifications
You must be signed in to change notification settings - Fork 0
/
BookingContract.sol
88 lines (73 loc) · 3.47 KB
/
BookingContract.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.13;
import "./Flight.sol";
/// @author GreatLearningGroup3
/// @title BookingContract holding customer booking details
contract BookingContract {
enum BookingState {INITIATED, PENDING, CONFIRMED, CANCELLED}
struct BookingData {
address customer;
string confirmationId;
address airlines;
BookingState state;
string comment;
Flight.SeatCategory seatCategory;
string flightNumber;
}
// mapping(uint8 => uint8) public _penaltyMap;
BookingData bookingData;
uint val;
constructor(address _customer, address _airlines, uint _val) {
bookingData = BookingData({
customer: _customer,
confirmationId: '',
airlines: _airlines,
state: BookingState.INITIATED,
comment: '',
seatCategory: Flight.SeatCategory.ECONOMY,
flightNumber: ''
});
val += _val;
}
/// Confirms ticket booking and sets rest of the booking details
/// @param _customer Customer for which booking is to be confirmed
/// @param _seatCategory Seat category requested by the customer
/// @param _flightNumber Flight for which booking is to be done
/// @dev Method does not perform parameter validation and caller of this method needs to validate the same
function bookTicket(address _customer, Flight.SeatCategory _seatCategory, string memory _flightNumber) public returns (string memory) {
bookingData.confirmationId = "CONF1233455";
bookingData.customer = _customer;
bookingData.seatCategory = _seatCategory;
bookingData.flightNumber = _flightNumber;
bookingData.state = BookingState.CONFIRMED;
bookingData.comment = string(abi.encodePacked("Booking confirmed with confirmation id ", bookingData.confirmationId, " for the flight ", _flightNumber));
return bookingData.comment;
}
/// Get booking details for given customer
/// @dev Method does not perform parameter validation and caller of this method needs to validate the same
// function getBookingData() public view returns (address, string memory, BookingState, string memory){
function getBookingData() public view returns (BookingData memory){
// return (bookingData.customer, bookingData.comment, bookingData.state, bookingData.flightNumber);
return bookingData;
}
/// Cancel booking for the confirmationId provided
/// @dev Method does not perform parameter validation and caller of this method needs to validate the same
function cancelBooking() public {
//Requires current time is 2 hours before the flight time
//Retrieve the booking based on either customer address or confirmationId
//Calculate Refund and Penalty
//Transfer funds to both the parties
//Change the BookingState to Cancelled
bookingData.state = BookingState.CANCELLED;
bookingData.comment = string(abi.encodePacked("Booking cancelled for the customer with confirmation id ", bookingData.confirmationId));
//Remove the booking from the bookings List?
}
function flightCancelled() public {
bookingData.state = BookingState.CANCELLED;
bookingData.comment = string(abi.encodePacked("Booking cancelled for the customer ", msg.sender,
"with confirmation id ", bookingData.confirmationId));
}
function getValue() public view returns(uint) {
return val;
}
}