utils

package
v0.0.0-...-440c973 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2023 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateID

func GenerateID() string

GenerateID generates an ID in the format of [A-Z]{2}[0-9]{8}

func GetAttachmentIDFromVars

func GetAttachmentIDFromVars(vars map[string]string) string

GetAttachmentIDFromVars returns the attachment id from the supplied request vars

func GetPractitionerIDFromVars

func GetPractitionerIDFromVars(vars map[string]string) string

GetPractitionerIDFromVars returns the practitioner id from the supplied request vars.

func GetTransactionIDFromVars

func GetTransactionIDFromVars(vars map[string]string) string

GetTransactionIDFromVars returns the transaction id from the supplied request vars.

func IsDateBeforeDate

func IsDateBeforeDate(beforeDate string, afterDate string) (bool, error)

IsDateBeforeDate check if before date is earlier than after date

func IsDateBetweenIncorporationAndNow

func IsDateBetweenIncorporationAndNow(dateToTest string, incorporationDate string) (bool, error)

IsDateBetweenIncorporationAndNow is a helper function to check if the date supplied is in the future or before the incorporation date

func IsDateInFuture

func IsDateInFuture(dateToTest string) (bool, error)

IsDateInFuture check if the date supplied is after today

func ResponseTypeToStatus

func ResponseTypeToStatus(responseType string) (int, error)

ResponseTypeToStatus converts a response type to an http status

func Validate

func Validate(data interface{}) string

Validate takes in any request object and checks whether it has met the validation criteria according to the annotations on that object. If the object is invalid, the method returns a human-readable string which can then be added to the message response for the API user

func ValidateDate

func ValidateDate(dateToTest string) (time.Time, error)

ValidateDate check date is in a valid date format

func ValidateTransaction

func ValidateTransaction(helperService HelperService, req *http.Request, res http.ResponseWriter, startMessage string, checkIfTransactionClosedFn func(transactionID string, req *http.Request) (bool, error, int)) (string, bool)

func WriteJSONWithStatus

func WriteJSONWithStatus(w http.ResponseWriter, r *http.Request, data interface{}, status int)

WriteJSONWithStatus writes the interface as a json string with the supplied status.

Types

type HelperService

type HelperService interface {
	HandleTransactionIdExistsValidation(w http.ResponseWriter, req *http.Request, transactionID string) (bool, string)
	HandleTransactionNotClosedValidation(w http.ResponseWriter, req *http.Request, transactionID string, isTransactionClosed bool, httpStatus int, err error) bool
	HandleBodyDecodedValidation(w http.ResponseWriter, req *http.Request, transactionID string, err error) bool
	HandleMandatoryFieldValidation(w http.ResponseWriter, req *http.Request, err string) bool
	HandleAttachmentValidation(w http.ResponseWriter, req *http.Request, transactionID string, attachment models.AttachmentResourceDao, err error) bool
	HandleAttachmentTypeValidation(w http.ResponseWriter, req *http.Request, responseMessage string, err error) int
	HandleEtagGenerationValidation(err error) bool
	HandleCreateResourceValidation(w http.ResponseWriter, req *http.Request, statusCode int, err error) bool
	// GenerateEtag generates a random etag which is generated on every write action
	GenerateEtag() (string, error)
}

HelperService interface declares

func NewHelperService

func NewHelperService() HelperService

NewHelperService will create a new instance of the HelperService interface.

Jump to

Keyboard shortcuts

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