entity

package
v0.0.0-...-266b4ff Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultAPIVersion = "1.0"
	DefaultStartIndex = 1
)

Variables

This section is empty.

Functions

func RespondWithJSON

func RespondWithJSON(w http.ResponseWriter, r *http.Request, msg string, err string)

RespondWithJSON message into JSON as http response

func RespondWithTokenJSON

func RespondWithTokenJSON(w http.ResponseWriter, r *http.Request, msg string, err string)

func ValidateRestaurant

func ValidateRestaurant(restaurant *Restaurant) []error

ValidateRestaurant Validates such restaurant fields as ID, Score, Category and Price Range

func ValidateScore

func ValidateScore(score float64) error

ValidateScore Validates if score for the restaurant is in a valid range

Types

type Cart

type Cart struct {
	UserID       string    `dynamo:"user_id"`
	ItemID       string    `dynamo:"product_id"`
	Item         Menu      `dynamo:"item"`
	Quantity     int64     `dynamo:"quantity"`
	PricePerUnit float64   `dynamo:"price"`
	TotalPrice   float64   `dynamo:"total_price"`
	AddedAt      time.Time `dynamo:"added_at"`
}

Cart is a struct for user's cart management, which entity values stored in dynamoDB table

type CustomResponse

type CustomResponse struct {
	Error string `json:"error,omitempty"`
	Data  any    `json:"data,omitempty"`
}
type Menu struct {
	ID           string    `gorm:"primaryKey;autoIncrement:true"`
	RestaurantID int       `json:"restaurant_id" gorm:"index:idx_restaurant_id"`
	Category     string    `json:"category"`
	Name         string    `json:"name"`
	Description  string    `json:"description"`
	Price        string    `json:"price"`
	CreatedAt    time.Time `json:"-"`
	UpdatedAt    time.Time `json:"-"`
}

A Menu represents menu entity which is a menu of the restaurant

type Order

type Order struct {
	OrderID         string      `json:"order_id" dynamo:"order_id"`
	UserID          string      `dynamo:"user_id"`
	Items           []Cart      `dynamo:"cart"`
	TotalOrderPrice float64     `dynamo:"total_price"`
	AddedAt         time.Time   `dynamo:"added_at"`
	Status          OrderStatus `dynamo:"status"`
}

Order struct is takes items from user's cart and transforms to order

type OrderIDRequest

type OrderIDRequest struct {
	OrderID string `json:"order_id"`
}

OrderIDRequest struct for deserialization json body of order ID

type OrderStatus

type OrderStatus int

OrderStatus numerical value of order status

const (
	InProcess OrderStatus = iota + 1
	Shipped
	Delivered
)

OrderStatus is enum representing actual status of order

func (OrderStatus) EnumIndex

func (status OrderStatus) EnumIndex() int

EnumIndex returns numerical value of order status

func (OrderStatus) String

func (status OrderStatus) String() string

String returns string value of order status

type PaginatedData

type PaginatedData struct {
	Limit      int   `json:"limit,omitempty"`
	Offset     int   `json:"offset,omitempty"`
	TotalRows  int64 `json:"total_rows"`
	TotalPages int   `json:"total_pages"`
	Items      any   `json:"items"`
}

type PaginatedResponse

type PaginatedResponse struct {
	APIVersion string        `json:"apiVersion"`
	Data       PaginatedData `json:"data,omitempty"`
}

func NewPaginatedResponse

func NewPaginatedResponse(pagination *utils.Pagination) *PaginatedResponse

type QuantityItemRequest

type QuantityItemRequest struct {
	Quantity int64 `json:"quantity"`
}

QuantityItemRequest struct for deserialization json body of quantity

type Restaurant

type Restaurant struct {
	ID          int64   `json:"id"`
	Position    int64   `json:"position"`
	Name        string  `json:"name"`
	Score       float64 `json:"score"`
	Ratings     int64   `json:"ratings"`
	Category    string  `json:"category"`
	PriceRange  string  `json:"price_range"`
	FullAddress string  `json:"full_address"`
	//TODO: Add additional validation for the zip range
	ZipCode string `json:"zip_code"`
	// TODO: add validation
	Lat string `json:"lat"`
	// TODO: add validation
	Lng       string    `json:"lng"`
	CreatedAt time.Time `json:"-"`
	UpdatedAt time.Time `json:"-"`
}

Restaurant represents information about the restaurant entity

type TokenData

type TokenData struct {
	Token string `json:"token"`
}

type User

type User struct {
	UserID    string    `json:"user_id" gorm:"type:uuid;default:uuid_generate_v4();primaryKey"`
	Email     string    `json:"email"`
	Password  string    `json:"password"`
	Role      string    `json:"role"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

User represents a user entity/

func (*User) Validate

func (user *User) Validate() error

Validate validates the user entity.

Jump to

Keyboard shortcuts

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