Documentation
¶
Index ¶
- Variables
- func CalculateRate(scores []int) int
- func ChangeMenuField(filter bson.D, update bson.D) (*mongo.UpdateResult, error)
- func CloseDB() error
- func ConnectDB()
- func CreateGeoIndex(name string, Collection *mongo.Collection)
- func CreateIndex(name string, Collection *mongo.Collection)
- func CustomerLoginCheck(email string, password string, device Device) (*TokenResponse, *ErrorResponse)
- func DeleteReview(id primitive.ObjectID) (*mongo.DeleteResult, error)
- func DriverLoginCheck(email string, password string, device Device) (*TokenResponse, *ErrorResponse)
- func GetDrivers(query bson.M, projection []string) ([]map[string]interface{}, error)
- func GoogleLogin(data GoogleUserInfoType) (*TokenResponse, *ErrorResponse)
- func IsDup(err error) bool
- func MerchantLoginCheck(email string, password string, device Device) (*TokenResponse, *ErrorResponse)
- func ProtectFields(fields []string) primitive.D
- func ReviewMenu(id primitive.ObjectID)
- func ReviewUpdate(filter bson.M, update bson.D) (*mongo.UpdateResult, error)
- func TokenGenerate(email string, id primitive.ObjectID, tokenVersion int) (*TokenResponse, *ErrorResponse)
- func UpdateCustomer(query bson.M, change bson.D) (*mongo.UpdateResult, error)
- func UpdateDriver(query bson.M, change bson.D) (*mongo.UpdateResult, error)
- func UpdateMerchant(query bson.M, change bson.D) (*mongo.UpdateResult, error)
- func UpdateOrder(query bson.M, change bson.D) (*mongo.UpdateResult, error)
- type AccountMetadata
- type ActiveDays
- type Attributes
- type Badge
- type Category
- type Coupon
- type Customer
- func (c *Customer) BeforeSave() error
- func (c *Customer) ChangeEmail(OldEmail string, NewEmail string) (*mongo.UpdateResult, *ErrorResponse)
- func (c *Customer) ChangeMetadataLogin() error
- func (c *Customer) ChangePassword(OldPassword string, NewPassword string) *ErrorResponse
- func (c *Customer) Delete() (*mongo.DeleteResult, error)
- func (c *Customer) GetAll() ([]*Customer, error)
- func (c *Customer) GetById() error
- func (c *Customer) Save() (*mongo.InsertOneResult, error)
- func (c *Customer) Update() (*mongo.UpdateResult, error)
- type Device
- type Driver
- func (d *Driver) BeforeSave() error
- func (d *Driver) ChangeEmail(OldEmail string, NewEmail string) (*mongo.UpdateResult, *ErrorResponse)
- func (d *Driver) ChangeMetadataLogin() error
- func (d *Driver) ChangePassword(OldPassword string, NewPassword string) *ErrorResponse
- func (d *Driver) ChangePhone(OldPhone string, NewPhone string) (*mongo.UpdateResult, error)
- func (d *Driver) Delete() (*mongo.DeleteResult, error)
- func (d *Driver) GetById() error
- func (d *Driver) Save() (*mongo.InsertOneResult, error)
- func (d *Driver) Update() (*mongo.UpdateResult, error)
- type ErrorResponse
- type GoogleUserInfoType
- type Item
- type Location
- type Menu
- func (m *Menu) Create() (*mongo.InsertOneResult, error)
- func (m *Menu) Delete() (*mongo.DeleteResult, error)
- func (m Menu) GetAll() ([]*Menu, error)
- func (m *Menu) GetById() error
- func (m Menu) GetFromMerchant() ([]*Menu, error)
- func (m Menu) SetImages() (*mongo.UpdateResult, error)
- func (m *Menu) Update() (*mongo.UpdateResult, error)
- type Merchant
- func (m *Merchant) BeforeSave() error
- func (m *Merchant) ChangeBusinessPhone(OldPhone string, NewPhone string) (*mongo.UpdateResult, error)
- func (m *Merchant) ChangeMetadataLogin() error
- func (m *Merchant) ChangePassword(OldPassword string, NewPassword string) *ErrorResponse
- func (m *Merchant) Delete() (*mongo.DeleteResult, error)
- func (m *Merchant) GetAll() ([]*Merchant, error)
- func (m *Merchant) GetById() error
- func (m *Merchant) Save() (*mongo.InsertOneResult, *ErrorResponse)
- func (m *Merchant) Update() (*mongo.UpdateResult, error)
- type Metadata
- type Order
- func (o *Order) BeforeSave() *ErrorResponse
- func (o *Order) CalculatePrice()
- func (o *Order) ExtractItems() *ErrorResponse
- func (o *Order) GetById() error
- func (o *Order) GetByLocation(location []float64, maxdist int64, mindist int64) ([]*Order, error)
- func (o *Order) PickuPExtract() *ErrorResponse
- func (o *Order) PlaceOrder() (*mongo.InsertOneResult, *ErrorResponse)
- type Rate
- type Review
- type Setting
- type TokenResponse
- type Vehicle
Constants ¶
This section is empty.
Variables ¶
View Source
var ( Mongoclient *mongo.Client Ctx context.Context CustomerCollection *mongo.Collection DriverCollection *mongo.Collection OrderCollection *mongo.Collection MerchantCollection *mongo.Collection MenuCollection *mongo.Collection ReviewCollection *mongo.Collection CategoryCollection *mongo.Collection )
TODO: support db validation and error handling which almost return description what error happened
View Source
var CommonProtoctedFields []string = []string{"password", "device", "metadata.token_version", "metadata.provider"}
View Source
var Roles []string = []string{
"customer",
"driver",
"merchant",
}
Functions ¶
func CalculateRate ¶
Calculate all score and return five 5-star rating score i.e 2.9 ,3.7 etc.
func ChangeMenuField ¶
func CreateGeoIndex ¶
func CreateGeoIndex(name string, Collection *mongo.Collection)
func CreateIndex ¶
func CreateIndex(name string, Collection *mongo.Collection)
func CustomerLoginCheck ¶
func CustomerLoginCheck(email string, password string, device Device) (*TokenResponse, *ErrorResponse)
func DeleteReview ¶
func DeleteReview(id primitive.ObjectID) (*mongo.DeleteResult, error)
delte review
func DriverLoginCheck ¶
func DriverLoginCheck(email string, password string, device Device) (*TokenResponse, *ErrorResponse)
func GetDrivers ¶
func GoogleLogin ¶
func GoogleLogin(data GoogleUserInfoType) (*TokenResponse, *ErrorResponse)
func MerchantLoginCheck ¶
func MerchantLoginCheck(email string, password string, device Device) (*TokenResponse, *ErrorResponse)
func ProtectFields ¶
func ReviewMenu ¶
func ReviewUpdate ¶
Update review
func TokenGenerate ¶
func TokenGenerate(email string, id primitive.ObjectID, tokenVersion int) (*TokenResponse, *ErrorResponse)
func UpdateCustomer ¶
func UpdateDriver ¶
func UpdateMerchant ¶
func UpdateOrder ¶
Types ¶
type AccountMetadata ¶
type AccountMetadata struct {
TokenVersion int `bson:"token_version" json:"-"`
CreatedAt time.Time `json:"created_at" bson:"created_at"`
UpdatedAt time.Time `json:"-" bson:"updated_at"`
LasLogin time.Time `bson:"last_login" json:"-"`
WebhookEndpoint string `json:"webhook_endpoint" bson:"webhook_endpoint"`
Provider string `bson:"provider" json:"-"` // google , email , facebook
}
type ActiveDays ¶
type Attributes ¶
type Attributes struct {
Volume float64 `bson:"volume" json:"volume"`
Height float64 `bson:"height" json:"height"`
Width float64 `bson:"width" json:"width"`
Length float64 `bson:"length" json:"length"`
}
TODO: support attributes for basic types and custom type for menues. all this values are represented as cm or centimeter as unit type
type Category ¶
type Coupon ¶
type Coupon struct {
Token string `json:"token" bson:"token"`
Rate uint `json:"rate" bson:"rate"` // percentage of the discount
TimeOperatorStart time.Time `bson:"time_operation_start" json:"time_operation_start"` // Datetime Started
TimeOperatorEnd time.Time `bson:"time_operation_end" json:"time_operation_end"` // Datetime End coupon expires
}
type Customer ¶
type Customer struct {
Id primitive.ObjectID `bson:"_id,omitempty" json:"id,omitempty"`
Email string `bson:"email,omitempty" json:"email"`
FamilyName string `bson:"family_name,omitempty" json:"family_name,omitempty"`
GivenName string `bson:"given_name" json:"given_name"`
Address string `bson:"address" json:"address"`
Metadata AccountMetadata `bson:"metadata" json:"metadata"`
Profile string `bson:"profile" json:"profile"`
Password string `bson:"password" json:"-"`
Device Device `bson:"device" json:"-"`
Phone string `bson:"phone" json:"phone"`
Preference []string `bson:"preference" json:"preference"`
}
func (*Customer) BeforeSave ¶
func (*Customer) ChangeEmail ¶
func (c *Customer) ChangeEmail(OldEmail string, NewEmail string) (*mongo.UpdateResult, *ErrorResponse)
func (*Customer) ChangeMetadataLogin ¶
func (*Customer) ChangePassword ¶
func (c *Customer) ChangePassword(OldPassword string, NewPassword string) *ErrorResponse
type Driver ¶
type Driver struct {
Id primitive.ObjectID `bson:"_id,omitempty" json:"id,omitempty"`
Password string `json:"-" bson:"password"`
Email string `json:"email" bson:"email"`
Phone string `json:"phone" bson:"phone"`
GivenName string `json:"given_name" bson:"given_name"`
Age primitive.DateTime `json:"age" bson:"age"`
Address string `json:"address" bson:"address"`
Metadata AccountMetadata `json:"metadata" bson:"metadata"`
Profile string `json:"profile" bson:"profile"`
Device Device `json:"-" bson:"device"`
Rate Rate `json:"rate" bson:"rate"`
Location Location `json:"location" bson:"location"`
Satus bool `json:"status" bson:"status"` // true available, false unavailable
Vehicle Vehicle `json:"vehicle" bson:"vehicle"`
}
func GetByDriversLocation ¶
func (*Driver) BeforeSave ¶
func (*Driver) ChangeEmail ¶
func (d *Driver) ChangeEmail(OldEmail string, NewEmail string) (*mongo.UpdateResult, *ErrorResponse)
func (*Driver) ChangeMetadataLogin ¶
func (*Driver) ChangePassword ¶
func (d *Driver) ChangePassword(OldPassword string, NewPassword string) *ErrorResponse
func (*Driver) ChangePhone ¶
type ErrorResponse ¶
func AssignOrderToDriver ¶
func AssignOrderToDriver(orderId primitive.ObjectID, driverId primitive.ObjectID) (*mongo.UpdateResult, *ErrorResponse)
func DBErrorHandler ¶
func DBErrorHandler(err error) *ErrorResponse
func DropOrder ¶
func DropOrder(orderId primitive.ObjectID, driverId string) (*mongo.UpdateResult, *ErrorResponse)
drop the order like driver decline order after he accept
func (*ErrorResponse) Error ¶
func (e *ErrorResponse) Error(c *gin.Context)
type GoogleUserInfoType ¶
type GoogleUserInfoType struct {
Id string `json:"id"`
Email string `json:"email"`
VerifiedEmail bool `json:"verified_email"`
Name string `json:"name"` // full name
GivenName string `json:"given_name"` // first name
FamilyName string `json:"family_name"` // last name
Picture string `json:"picture"`
Locale string `json:"locale"`
}
type Menu ¶
type Menu struct {
Id primitive.ObjectID `bson:"_id,omitempty" json:"id,omitempty"`
Title string `json:"title" bson:"title" binding:"max=30,min=1"` // Burger
Description string `json:"description" bson:"description"` // Chicken fries contains
Status string `json:"status" bson:"status"` // available , unavailable , banned
Category string `json:"category" bson:"category"` // fast food , drink ,
Images []string `json:"images" bson:"images"` // Images of the product urls
Price uint `json:"price" bson:"price"` // the price of the product is represented as cents 99 = $0.99
Attributes Attributes `json:"attributes" bson:"attributes"`
Metadata Metadata `json:"metadata" bson:"metadata"`
MerchantExternalId string `json:"merchant_external_id" bson:"merchant_external_id"`
Reciepe []string `json:"reciepe" bson:"reciepe"` // floor , meat , egg etc.
Barcode string `json:"-" bson:"barcode"` // if this needed
EstimateTime int `json:"estimate_time" bson:"estimate_time"` // estimate of preparation and cooking time in seconds
ServiceAvailability []ActiveDays ` json:"service_availablity" bson:"service_availablity"`
Likes uint `json:"likes" bson:"likes"` //
}
func GetCategoryMenues ¶
func (Menu) GetFromMerchant ¶
type Merchant ¶
type Merchant struct {
Id primitive.ObjectID `bson:"_id,omitempty" json:"id,omitempty"` // 63f642ac061b6f5f089b3a65
BusinessName string `bson:"business_name" json:"business_name"`
BusinessEmail string `json:"business_email" bson:"business_email"`
BusinessPhone string `bson:"business_phone" json:"business_phone"`
Location Location `bson:"location" json:"location"`
Address string `bson:"address" json:"address"`
Metadata AccountMetadata `bson:"metadata" json:"metadata"`
Password string `json:"-" bson:"password"`
Profile string `json:"profile" bson:"profile"`
Device Device `json:"-" bson:"device"`
Rate Rate `json:"rate" bson:"rate"`
Badge Badge `json:"badge" bson:"badge"`
Closed bool `json:"closed" bson:"closed"`
ActiveDays []ActiveDays `json:"active_days" bson:"active_days"`
Generes []string `bson:"generes" json:"generes"` //Fast food.Fast casual.Casual dining / Slow Casual.Premium casual.Family style.Fine dining.
Likes uint `bson:"likes" json:"likes"`
Popular uint `bson:"popular" json:"popular"`
}
func FilterMerchants ¶
func GetMerchantByLocation ¶
func (*Merchant) BeforeSave ¶
func (*Merchant) ChangeBusinessPhone ¶
func (*Merchant) ChangeMetadataLogin ¶
func (*Merchant) ChangePassword ¶
func (m *Merchant) ChangePassword(OldPassword string, NewPassword string) *ErrorResponse
func (*Merchant) Save ¶
func (m *Merchant) Save() (*mongo.InsertOneResult, *ErrorResponse)
type Order ¶
type Order struct {
Id primitive.ObjectID `bson:"_id,omitempty" json:"id,omitempty"`
DisplayId string `bson:"display_id" json:"display_id"`
OrderValue uint `json:"order_value" bson:"order_value" ` // Order value is represented as cents 199 = $19.9
Type string `json:"type" bson:"type"` // pickup or delivery order
Items []Item `json:"items" bson:"items"`
DropOffPhone string `json:"dropoff_phone" bson:"dropoff_phone"`
DropOffExteranlId string `json:"dropoff_external_id" bson:"dropoff_external_id"`
DropOffContactName string `json:"dropoff_contact_name" bson:"dropoff_contact_name"`
DropOffTimeEstimated int `json:"dropoff_time_estimated" bson:"dropoff_time_estimated"`
DropOffTime time.Time `json:"dropoff_time" bson:"dropoff_time"`
DropOffAddress string `json:"dropoff_address" bson:"dropoff_address"` // address 901 Market Street 6th Floor San Francisco, CA 94103
DroOffLocation Location `json:"dropoff_location" bson:"dropoff_location"` // location cordinates. float([123.1312343,-37.2144343])
DropOffInstruction string `json:"dropoff_instructions" bson:"dropoff_instructions"`
Stage string `json:"stage" bson:"stage"` // placed,accepted,preparing,ready,pickuped,deleivered,cancelled.
ActionIfUndeliverable string `json:"action_if_undeliverable" bson:"action_if_undeliverable"` // return_to_merchant // destroy
PickupAddress string `json:"pickup_address" bson:"pickup_address"`
PickUpExternalId string `bson:"pickup_external_id" json:"pickup_external_id"`
PickUpName string `bson:"pickup_name" json:"pickup_name"`
PickUpPhone string `bson:"pickup_phone" json:"pickup_phone"`
PickUpLocation Location `bson:"pickup_location" json:"pickup_location"`
PickupTime time.Time `bson:"pickup_time" json:"pickup_time"`
PickupEstimatedTime int `bson:"pickup_estimated_time" json:"pickup_estimated_time"` // seconds
DriverPhone string `bson:"driver_phone" json:"driver_phone"`
DriverAllowedVehicles []string `json:"driver_allowed_vehicles" bson:"driver_allowed_vehicles" ` // car , motorcycle , walking
DriverExternalId string `bson:"driver_external_id" json:"driver_external_id"`
Metadata Metadata `bson:"metadata" json:"metadata"`
CancelReason string `bson:"cancel_reason" json:"cancel_reason"`
}
func (*Order) BeforeSave ¶
func (o *Order) BeforeSave() *ErrorResponse
func (*Order) CalculatePrice ¶
func (o *Order) CalculatePrice()
func (*Order) ExtractItems ¶
func (o *Order) ExtractItems() *ErrorResponse
func (*Order) GetByLocation ¶
func (*Order) PickuPExtract ¶
func (o *Order) PickuPExtract() *ErrorResponse
func (*Order) PlaceOrder ¶
func (o *Order) PlaceOrder() (*mongo.InsertOneResult, *ErrorResponse)
places order
type Review ¶
type Review struct {
Id primitive.ObjectID `bson:"_id,omitempty" json:"id,omitempty"` // 63f642ac061b6f5f089b3a65
Type string `bson:"type" json:"type"` // REVIEW_MERCHANT , REVIEW_DRIVER , REVIEW_MENU
OrderId string `bson:"order_id" json:"order_id"`
From string `bson:"from" json:"from"`
Message string `bson:"message" json:"message"`
Rate uint `bson:"rate" json:"rate"`
ExternalId string `bson:"external_id" json:"external_id"`
Options []string `bson:"options" json:"options"`
Metadata Metadata `bson:"metadata" json:"metadata"`
}
type TokenResponse ¶
Click to show internal directories.
Click to hide internal directories.