ddbHandler

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2024 License: GPL-3.0 Imports: 10 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DDBHandler

type DDBHandler struct {
	// contains filtered or unexported fields
}

=============================================================================================================================== TYPE DEFINITIONS ===============================================================================================================================

func New

func New(svc dynamodbiface.DynamoDBAPI, concertsTable string, ordersTable string) DDBHandler

New takes the AWS DynamoDBAPI interface, the name of the concerts and orders tables (both strings) and returns a newly created DDBHandler struct

func (DDBHandler) CreateOrderInTable

func (d DDBHandler) CreateOrderInTable(order paymentHandler.Order) (err error)

CreateOrderInTable takes the paymentRequest struct, generates a new payment references, checks for uniqueness and creates an entry in the orders table. Returns an error if it fails at any point

func (DDBHandler) GenerateOrderReference

func (d DDBHandler) GenerateOrderReference(size uint8) (ref string)

GenerateOrderReference takes a uint8 indicating the num of random characters to generate. In an infinite loop it calls the generateRandomString function, check if the returned string is unique in the dynamoDB table and breaks and returns the random in the form of a string once a unique string is found

func (DDBHandler) GetConcertFromTable

func (d DDBHandler) GetConcertFromTable(concertID string) (concert *databaseHandler.Concert, err error)

GetConcertFromTable retrieves a specific concert from the dynamoDB table, returns a pointer to a databaseHandler.Concert struct and error (nil if successful).

func (DDBHandler) GetConcertsFromTable

func (d DDBHandler) GetConcertsFromTable() (concerts []databaseHandler.Concert, err error)

GetConcertsFromTable gets all upcoming concerts from the dynamoDB table, returning a slice of databaseHandler.Concert structs and an error (nil if successful).

func (DDBHandler) GetOrderFromTable

func (d DDBHandler) GetOrderFromTable(concertId string, ref string) (order *paymentHandler.Order, err error)

GetOrderFromTable takes a reference id and returns an paymentHandler.Order struct, or nil if the order does not exist. The second return type is error which will be nil if successful or not nil if an error occur retriving the entry

func (DDBHandler) GetOrdersByOrderReferenceFromTable

func (d DDBHandler) GetOrdersByOrderReferenceFromTable(ref string) (orders []paymentHandler.Order, err error)

GetOrdersByOrderReferenceFromTable takes an order reference and return a slice of orders, or an error if this failed

func (DDBHandler) ReformatDateTimeAndTickets

func (d DDBHandler) ReformatDateTimeAndTickets(concert *databaseHandler.Concert) (err error)

ReformatDateTimeAndTickets takes a pointer to a databaseHandler.Concert struct, modifying it in-place to convert DateTime epoch into a date and time string, and converts num of tickets sold into num of tickets available. Returns an error if nil is passed

func (DDBHandler) UpdateOrderInTable

func (d DDBHandler) UpdateOrderInTable(concertID string, reference string, newStatus string) (err error)

UpdateOrderInTable takes a concertID and payment reference and new status value, fetches the order from DynamoDB, and updates the order with the new status value. Returns an error if unsuccessful, or nil if successful

func (DDBHandler) UpdateTicketsSoldInTable

func (d DDBHandler) UpdateTicketsSoldInTable(concertID string, ticketsSold uint16) (err error)

UpdateTicketsSoldInTable takes the concertID and the number of tickets sold, fetches the concert from DynamoDB, then increments the ticketsSold field with the provided parameter

Jump to

Keyboard shortcuts

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