controllers

package
v0.0.0-...-27c22b8 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CancelOrder

func CancelOrder(c *gin.Context)

CancelOrder cancels the order if it's still pending CancelOrder godoc @Summary Cancel an order @Description Allows an authenticated user to cancel an order if it is in "Pending" status @Tags Orders @Param id path string true "Order ID" @Security BearerAuth @Success 200 {object} models.SuccessResponse "Order canceled successfully" @Failure 400 {object} models.ErrorResponse "Invalid order ID or status" @Failure 401 {object} models.ErrorResponse "Unauthorized" @Failure 404 {object} models.ErrorResponse "Order not found" @Failure 500 {object} models.ErrorResponse "Failed to cancel order" @Router /orders/{id}/cancel [put]

func CheckPassword

func CheckPassword(plain, hashed string) error

CheckPassword compares plain password with hashed

func CreateProduct

func CreateProduct(c *gin.Context)

CreateProduct allows an admin user to add a new product CreateProduct godoc @Summary Create a new product @Description Allows an admin user to add a new product @Tags Products @Accept json @Produce json @Param product body models.ProductInput true "Product payload" @Security BearerAuth @Success 200 {object} models.SuccessResponse "Product created successfully" @Failure 400 {object} models.ValidationErrorResponse "Invalid product payload" @Failure 500 {object} models.ErrorResponse "Failed to create product" @Router /products [post]

func DeleteProduct

func DeleteProduct(c *gin.Context)

DeleteProduct deletes a product by ID (admin only) DeleteProduct godoc @Summary Delete a product @Description Allows an admin user to delete a product by ID @Tags Products @Param id path string true "Product ID" @Security BearerAuth @Success 200 {object} models.SuccessResponse "Product deleted successfully" @Failure 400 {object} models.ErrorResponse "Invalid product ID" @Failure 404 {object} models.ErrorResponse "Product not found" @Failure 500 {object} models.ErrorResponse "Failed to delete product" @Router /products/{id} [delete]

func GetProductByID

func GetProductByID(c *gin.Context)

GetProductByID retrieves a single product by ID GetProductByID godoc @Summary Get product by ID @Description Retrieves a single product by its ID @Tags Products @Param id path string true "Product ID" @Security BearerAuth @Success 200 {object} models.SuccessResponse "Product retrieved successfully" @Failure 400 {object} models.ErrorResponse "Invalid product ID" @Failure 404 {object} models.ErrorResponse "Product not found" @Failure 500 {object} models.ErrorResponse "Failed to retrieve product" @Router /products/{id} [get]

func GetProducts

func GetProducts(c *gin.Context)

GetProducts lists all products GetProducts godoc @Summary Get all products @Description Retrieves a list of all products available in the store @Tags Products @Produce json @Security BearerAuth @Success 200 {object} models.SuccessResponse "Product(s) retrieved successfully" @Failure 500 {object} models.ErrorResponse "Failed to retrieve products" @Router /products [get]

func GetUserOrders

func GetUserOrders(c *gin.Context)

GetUserOrders lists all orders for the authenticated user GetUserOrders godoc @Summary Get all orders for a user @Description Retrieve a list of all orders placed by the authenticated user @Tags Orders @Produce json @Security BearerAuth @Success 200 {object} models.SuccessResponse "List of orders" @Failure 401 {object} models.ErrorResponse "Unauthorized" @Failure 500 {object} models.ErrorResponse "Failed to fetch orders" @Router /orders [get]

func HashPassword

func HashPassword(password string) (string, error)

HashPassword hashes the plain text password

func LoginUser

func LoginUser(c *gin.Context)

LoginUser handles user authentication LoginUser godoc @Summary Authenticate a user @Description Authenticate a user with email and password, returning a JWT token @Tags Users @Accept json @Produce json @Param login body models.LoginInput true "User login payload" @Success 200 {object} models.SuccessResponse "Login successful" @Failure 400 {object} models.ValidationErrorResponse "Validation errors" @Failure 401 {object} models.ErrorResponse "Invalid email or password" @Failure 500 {object} models.ErrorResponse "Failed to generate token" @Router /users/login [post]

func PlaceOrder

func PlaceOrder(c *gin.Context)

PlaceOrder allows an authenticated user to create a new order PlaceOrder godoc @Summary Place a new order @Description Allows an authenticated user to place an order with one or more products @Tags Orders @Accept json @Produce json @Param order body models.PlaceOrderInput true "Order payload" @Security BearerAuth @Success 200 {object} models.SuccessResponse "Order created successfully" @Failure 400 {object} models.ValidationErrorResponse "Invalid order payload" @Failure 401 {object} models.ErrorResponse "Unauthorized" @Failure 500 {object} models.ErrorResponse "Failed to create order" @Router /orders [post]

func RegisterUser

func RegisterUser(c *gin.Context)

RegisterUser handles user signup RegisterUser godoc @Summary Register a new user @Description Create a new user in the system with email, password, and optional role @Tags Users @Accept json @Produce json @Param user body models.UserInput true "User registration payload" @Success 200 {object} models.SuccessResponse "User registered successfully" @Failure 400 {object} models.ValidationErrorResponse "Validation errors" @Failure 500 {object} models.ErrorResponse "Failed to create user" @Router /users/register [post]

func UpdateOrderStatus

func UpdateOrderStatus(c *gin.Context)

UpdateOrderStatus allows an admin to update an order status UpdateOrderStatus godoc @Summary Update order status @Description Allows an admin to update the status of an order @Tags Orders @Param id path string true "Order ID" @Param status body models.UpdateOrderStatusInput true "Update order status payload" @Security BearerAuth @Success 200 {object} models.SuccessResponse "Order status updated successfully" @Failure 400 {object} models.ValidationErrorResponse "Invalid order ID or payload" @Failure 401 {object} models.ErrorResponse "Unauthorized" @Failure 404 {object} models.ErrorResponse "Order not found" @Failure 500 {object} models.ErrorResponse "Failed to update order status" @Router /orders/{id}/status [put]

func UpdateProduct

func UpdateProduct(c *gin.Context)

UpdateProduct modifies an existing product (admin only) UpdateProduct godoc @Summary Update a product @Description Allows an admin user to update an existing product by ID @Tags Products @Param id path string true "Product ID" @Param product body models.ProductInput true "Updated product payload" @Security BearerAuth @Success 200 {object} models.SuccessResponse "Product updated successfully" @Failure 400 {object} models.ValidationErrorResponse "Invalid product ID or payload" @Failure 404 {object} models.ErrorResponse "Product not found" @Failure 500 {object} models.ErrorResponse "Failed to update product" @Router /products/{id} [put]

Types

This section is empty.

Jump to

Keyboard shortcuts

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