forked from airheartdev/duffel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
seatmaps.go
121 lines (99 loc) · 3.95 KB
/
seatmaps.go
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// Copyright 2021-present Airheart, Inc. All rights reserved.
// This source code is licensed under the Apache 2.0 license found
// in the LICENSE file in the root directory of this source tree.
package duffel
import (
"context"
"github.com/bojanz/currency"
)
type (
Seatmap struct {
Cabins []Cabin `json:"cabins"`
ID string `json:"id"`
SegmentID string `json:"segment_id"`
SliceID string `json:"slice_id"`
}
Cabin struct {
Aisles int `json:"aisles"`
CabinClass CabinClass `json:"cabin_class"`
Deck int `json:"deck"`
// A list of rows in this cabin.
Rows []Row `json:"rows"`
// Where the wings of the aircraft are in relation to rows in the cabin.
Wings Wing `json:"wings"`
}
// Row represents a row in a cabin.
Row struct {
// A list of sections. Each row is divided into sections by one or more aisles.
Sections []SeatSection `json:"sections"`
}
// SeatSection represents a section of a row.
SeatSection struct {
// The elements that make up this section.
Elements []SectionElement `json:"elements"`
}
// SectionElement represents an element in a section.
SectionElement struct {
// The element type, e.g. seat, exit_row, stairs, etc.
Type ElementType `json:"type"`
// Seats are considered a special kind of service.
// There will be at most one service per seat per passenger.
// A seat can only be booked for one passenger. If a seat has no available services (which will be represented as an empty list : []) then it's unavailable.
AvailableServices []SectionService `json:"available_services"`
// The designator used to uniquely identify the seat, usually made up of a row number and a column letter
Designator string `json:"designator"`
// Each disclosure is text, in English, provided by the airline that describes the terms and conditions of this seat. We recommend showing this in your user interface to make sure that customers understand any restrictions and limitations.
Disclosures []string `json:"disclosures"`
// A name which describes the type of seat, which you can display in your user interface to help customers to understand its features.
// Example: "Exit row seat"
Name string `json:"name"`
}
SectionService struct {
ID string `json:"id"`
PassengerID string `json:"passenger_id"`
RawTotalAmount string `json:"total_amount"`
RawTotalCurrency string `json:"total_currency"`
}
ElementType string
// Wing represents a wing of the aircraft in relation to rows in the cabin.
Wing struct {
// The index of the first row which is overwing, starting from the front of the aircraft.
FirstRowIndex int `json:"first_row_index"`
// The index of the last row which is overwing, starting from the front of the aircraft.
LastRowIndex int `json:"last_row_index"`
}
SeatmapClient interface {
// GetSeatmap returns an iterator for the seatmaps of a given Offer.
GetSeatmap(ctx context.Context, offerID string) ([]*Seatmap, error)
SeatmapForOffer(ctx context.Context, offer Offer) ([]*Seatmap, error)
}
)
const (
ElementTypeSeat ElementType = "seat"
ElementTypeBassinet ElementType = "bassinet"
ElementTypeEmpty ElementType = "empty"
ElementTypeExitRow ElementType = "exit_row"
ElementTypeLavatory ElementType = "lavatory"
ElementTypeGalley ElementType = "galley"
ElementTypeCloset ElementType = "closet"
ElementTypeStairs ElementType = "stairs"
)
func (e ElementType) String() string {
return string(e)
}
func (a *API) SeatmapForOffer(ctx context.Context, offer Offer) ([]*Seatmap, error) {
return a.GetSeatmap(ctx, offer.ID)
}
func (a *API) GetSeatmap(ctx context.Context, offerID string) ([]*Seatmap, error) {
return newRequestWithAPI[EmptyPayload, Seatmap](a).
Get("/air/seat_maps").
WithParam("offer_id", offerID).
Slice(ctx)
}
func (s *SectionService) TotalAmount() currency.Amount {
amount, err := currency.NewAmount(s.RawTotalAmount, s.RawTotalCurrency)
if err != nil {
return currency.Amount{}
}
return amount
}