Documentation ¶
Index ¶
- Constants
- Variables
- func IsValidCarNumber(carNum int) bool
- func IsValidSeatClass(seatClass string) bool
- func IsValidStation(station string) bool
- func IsValidStations(gotStations []*Station) bool
- func IsValidTrainClass(trainClass string) bool
- func IsValidTrainSeatColumn(seatColumn string) bool
- type CancelReservationResponse
- type Client
- func (c *Client) CancelReservation(ctx context.Context, reservationID int, opt ...ClientOption) error
- func (c *Client) CommitReservation(ctx context.Context, reservationID int, cardToken string, opt ...ClientOption) error
- func (c *Client) DownloadAsset(ctx context.Context, path string) ([]byte, error)
- func (c *Client) Initialize(ctx context.Context)
- func (c *Client) ListReservations(ctx context.Context, opt ...ClientOption) (ListReservationsResponse, error)
- func (c *Client) ListStations(ctx context.Context, opt ...ClientOption) (ListStationsResponse, error)
- func (c *Client) Login(ctx context.Context, email, password string, opt ...ClientOption) error
- func (c *Client) Logout(ctx context.Context, opt ...ClientOption) error
- func (c *Client) ReplaceMockTransport()
- func (c *Client) Reserve(ctx context.Context, trainClass, trainName string, seatClass string, ...) (*ReserveResponse, error)
- func (c *Client) SearchTrainSeats(ctx context.Context, date time.Time, trainClass, trainName string, carNum int, ...) (*SearchTrainSeatsResponse, error)
- func (c *Client) SearchTrains(ctx context.Context, useAt time.Time, from, to, trainClass string, ...) (SearchTrainsResponse, error)
- func (c *Client) Settings(ctx context.Context) (*SettingsResponse, error)
- func (c *Client) ShowReservation(ctx context.Context, reservationID int, opt ...ClientOption) (ShowReservationResponse, error)
- func (c *Client) Signup(ctx context.Context, email, password string, opt ...ClientOption) error
- type ClientOption
- type ClientOptions
- type CommitReservationRequest
- type CommitReservationResponse
- type FareInformation
- type InitializeResponse
- type ListReservationsResponse
- type ListStationsResponse
- type Reservation
- type ReservationCacheEntry
- type ReservationSeat
- type ReservationSeats
- type ReserveRequest
- type ReserveResponse
- type SearchTrainSeatsResponse
- type SearchTrainsResponse
- type SeatAvailability
- type Session
- type SettingsResponse
- type ShowReservationResponse
- type Station
- type Train
- type TrainCar
- type TrainCars
- type TrainSeat
- type TrainSeatColumn
- type TrainSeats
- type User
Constants ¶
View Source
const ( ColumnA TrainSeatColumn = "A" ColumnB = "B" ColumnC = "C" ColumnD = "D" ColumnE = "E" )
Variables ¶
View Source
var ( ErrCommitReservation = errors.New("存在しない予約IDの予約Commitを実施しようとしました") ErrCancelReservation = errors.New("存在しない予約IDの予約Cancelを実施しようとしました") ErrCanNotReserve = errors.New("予約済みの座席が指定されたため予約できません") )
View Source
var (
ErrInvalidStationName = errors.New("駅名が不正です")
)
View Source
var (
ErrNoSeats = errors.New("座席がありません")
)
View Source
var (
ErrRedirect = errors.New("redirectが検出されました")
)
View Source
var (
// RCache は、webappの予約に関する情報が適切か検証するために用いられるキャッシュです
ReservationCache = newReservationCache()
)
Functions ¶
func IsValidCarNumber ¶
func IsValidSeatClass ¶
func IsValidStation ¶
func IsValidStations ¶
func IsValidTrainClass ¶
func IsValidTrainSeatColumn ¶
Types ¶
type CancelReservationResponse ¶
type CancelReservationResponse struct {
IsOK bool `json:"is_ok"`
}
予約キャンセルAPI
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func NewClientForInitialize ¶
func (*Client) CancelReservation ¶
func (*Client) CommitReservation ¶
func (*Client) DownloadAsset ¶
func (*Client) Initialize ¶
func (*Client) ListReservations ¶
func (c *Client) ListReservations(ctx context.Context, opt ...ClientOption) (ListReservationsResponse, error)
func (*Client) ListStations ¶
func (c *Client) ListStations(ctx context.Context, opt ...ClientOption) (ListStationsResponse, error)
ListStations は駅一覧列挙APIです
func (*Client) ReplaceMockTransport ¶
func (c *Client) ReplaceMockTransport()
ReplaceMockTransport は、clientの利用するhttp.RoundTripperを、DefaultTransportに差し替えます NOTE: httpmockはhttp.DefaultTransportを利用するため、モックテストの時この関数を利用する
func (*Client) Reserve ¶
func (c *Client) Reserve( ctx context.Context, trainClass, trainName string, seatClass string, seats TrainSeats, departure, arrival string, useAt time.Time, carNum int, child, adult int, opt ...ClientOption, ) (*ReserveResponse, error)
func (*Client) SearchTrainSeats ¶
func (*Client) SearchTrains ¶
func (c *Client) SearchTrains(ctx context.Context, useAt time.Time, from, to, trainClass string, adult, child int, opt ...ClientOption) (SearchTrainsResponse, error)
SearchTrains は 列車検索APIです
func (*Client) ShowReservation ¶
func (c *Client) ShowReservation(ctx context.Context, reservationID int, opt ...ClientOption) (ShowReservationResponse, error)
type ClientOption ¶
type ClientOption func(o *ClientOptions)
func DisableAssertOpt ¶
func DisableAssertOpt() ClientOption
func EnableAssertSeatCountOpt ¶
func EnableAssertSeatCountOpt(count int) ClientOption
func IsOKOpt ¶
func IsOKOpt(isOK bool) ClientOption
func StatusCodeOpt ¶
func StatusCodeOpt(statusCode int) ClientOption
type ClientOptions ¶
type ClientOptions struct {
// contains filtered or unexported fields
}
type CommitReservationRequest ¶
type CommitReservationRequest struct { ReservationID int `json:"reservation_id"` CardToken string `json:"card_token"` }
予約確定API
type CommitReservationResponse ¶
type CommitReservationResponse struct {
IsOK bool `json:"is_ok"`
}
予約確定API
type FareInformation ¶
type FareInformation string
const ( FiPremium FareInformation = "premium" FiPremiumSmoke FareInformation = "premium_smoke" FiReserved FareInformation = "reserved" FiReservedSmoke FareInformation = "reserved_smoke" FiNonReserved FareInformation = "non_reserved" )
func (FareInformation) String ¶
func (fi FareInformation) String() string
func (FareInformation) Value ¶
func (fi FareInformation) Value() int
type InitializeResponse ¶
type ListStationsResponse ¶
type ListStationsResponse []*Station
ListStationsResponse は /api/stations のレスポンス形式です
type Reservation ¶
type Reservation struct { ReservationID int `json:"reservation_id"` Date string `json:"date"` TrainClass string `json:"train_class"` TrainName string `json:"train_name"` CarNumber int `json:"car_number"` SeatClass string `json:"seat_class"` Amount int `json:"amount"` Adult int `json:"adult"` Child int `json:"child"` Departure string `json:"departure"` Arrival string `json:"arrival"` DepartureTime string `json:"departure_time"` ArrivalTime string `json:"arrival_time"` Seats ReservationSeats `json:"seats"` }
予約詳細・列挙API
type ReservationCacheEntry ¶
type ReservationCacheEntry struct { // ユーザ情報 User *User // 予約情報 ID int Date time.Time Departure, Arrival string TrainClass, TrainName string CarNum int SeatClass string Seats TrainSeats Adult, Child int }
func (*ReservationCacheEntry) Amount ¶
func (r *ReservationCacheEntry) Amount() (int, error)
Amount は、大人と子供を考慮し、合計の運賃を算出します
func (*ReservationCacheEntry) SeatCount ¶
func (r *ReservationCacheEntry) SeatCount() int
type ReservationSeat ¶
type ReservationSeat struct { ReservationID int `json:"reservation_id,omitempty" db:"reservation_id"` CarNumber int `json:"car_number,omitempty" db:"car_number"` SeatRow int `json:"seat_row" db:"seat_row"` SeatColumn string `json:"seat_column" db:"seat_column"` }
予約詳細・列挙API
type ReservationSeats ¶
type ReservationSeats []*ReservationSeat
予約詳細・列挙API
func (ReservationSeats) GetNeighborSeatsBonus ¶
func (seats ReservationSeats) GetNeighborSeatsBonus() int
隣り合うパターンを見つけたら加算する
type ReserveRequest ¶
type ReserveRequest struct { Date string `json:"date"` TrainName string `json:"train_name"` TrainClass string `json:"train_class"` CarNum int `json:"car_number"` IsSmokingSeat bool `json:"is_smoking_seat"` SeatClass string `json:"seat_class"` Departure string `json:"departure"` Arrival string `json:"arrival"` Child int `json:"child"` Adult int `json:"adult"` Column string `json:"Column"` Seats TrainSeats `json:"seats"` }
予約API /api/train/reserve
type ReserveResponse ¶
type ReserveResponse struct { ReservationID int `json:"reservation_id"` Amount int `json:"amount"` IsOk bool `json:"is_ok"` }
予約API /api/train/reserve
type SearchTrainSeatsResponse ¶
type SearchTrainSeatsResponse struct { Date string `json:"date"` TrainClass string `json:"train_class"` TrainName string `json:"train_name"` CarNumber int `json:"car_number"` Seats TrainSeats `json:"seats"` Cars TrainCars `json:"cars"` }
/api/train/seats のレスポンス形式
type SeatAvailability ¶
type SeatAvailability string
const ( SaPremium SeatAvailability = "premium" SaPremiumSmoke SeatAvailability = "premium_smoke" SaReserved SeatAvailability = "reserved" SaReservedSmoke SeatAvailability = "reserved_smoke" SaNonReserved SeatAvailability = "non_reserved" )
func (SeatAvailability) String ¶
func (sa SeatAvailability) String() string
func (SeatAvailability) Value ¶
func (sa SeatAvailability) Value() string
type SettingsResponse ¶
type SettingsResponse struct {
PaymentAPI string `json:"payment_api"`
}
type Train ¶
type Train struct { Class string `json:"train_class"` Name string `json:"train_name"` Start string `json:"start"` Last string `json:"last"` Departure string `json:"departure"` Arrival string `json:"arrival"` DepartedAt string `json:"departure_time"` ArrivedAt string `json:"arrival_time"` SeatAvailability map[string]string `json:"seat_availability"` FareInformation map[string]int `json:"seat_fare"` }
/api/train/search のレスポンス形式
type TrainSeat ¶
type TrainSeat struct { Row int `json:"row"` Column string `json:"column"` Class string `json:"class"` IsSmokingSeat bool `json:"is_smoking_seat,omitempty"` IsOccupied bool `json:"is_occupied,omitempty"` }
/api/train/seats のレスポンス形式
type TrainSeatColumn ¶
type TrainSeatColumn string
func (TrainSeatColumn) Int ¶
func (c TrainSeatColumn) Int() int
func (TrainSeatColumn) IsNeighbor ¶
func (c TrainSeatColumn) IsNeighbor(c2 TrainSeatColumn) bool
type TrainSeats ¶
type TrainSeats []*TrainSeat
/api/train/seats のレスポンス形式
func (TrainSeats) IsSame ¶
func (seats TrainSeats) IsSame(gotSeats TrainSeats) bool
Click to show internal directories.
Click to hide internal directories.