services

package
v0.0.0-...-181e07b Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2023 License: MPL-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AddProductRequest

type AddProductRequest struct {
	Name            string   `json:"name" form:"name"`
	Description     string   `json:"description" form:"description"`
	Category        string   `json:"category" form:"category"`
	Ingredients     string   `json:"ingredients" form:"ingredients"`
	NutritionalInfo string   `json:"nutritional_info" form:"nutritional_info"`
	ImageURLs       []string `json:"image_urls" form:"image_urls"`
}

AddProductRequest represents the request body for the AddProduct endpoint.

type AddProductResponse

type AddProductResponse struct {
	Message   string `json:"message"`
	ProductID int    `json:"product_id"`
}

type AddProductWeightRequest

type AddProductWeightRequest struct {
	Weight            int     `json:"weight" form:"weight"`
	Price             float64 `json:"price" form:"price"`
	StockAvailability int     `json:"stock" form:"stock"`
	Measurement       string  `json:"measurement" form:"measurement"`
}

AddProductWeightRequest represents the request body for adding a new weight variant

type AddToCartRequest

type AddToCartRequest struct {
	UserID          int `json:"user_id"`
	ProductWeightID int `json:"product_weight_id"`
	Quantity        int `json:"quantity"`
}

AddToCartRequest represents the request payload for adding a product to the cart

type AddressService

type AddressService struct {
	DB *db.Repository
}

AddressService represents a service for address-related operations

func NewAddressService

func NewAddressService(db *db.Repository) *AddressService

NewAddressService creates a new AddressService instance

func (*AddressService) CreateAddress

func (as *AddressService) CreateAddress(w http.ResponseWriter, r *http.Request)

CreateAddress creates a new address @Summary Create a new address @Tags Addresses @Accept json @Produce json @Param address body models.Address true "Address object" @Success 200 {object} CreateAddressResponse "Address created successfully" @Failure 400 {object} ErrorResponse "Invalid request body" @Failure 500 {object} ErrorResponse "Failed to create address" @Router /addresses [post]

func (*AddressService) DeleteAddress

func (as *AddressService) DeleteAddress(w http.ResponseWriter, r *http.Request)

DeleteAddress deletes an address DeleteAddress deletes an address @Summary Delete an address @Tags Addresses @Param id path string true "Address ID" @Success 200 {string} string "Address deleted successfully" @Failure 500 {object} ErrorResponse "Failed to delete address" @Router /addresses/{id} [delete]

func (*AddressService) GetAddressByID

func (as *AddressService) GetAddressByID(w http.ResponseWriter, r *http.Request)

GetAddressByID retrieves an address by ID @Summary Retrieve an address by ID @Tags Addresses @Accept json @Produce json @Param id path string true "Address ID" @Success 200 {object} models.Address "Address retrieved successfully" @Failure 500 {object} ErrorResponse "Failed to retrieve address" @Router /addresses/{id} [get]

func (*AddressService) GetAddressesByUserID

func (as *AddressService) GetAddressesByUserID(w http.ResponseWriter, r *http.Request)

GetAddressesByUserID fetches all addresses for a given user ID @Summary Fetch all addresses for a given user ID @Tags Addresses @Accept json @Produce json @Param user_id path string true "User ID" @Success 200 {array} models.Address "Addresses retrieved successfully" @Failure 400 {object} ErrorResponse "Invalid user ID" @Failure 500 {object} ErrorResponse "Failed to get addresses" @Router /users/{user_id}/addresses [get]

func (*AddressService) RegisterRoutes

func (as *AddressService) RegisterRoutes(r *mux.Router)

RegisterRoutes registers the address service routes

func (*AddressService) UpdateAddress

func (as *AddressService) UpdateAddress(w http.ResponseWriter, r *http.Request)

UpdateAddress updates an address @Summary Update an address @Tags Addresses @Accept json @Produce json @Param id path string true "Address ID" @Param address body models.Address true "Address object" @Success 200 {string} string "Address updated successfully" @Failure 400 {object} ErrorResponse "Invalid request body" @Failure 500 {object} ErrorResponse "Failed to update address" @Router /addresses/{id} [put]

type CartService

type CartService struct {
	DB *db.Repository
}

CartService handles the cart related operations

func NewCartService

func NewCartService(db *db.Repository) *CartService

func (*CartService) AddToCart

func (cs *CartService) AddToCart(w http.ResponseWriter, r *http.Request)

AddToCart adds a product to the user's cart @Summary Add a product to the cart @Tags Cart @Accept json @Produce json @Param request body AddToCartRequest true "Add to cart request payload" @Success 200 {object} ErrorResponse "Product added to cart successfully" @Failure 400 {object} ErrorResponse "Invalid request payload" @Failure 500 {object} ErrorResponse "Failed to add product to cart" @Router /cart [post]

func (*CartService) ClearCart

func (cs *CartService) ClearCart(w http.ResponseWriter, r *http.Request)

ClearCart removes all items from the cart @Summary Clear the cart @Tags Cart @Accept json @Produce json @Param request body ClearCartRequest true "Clear cart request payload" @Success 200 {object} ErrorResponse "Cart cleared successfully" @Failure 400 {object} ErrorResponse "Invalid request payload" @Failure 500 {object} ErrorResponse "Failed to clear cart" @Router /cart/clear [delete]

func (*CartService) GetCartByUserID

func (cs *CartService) GetCartByUserID(w http.ResponseWriter, r *http.Request)

GetCartByUserID retrieves the user's cart by user ID @Summary Get the user's cart by user ID @Tags Cart @Accept json @Produce json @Param userID path string true "User ID" @Success 200 {object} GetCartResponse "User's cart retrieved successfully" @Failure 400 {object} ErrorResponse "Invalid user ID" @Failure 500 {object} ErrorResponse "Failed to fetch cart" @Router /cart/{userID} [get]

func (*CartService) RegisterRoutes

func (cs *CartService) RegisterRoutes(r *mux.Router)

func (*CartService) RemoveCartItem

func (cs *CartService) RemoveCartItem(w http.ResponseWriter, r *http.Request)

RemoveCartItem removes a cart item @Summary Remove a cart item @Tags Cart @Accept json @Produce json @Param request body RemoveCartItemRequest true "Remove cart item request payload" @Success 200 {object} ErrorResponse "Cart item removed successfully" @Failure 400 {object} ErrorResponse "Invalid request payload" @Failure 500 {object} ErrorResponse "Failed to remove cart item" @Router /cart [delete]

func (*CartService) UpdateCartItem

func (cs *CartService) UpdateCartItem(w http.ResponseWriter, r *http.Request)

UpdateCartItem updates the quantity of a cart item @Summary Update the quantity of a cart item @Tags Cart @Accept json @Produce json @Param request body UpdateCartItemRequest true "Update cart item request payload" @Success 200 {object} ErrorResponse "Cart item updated successfully" @Failure 400 {object} ErrorResponse "Invalid request payload" @Failure 500 {object} ErrorResponse "Failed to update cart item" @Router /cart [put]

type ClearCartRequest

type ClearCartRequest struct {
	UserID int `json:"user_id"`
}

ClearCartRequest represents the request payload for clearing the cart

type CreateAddressResponse

type CreateAddressResponse struct {
	AddressID int `json:"address_id"`
}

CreateAddressResponse represents the response model for the CreateAddress endpoint

type ErrorResponse

type ErrorResponse struct {
	Message string `json:"message"`
}

type GetCartItem

type GetCartItem struct {
	Product   *models.ProductWeight `json:"product"`
	Quantity  int                   `json:"quantity"`
	CreatedAt time.Time             `json:"created_at"`
	UpdatedAt time.Time             `json:"updated_at"`
}

GetCartItem represents a cart item

type GetCartResponse

type GetCartResponse struct {
	CartItems  []*models.CartItem `json:"cart_items"`
	TotalPrice float64            `json:"total_price"`
}

GetCartResponse represents the response payload for retrieving the user's cart

type LoginRequest

type LoginRequest struct {
	Email    string `json:"email"`
	Password string `json:"password"`
}

LoginRequest represents the request body for user login

type LoginResponse

type LoginResponse struct {
	UserID int `json:"user_id"`
}

LoginResponse represents the response for user login

type PaymentService

type PaymentService struct {
	DB *db.Repository
}

PaymentService handles the payment mode related operations

func NewPaymentService

func NewPaymentService(db *db.Repository) *PaymentService

NewPaymentService creates a new instance of PaymentService

func (*PaymentService) GetPaymentModes

func (ps *PaymentService) GetPaymentModes(w http.ResponseWriter, r *http.Request)

GetPaymentModes retrieves all payment modes

func (*PaymentService) RegisterRoutes

func (ps *PaymentService) RegisterRoutes(r *mux.Router)

RegisterRoutes registers the payment mode routes

type ProductService

type ProductService struct {
	DB *db.Repository
}

func NewProductService

func NewProductService(db *db.Repository) *ProductService

func (*ProductService) AddProduct

func (ps *ProductService) AddProduct(w http.ResponseWriter, r *http.Request)

AddProduct adds a new product to the inventory @Summary Add a new product to the inventory @Tags Products @Accept json @Param product body AddProductRequest true "Product details" @Produce json @Success 200 {object} AddProductResponse "Product added successfully" @Failure 400 {object} ErrorResponse "Invalid request body" @Failure 500 {object} ErrorResponse "Failed to add product" @Router /products [post]

func (*ProductService) DeleteProduct

func (ps *ProductService) DeleteProduct(w http.ResponseWriter, r *http.Request)

DeleteProduct deletes a product from the inventory @Summary Delete a product from the inventory @Tags Products @Param id path string true "Product ID" @Success 200 "Product deleted successfully" @Failure 500 "Failed to delete product" @Router /products/{id} [delete]

func (*ProductService) GetProductByID

func (ps *ProductService) GetProductByID(productID string) (*models.Product, error)

func (*ProductService) GetProductDetails

func (ps *ProductService) GetProductDetails(w http.ResponseWriter, r *http.Request)

GetProductDetails retrieves a product from the inventory by its ID @Summary Get product details by ID @Tags Products @Param id path string true "Product ID" @Produce json @Success 200 {object} models.Product "Product details" @Failure 500 "Failed to retrieve product details" @Router /products/{id} [get]

func (*ProductService) GetProductNameByID

func (ps *ProductService) GetProductNameByID(productID int) (string, error)

GetProductNameByID retrieves the name of a product based on its ID

func (*ProductService) GetProductPriceByID

func (ps *ProductService) GetProductPriceByID(weightID int) float64

GetProductPriceByID retrieves the price of a product variant based on its weight ID

func (*ProductService) ListProducts

func (ps *ProductService) ListProducts(w http.ResponseWriter, r *http.Request)

ListProducts returns a list of all products in the inventory @Summary List all products @Tags Products @Produce json @Success 200 {array} models.Product "List of products" @Failure 500 "Failed to retrieve products" @Router /products [get]

func (*ProductService) RegisterRoutes

func (ps *ProductService) RegisterRoutes(r *mux.Router)

RegisterRoutes registers the product management routes

func (*ProductService) UpdateProduct

func (ps *ProductService) UpdateProduct(w http.ResponseWriter, r *http.Request)

UpdateProduct updates an existing product in the inventory @Summary Update an existing product in the inventory @Tags Products @Accept multipart/form-data @Param id path string true "Product ID" @Param name formData string true "Product name" @Param description formData string true "Product description" @Param category formData string true "Product category" @Param ingredients formData string true "Product ingredients" @Param nutritional_info formData string true "Product nutritional information" @Param image_urls formData string true "Product image URLs (comma-separated)" @Success 200 "Product updated successfully" @Failure 400 "Invalid form data" @Failure 500 "Failed to update product" @Router /products/{id} [put]

func (*ProductService) UpdateProductWeightByID

func (ps *ProductService) UpdateProductWeightByID(w http.ResponseWriter, r *http.Request)

type ProductWeightService

type ProductWeightService struct {
	DB *db.Repository
}

func NewProductWeightService

func NewProductWeightService(db *db.Repository) *ProductWeightService

func (*ProductWeightService) AddProductWeight

func (ps *ProductWeightService) AddProductWeight(w http.ResponseWriter, r *http.Request)

AddProductWeight adds a new weight variant for a product @Summary Add a new weight variant for a product @Tags Product Weights @Param productID path string true "Product ID" @Param weight body AddProductWeightRequest true "Product weight details" @Produce json @Success 200 {object} SuccessResponse "Weight added successfully" @Failure 400 {object} ErrorResponse "Invalid request body or product ID" @Failure 500 {object} ErrorResponse "Failed to add weight" @Router /productweight/{productID}/weights [post]

func (*ProductWeightService) FetchProductWeight

func (ps *ProductWeightService) FetchProductWeight(w http.ResponseWriter, r *http.Request)

FetchProductWeight fetches product weight details based on product_weight_id @Summary Fetch product weight details based on product_weight_id @Tags Product Weights @Param weightID path string true "Weight ID" @Produce json @Success 200 {object} models.ProductWeight "Successfully fetched weight details" @Failure 400 "Invalid weight ID" @Failure 500 "Failed to fetch weight details" @Router /productweight/weights/{weightID} [get]

func (*ProductWeightService) RegisterRoutes

func (ps *ProductWeightService) RegisterRoutes(router *mux.Router)

DefineRoutes sets up the routes for the ProductWeightService

func (*ProductWeightService) UpdateProductWeight

func (ps *ProductWeightService) UpdateProductWeight(w http.ResponseWriter, r *http.Request)

UpdateProductWeight updates an existing weight variant for a product @Summary Update an existing weight variant for a product @Tags Product Weights @Param productID path string true "Product ID" @Param weightID path string true "Weight ID" @Param weight body UpdateProductWeightRequest true "Product weight details" @Success 200 "Weight updated successfully" @Failure 400 "Invalid request body or product/weight ID" @Failure 500 "Failed to update weight" @Router /productweight/{productID}/weights/{weightID} [put]

type PurchaseService

type PurchaseService struct {
	DB              *db.Repository
	ProductService  *ProductService
	RecentPurchases map[string]time.Time
	CartService     *CartService
	Mutex           sync.Mutex
}

PurchaseService handles the purchase related operations

func NewPurchaseService

func NewPurchaseService(db *db.Repository, prodService *ProductService, cartService *CartService) *PurchaseService

NewPurchaseService creates a new instance of PurchaseService

func (*PurchaseService) CreatePurchase

func (ps *PurchaseService) CreatePurchase(w http.ResponseWriter, r *http.Request)

@Summary Create a new purchase @Tags Purchases @Accept json @Produce json @Param purchase body models.PurchaseRequest true "Purchase payload" @Success 200 {string} string "Purchase created successfully" @Failure 400 "Bad request" @Failure 500 "Failed to create purchase" @Router /purchase [post]

func (*PurchaseService) GetPurchasesByUserID

func (ps *PurchaseService) GetPurchasesByUserID(w http.ResponseWriter, r *http.Request)

GetPurchasesByUserID retrieves purchases made by a specific user @Summary Get purchases by user ID @Tags Purchases @Param userID path int true "User ID" @Produce json @Success 200 {array} models.Purchase "Purchases retrieved successfully" @Failure 400 {object} ErrorResponse "Invalid user ID" @Failure 500 {object} ErrorResponse "Failed to fetch purchases" @Router /purchase/{userID} [get]

func (*PurchaseService) RegisterRoutes

func (ps *PurchaseService) RegisterRoutes(r *mux.Router)

RegisterRoutes registers the purchase routes

type RemoveCartItemRequest

type RemoveCartItemRequest struct {
	UserID          int `json:"user_id"`
	ProductWeightID int `json:"product_weight_id"`
}

RemoveCartItemRequest represents the request payload for removing a cart item

type SuccessResponse

type SuccessResponse struct {
	Message   string `json:"message"`
	ProductID int    `json:"product_id"`
}

type UpdateCartItemRequest

type UpdateCartItemRequest struct {
	UserID          int `json:"user_id"`
	ProductWeightID int `json:"product_weight_id"`
	Quantity        int `json:"quantity"`
}

UpdateCartItemRequest represents the request payload for updating a cart item

type UpdateProductWeightRequest

type UpdateProductWeightRequest struct {
	Weight            int     `json:"weight" form:"weight"`
	Price             float64 `json:"price" form:"price"`
	StockAvailability int     `json:"stock" form:"stock"`
	Measurement       string  `json:"measurement" form:"measurement"`
}

UpdateProductWeightRequest represents the request body for updating an existing weight variant

type UserService

type UserService struct {
	DB *db.Repository
}

UserService represents a service for user-related operations

func NewUserService

func NewUserService(db *db.Repository) *UserService

func (*UserService) CreateUser

func (us *UserService) CreateUser(w http.ResponseWriter, r *http.Request)

CreateUser creates a new user @Summary Create a new user @Tags Users @Accept json @Produce json @Param user body models.User true "User object" @Success 200 {string} string "User created successfully" @Failure 400 {object} ErrorResponse "Invalid request body" @Failure 409 {object} ErrorResponse "Contact number already exists" @Failure 500 {object} ErrorResponse "Failed to create user" @Router /users [post]

func (*UserService) DeleteUser

func (us *UserService) DeleteUser(w http.ResponseWriter, r *http.Request)

DeleteUser deletes a user @Summary Delete a user @Tags Users @Param id path string true "User ID" @Success 200 {string} string "User deleted successfully" @Failure 500 {object} ErrorResponse "Failed to delete user" @Router /users/{id} [delete]

func (*UserService) GetUserByID

func (us *UserService) GetUserByID(w http.ResponseWriter, r *http.Request)

GetUserByID retrieves a user by ID @Summary Retrieve a user by ID @Tags Users @Accept json @Produce json @Param id path string true "User ID" @Success 200 {object} models.User "User retrieved successfully" @Failure 500 {object} ErrorResponse "Failed to retrieve user" @Router /users/{id} [get]

func (*UserService) Login

func (us *UserService) Login(w http.ResponseWriter, r *http.Request)

Login logs in a user and returns the user_id if the password is correct @Summary User login @Tags Users @Accept json @Produce json @Param loginReq body LoginRequest true "Login request object" @Success 200 {object} LoginResponse "Login successful" @Failure 400 {object} ErrorResponse "Invalid request body" @Failure 401 {object} ErrorResponse "Invalid email or password" @Router /login [post] Login logs in a user and returns the user_id if the password is correct Login logs in a user and returns the user_id if the password is correct Login logs in a user and returns the user_id if the password is correct Login logs in a user and returns the user_id if the password is correct Login logs in a user and returns the user_id if the password is correct Login logs in a user and returns the user_id if the password is correct

func (*UserService) RegisterRoutes

func (us *UserService) RegisterRoutes(r *mux.Router)

RegisterRoutes registers the user service routes

func (*UserService) UpdateUser

func (us *UserService) UpdateUser(w http.ResponseWriter, r *http.Request)

UpdateUser updates a user @Summary Update a user @Tags Users @Accept json @Produce json @Param id path string true "User ID" @Param user body models.User true "User object" @Success 200 {string} string "User updated successfully" @Failure 400 {object} ErrorResponse "Invalid request body" @Failure 500 {object} ErrorResponse "Failed to update user" @Router /users/{id} [put]

func (*UserService) VerifyOTP

func (us *UserService) VerifyOTP(w http.ResponseWriter, r *http.Request)

VerifyOTP verifies the provided OTP and updates verified_account @Summary Verify OTP and update verified_account @Tags Users @Accept json @Produce json @Param id path string true "User ID" @Param otp body models.VerifyOTPRequest true "OTP object" @Success 200 {string} string "OTP verified and account updated successfully" @Failure 400 {object} ErrorResponse "Invalid request body" @Failure 401 {string} string "Invalid OTP" @Failure 500 {object} ErrorResponse "Failed to update user" @Router /verify-otp/{id} [post]

type WishlistService

type WishlistService struct {
	DB *db.Repository
}

func NewWishlistService

func NewWishlistService(db *db.Repository) *WishlistService

func (*WishlistService) AddToWishlist

func (ws *WishlistService) AddToWishlist(w http.ResponseWriter, r *http.Request)

@Summary Add an item to the wishlist @Tags Wishlist @Accept json @Produce json @Param item body models.WishlistRequest true "Wishlist item" @Success 200 {object} map[string]int "Item added successfully" @Failure 400 "Bad request" @Failure 500 "Failed to add item to wishlist" @Router /wishlist [post]

func (*WishlistService) CheckItemInWishlist

func (ws *WishlistService) CheckItemInWishlist(w http.ResponseWriter, r *http.Request)

@Summary Check if an item exists in the wishlist @Tags Wishlist @Produce json @Param user_id path int true "User ID" @Param product_id path int true "Product ID" @Success 200 {object} map[string]bool "Item exists in the wishlist" @Failure 400 "Bad request" @Failure 500 "Failed to check item in wishlist" @Router /wishlist/check/{user_id}/{product_id} [get]

func (*WishlistService) GetWishlistItemsByUserID

func (ws *WishlistService) GetWishlistItemsByUserID(w http.ResponseWriter, r *http.Request)

@Summary Get all wishlist items for a user @Tags Wishlist @Produce json @Param user_id path int true "User ID" @Success 200 {array} models.Wishlist "Wishlist items retrieved successfully" @Failure 400 "Bad request" @Failure 500 "Failed to fetch wishlist items" @Router /wishlist/{user_id} [get]

func (*WishlistService) RegisterRoutes

func (ws *WishlistService) RegisterRoutes(r *mux.Router)

func (*WishlistService) RemoveFromWishlist

func (ws *WishlistService) RemoveFromWishlist(w http.ResponseWriter, r *http.Request)

@Summary Remove an item from the wishlist @Tags Wishlist @Produce json @Param user_id path int true "User ID" @Param product_id path int true "Product ID" @Success 200 {string} string "Item removed successfully" @Failure 400 "Bad request" @Failure 500 "Failed to remove item from wishlist" @Router /wishlist/{user_id}/{product_id} [delete]

Jump to

Keyboard shortcuts

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