schema

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 28, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ADMN  = "ADMIN"
	CSTMR = "CUSTOMER"
)
View Source
const BUS_UNIT_MIN_CAPACITY = 25

Variables

View Source
var UserIDCode = map[int]string{
	1: "ADMN",
	2: "CSTMR",
}
View Source
var UserType = map[int]string{
	1: ADMN,
	2: CSTMR,
}

Functions

This section is empty.

Types

type BookingCancelled

type BookingCancelled struct {
	ID            string `json:"id" dynamodbav:"id"`                         // Unique booking cancellation ID
	BookingID     string `json:"booking_id" dynamodbav:"booking_id"`         // Unique booking ID as the primary key
	Reason        string `json:"reason" dynamodbav:"reason"`                 // Reason for booking cancellation
	CancelledBy   string `json:"cancelled_by" dynamodbav:"cancelled_by"`     // Indicates who cancelled the booking
	DateCancelled string `json:"date_cancelled" dynamodbav:"date_cancelled"` // The date when the booking was cancelled
}

Cancelled contains the cancelled booking information.

type BookingStatus

type BookingStatus string

BookingStatus is the status of the particular booking.

func (BookingStatus) Cancelled

func (BookingStatus) Cancelled() BookingStatus

Cancelled booking status means that the booking is cancelled by the user or due to other reason.

func (BookingStatus) Confirmed

func (BookingStatus) Confirmed() BookingStatus

Confirmed booking status means that is confirmed by the administrator.

func (BookingStatus) Pending

func (BookingStatus) Pending() BookingStatus

Pending booking status means that it is not yet confirmed of processed.

type Bookings

type Bookings struct {
	ID            string           `json:"id" dynamodbav:"id"`                                                 // Unique booking ID as the primary key
	UserID        string           `json:"user_id" dynamodbav:"user_id"`                                       // The user ID
	BusID         string           `json:"bus_id" dynamodbav:"bus_id"`                                         // The unique Bus ID
	BusRouteID    string           `json:"bus_route_id" dynamodbav:"bus_route_id"`                             // The unique Bus Route ID as the sort key
	Status        BookingStatus    `json:"status" dynamodbav:"status"`                                         // The status of the particular booking
	SeatNumber    string           `json:"seat_number" dynamodbav:"seat_number"`                               // The specific seat number(s) for the particular booking
	TravelDate    string           `json:"travel_date" dynamodbav:"travel_date"`                               // The date when to travel
	DateCreated   string           `json:"date_created" dynamodbav:"date_created"`                             // The date it was created as unix epoch time
	DateConfirmed string           `json:"date_confirmed,omitempty" dynamodbav:"date_confirmed,omitemptyelem"` // The date the booking was confirmed
	IsCancelled   *bool            `json:"is_cancelled,omitempty" dynamodbav:"is_cancelled,omitemptyelem"`     // Indicates if the booking is cancelled or not
	Cancelled     BookingCancelled `json:"cancelled,omitempty" dynamodbav:"-"`                                 // Contains the cancelled booking record
	Timestamp     string           `json:"timestamp" dynamodbav:"timestamp"`                                   // The timestamp when the request was made
}

Bookings is used to store the details of reserving seats for a particular bus.

The "dynamodbav" struct tag can be used to control the value that will be marshaled into a AttributeValue.

func (Bookings) Error

func (booking Bookings) Error(err error, code, message string, kv ...utility.KVP)

Error sets the default key-value pair.

func (Bookings) EventSource

func (booking Bookings) EventSource() (string, error)

EventSource returns an EventBridge event source.

EventSource Types:
 - booking:confirmed
 - booking:cancelled

func (Bookings) IsBookingCancelled

func (booking Bookings) IsBookingCancelled() error

IsBookingCancelled validates if the details for the canceled booking are set or not. If the required fields are not set, it will return an error message.

Required fields:
 reason, cancelled_by

func (Bookings) IsEmptyPayload

func (booking Bookings) IsEmptyPayload(payload string) error

IsEmptyPayload checks if the request payload is empty and if it is, it will return an error message.

func (Bookings) IsValidStatus

func (booking Bookings) IsValidStatus() error

IsValidStatus validates if the booking status is valid or not. If it is an invalid booking status, it will return an error message.

Valid Booking Status:

PENDING, CONFIRMED, CANCELLED

func (*Bookings) SetValues

func (booking *Bookings) SetValues()

SetValues automatically generates the Bookings ID as your primary key, and set the date it was created as unix epoch time.

Example:

ID: 36bc8bc5-44d6-447b-a63b-039b99658b78
DateCreated: 1688091891

type Bus

type Bus struct {
	ID           string `json:"id" dynamodbav:"id"`                                             // Unique bus ID
	Name         string `json:"name" dynamodbav:"name"`                                         // Name of the bus line as the primary key
	Owner        string `json:"owner" dynamodbav:"owner"`                                       // Bus company owner and is a required field
	Email        string `json:"email" dynamodbav:"email"`                                       // Bus company email and is a required field
	Address      string `json:"address" dynamodbav:"address"`                                   // Bus company address and is a required field
	Company      string `json:"company" dynamodbav:"company"`                                   // Name of the company and serves as your sort key and is a required field
	MobileNumber string `json:"mobile_number" dynamodbav:"mobile_number"`                       // Bus company mobile number and is a required field
	DateCreated  string `json:"date_created,omitempty" dynamodbav:"date_created,omitemptyelem"` // The date it was created as unix epoch time
}

Bus contains the basic information of the bus company.

The "dynamodbav" struct tag can be used to control the value that will be marshaled into a AttributeValue.

func (Bus) Error

func (bus Bus) Error(err error, code, message string, kv ...utility.KVP)

Error sets the default key-value pair.

func (Bus) IsEmptyPayload

func (bus Bus) IsEmptyPayload(payload string) error

IsEmptyPayload checks if the request payload is empty and if it is, it will return an error message.

func (*Bus) SetValues

func (bus *Bus) SetValues()

SetValues automatically generates the Bus ID as your primary key, and set the date it was created as unix epoch time.

Example:

id: RLBSW-856996
date_created: 1685699666

type BusRoute

type BusRoute struct {
	ID            string   `json:"id" dynamodbav:"id"`                                             // Unique bus route ID as the primary key
	BusID         string   `json:"bus_id" dynamodbav:"bus_id"`                                     // The Bus ID as the sort key
	BusUnitID     string   `json:"bus_unit_id" dynamodbav:"bus_unit_id"`                           // The Bus Unit ID for the identification of specific bus unit route
	Currency      string   `json:"currency_code" dynamodbav:"currency_code"`                       // Medium of exchange for goods and services
	Rate          *float64 `json:"rate" dynamodbav:"rate"`                                         // Fare charged to the passenger
	Active        *bool    `json:"active" dynamodbav:"active"`                                     // Defines if the bus is available for that route
	DepartureTime string   `json:"departure_time" dynamodbav:"departure_time"`                     // Expected departure time on the starting point and in 24-hour format
	ArrivalTime   string   `json:"arrival_time" dynamodbav:"arrival_time"`                         // Expected arrival time on the destination and in 24-hour format
	FromRoute     string   `json:"from_route" dynamodbav:"from_route"`                             // Indicating the starting point of a bus
	ToRoute       string   `json:"to_route" dynamodbav:"to_route"`                                 // Indicating the destination of bus
	DateCreated   string   `json:"date_created,omitempty" dynamodbav:"date_created,omitemptyelem"` // The date it was created as unix epoch time
}

BusRoute is used to store the specific bus unit route, rate, and schedule.

The "dynamodbav" struct tag can be used to control the value that will be marshaled into a AttributeValue.

func (BusRoute) Error

func (route BusRoute) Error(err error, code, message string, kv ...utility.KVP)

Error sets the default key-value pair.

func (BusRoute) IsEmptyPayload

func (route BusRoute) IsEmptyPayload(payload string) error

IsEmptyPayload checks if the request payload is empty and if it is, it will return an error message.

func (BusRoute) SetFilter

func (route BusRoute) SetFilter() BusRouteFilter

SetFilter sets and returns the fields of the bus route that will be used in filtering data.

func (*BusRoute) SetValues

func (route *BusRoute) SetValues()

SetValues automatically generates the Bus Route ID as your primary key, and set the date it was created as unix epoch time.

type BusRouteFilter

type BusRouteFilter struct {
	BusID     string // The unique Bus ID
	BusUnitID string // The Bus Unit ID for the identification of specific bus unit route
	Active    *bool  // Defines if the bus is available for that route
	Departure string // Expected departure time on the starting point and in 24-hour format
	Arrival   string // Expected arrival time on the destination and in 24-hour format
	FromRoute string // Indicating the starting point of a bus
	ToRoute   string // Indicating the destination of bus
}

BusRouteFilter contains the fields of a bus route that can be used for filtering.

type BusUnit

type BusUnit struct {
	BusID       string `json:"bus_id" dynamodbav:"bus_id"`                                     // The Bus ID as the sort key
	Code        string `json:"code" dynamodbav:"code"`                                         // Code is a uniqe identification of a bus unit
	Active      *bool  `json:"active" dynamodbav:"active"`                                     // Whether the bus unit is on trip and accepts a true or false value
	MinCapacity *int   `json:"min_capacity" dynamodbav:"min_capacity"`                         // The minimum number of passenger of a bus unit
	MaxCapacity *int   `json:"max_capacity" dynamodbav:"max_capacity"`                         // The maximum number of passenger of a bus unit
	DateCreated string `json:"date_created,omitempty" dynamodbav:"date_created,omitemptyelem"` // The date it was created as unix epoch time
}

BusUnit represents a bus company's active bus unit and the specific unit's capacity. The "Active" is set to a boolean pointer for us to validate if it is set by checking if the value is "nil" since it will be the default value if it is uninitialized.

Reference: https://stackoverflow.com/a/43351386/19679222

The "dynamodbav" struct tag can be used to control the value that will be marshaled into a AttributeValue.

func (BusUnit) Error

func (unit BusUnit) Error(err error, code, message string, kv ...utility.KVP)

Error sets the default key-value pair.

func (BusUnit) IsEmptyPayload

func (unit BusUnit) IsEmptyPayload(payload string) error

IsEmptyPayload checks if the request payload is empty and if it is, it will return an error message.

func (*BusUnit) SetValues

func (unit *BusUnit) SetValues()

SetValues automatically generates the Bus Unit ID as your primary key and set the date it was created as unix epoch time.

Example:

date_created: 1658837116

func (BusUnit) ValidateMaximumCapacity

func (unit BusUnit) ValidateMaximumCapacity(min_capacity int) error

ValidateMaximumCapacity validates if the amount set for the maximum capacity is not a negative amount or less than the existing minimum capacity.

func (BusUnit) ValidateMinimumCapacity

func (unit BusUnit) ValidateMinimumCapacity() error

ValidateMinimumCapacity validates if the amount set for the minimum capacity is not a negative amount or less than the minimum capacity requirement of the Bus Unit.

type FailedBus

type FailedBus struct {
	Failed []struct {
		Bus    Bus    `json:"bus"`
		Reason string `json:"reason,omitempty"`
	} `json:"failed"`
}

FailedBus represents the failed bus that needs to be re-processed.

func (*FailedBus) SetFailedBus

func (failed *FailedBus) SetFailedBus(bus Bus, reason string)

SetFailedBus sets the failed bus information transaction by passing the Bus and the reason why it failed.

type FailedBusUnits

type FailedBusUnits struct {
	Failed []struct {
		Unit   BusUnit `json:"unit"`
		Reason string  `json:"reason,omitempty"`
	} `json:"failed"`
}

FailedBusUnits represents the failed bus unit that needs to be re-processed.

func (*FailedBusUnits) SetFailedUnits

func (failed *FailedBusUnits) SetFailedUnits(unit BusUnit, reason string)

SetFailedUnits sets the failed bus units information transaction by passing the Bus Unit and the reason why it failed.

type User

type User struct {
	ID           string `json:"id" dynamodbav:"id"`                                             // The unique user ID and the sort key
	UserType     string `json:"user_type" dynamodbav:"user_type"`                               // The type of the user account (either ADMIN or CUSTOMER)
	FirstName    string `json:"first_name" dynamodbav:"first_name"`                             // The first name of the user
	LastName     string `json:"last_name" dynamodbav:"last_name"`                               // The last name of the user
	Username     string `json:"username" dynamodbav:"username"`                                 // The username of the user account and the primary key
	Password     string `json:"password,omitempty" dynamodbav:"password"`                       // THe user security password for the account
	Address      string `json:"address" dynamodbav:"address"`                                   // The user address
	Email        string `json:"email" dynamodbav:"email"`                                       // The user e-mail address
	MobileNumber string `json:"mobile_number" dynamodbav:"mobile_number"`                       // The user phone
	DateCreated  string `json:"date_created,omitempty" dynamodbav:"date_created,omitemptyelem"` // The date it was created
	LastLogin    string `json:"last_login,omitempty" dynamodbav:"last_login,omitemptyelem"`     // The last login session of the user
}

User contains the user account information.

The "dynamodbav" struct tag can be used to control the value that will be marshaled into a AttributeValue.

func (User) Error

func (user User) Error(err error, code, message string, kv ...utility.KVP)

Error sets the default key-value pair.

func (User) IsEmptyPayload

func (user User) IsEmptyPayload(payload string) error

IsEmptyPayload checks if the request payload is empty and if it is, it will return an error message.

func (User) LastLogIn

func (user User) LastLogIn() string

LastLogIn returns the current time when the user logged in.

func (*User) SetValues

func (user *User) SetValues()

SetValues automatically generates the User ID as your primary key, set the user type and the date it was created.

Example:

id: CSTMR-854980
user_type: CUSTOMER
date_created: 1685498070

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL