handlers

package
v0.0.0-...-7826c71 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateProduct

func CreateProduct(cfg *config.Config, productClient grpc.ProductClient) gin.HandlerFunc

CreateProduct adds a new product to the inventory @Summary Add a new product @Description Adds a new product to the inventory @Tags Products @Accept multipart/form-data @Produce json @Security ApiKeyAuth @Param Authorization header string true "Bearer token" @Param name formData string true "Product Name" example:"Paracetamol" @Param description formData string true "Product Description" example:"Pain relief medication" @Param price formData number true "Product Price" example:"9.99" @Param stock formData integer true "Stock Quantity" example:"100" @Param requires_prescription formData boolean false "Requires Prescription" example:"true" @Param image formData file false "Product Image" @Success 200 {object} proto.CreateProductResponse @Failure 400 {object} utils.ErrorResponse "Bad Request" @Failure 401 {object} utils.ErrorResponse "Unauthorized" @Failure 403 {object} utils.ErrorResponse "Forbidden" @Failure 409 {object} utils.ErrorResponse "Conflict" @Failure 500 {object} utils.ErrorResponse "Internal Server Error" @Router /api/v1/admin/products [post]

func DeleteProduct

func DeleteProduct(productClient grpc.ProductClient) gin.HandlerFunc

DeleteProduct deletes a product by ID @Summary Delete a product @Description Deletes a product by ID @Tags Products @Accept json @Produce json @Security ApiKeyAuth @Param Authorization header string true "Bearer token" @Param id path string true "Product ID" @Success 200 {object} proto.DeleteProductResponse @Failure 400 {object} utils.ErrorResponse "Bad Request" @Failure 401 {object} utils.ErrorResponse "Unauthorized" @Failure 403 {object} utils.ErrorResponse "Forbidden" @Failure 404 {object} utils.ErrorResponse "Not Found" @Failure 500 {object} utils.ErrorResponse "Internal Server Error" @Router /api/v1/admin/products/{id} [delete]

func DeleteReminder

func DeleteReminder(reminderClient grpc.ReminderClient) gin.HandlerFunc

DeleteReminder deletes a reminder @Summary Delete a reminder @Description Deletes a reminder @Tags Reminders @Accept json @Produce json @Security ApiKeyAuth @Param Authorization header string true "Bearer token" @Param reminder_id path string true "Reminder ID" @Success 200 {object} proto.DeleteReminderResponse @Failure 401 {object} utils.ErrorResponse @Failure 500 {object} utils.ErrorResponse @Router /api/v1/reminders/{reminder_id} [delete]

func GenerateNewPaymentUrl

func GenerateNewPaymentUrl(orderClient grpc.OrderClient) gin.HandlerFunc

GenerateNewPaymentUrl generates a new payment URL for an order @Summary Generate a new payment URL @Description Generates a new payment URL for an order @Tags Orders @Accept json @Produce json @Security ApiKeyAuth @Param Authorization header string true "Bearer token" @Param id path string true "Order ID" @Success 200 {object} proto.GeneratePaymentURLResponse @Failure 400 {object} ErrorResponse @Failure 401 {object} ErrorResponse @Failure 404 {object} ErrorResponse @Failure 500 {object} ErrorResponse @Router /api/v1/orders/{id}/payment [post]

func GetInventoryLogs

func GetInventoryLogs(productClient grpc.ProductClient) gin.HandlerFunc

GetInventoryLogs fetches inventory logs for a product @Summary Get inventory logs @Description Fetches inventory logs for a specific product @Tags Products @Accept json @Produce json @Security ApiKeyAuth @Param Authorization header string true "Bearer token" @Param id path string true "Product ID" @Param page query integer false "Page number" @Param limit query integer false "Number of items per page" @Param sort_by query string false "Sort by column" @Param sort_order query string false "Sort order (asc/desc)" @Param filter_column query string false "Filter column" @Param filter_operator query string false "Filter operator" @Param filter_value query string false "Filter value" @Success 200 {object} proto.GetInventoryLogsResponse @Failure 400 {object} utils.ErrorResponse "Bad Request" @Failure 401 {object} utils.ErrorResponse "Unauthorized" @Failure 403 {object} utils.ErrorResponse "Forbidden" @Failure 404 {object} utils.ErrorResponse "Not Found" @Failure 500 {object} utils.ErrorResponse "Internal Server Error" @Router /api/v1/admin/products/{id}/logs [get]

func GetOrder

func GetOrder(orderClient grpc.OrderClient, paymentClient grpc.PaymentClient) gin.HandlerFunc

GetOrder retrieves an order by ID @Summary Get an order @Description Retrieves an order by ID @Tags Orders @Accept json @Produce json @Security ApiKeyAuth @Param Authorization header string true "Bearer token" @Param id path string true "Order ID" @Success 200 {object} proto.GetOrderResponse @Failure 400 {object} ErrorResponse @Failure 401 {object} ErrorResponse @Failure 404 {object} ErrorResponse @Failure 500 {object} ErrorResponse @Router /api/v1/orders/{id} [get]

func GetPayment

func GetPayment(paymentClient grpc.PaymentClient) gin.HandlerFunc

GetPayment returns a payment by ID @Summary Get a payment @Description Retrieves a payment by ID @Tags Payments @Accept json @Produce json @Security ApiKeyAuth @Param Authorization header string true "Bearer token" @Param id path string true "Payment ID" @Success 200 {object} proto.GetPaymentResponse @Failure 400 {object} utils.ErrorResponse "Bad Request" @Failure 401 {object} utils.ErrorResponse "Unauthorized" @Failure 403 {object} utils.ErrorResponse "Forbidden" @Failure 404 {object} utils.ErrorResponse "Not Found" @Failure 500 {object} utils.ErrorResponse "Internal Server Error" @Router /api/v1/payments/{id} [get]

func GetPaymentByOrderID

func GetPaymentByOrderID(paymentClient grpc.PaymentClient) gin.HandlerFunc

GetPaymentByOrderID returns a payment by order ID @Summary Get a payment by order ID @Description Retrieves a payment by order ID @Tags Payments @Accept json @Produce json @Security ApiKeyAuth @Param Authorization header string true "Bearer token" @Param id path string true "Order ID" @Success 200 {object} proto.GetPaymentResponse @Failure 400 {object} utils.ErrorResponse "Bad Request" @Failure 401 {object} utils.ErrorResponse "Unauthorized" @Failure 403 {object} utils.ErrorResponse "Forbidden" @Failure 404 {object} utils.ErrorResponse "Not Found" @Failure 500 {object} utils.ErrorResponse "Internal Server Error" @Router /api/v1/payments/order/{id} [get]

func GetProduct

func GetProduct(productClient grpc.ProductClient) gin.HandlerFunc

GetProduct fetches a product by ID @Summary Get a product @Description Fetches a product by ID @Tags Products @Accept json @Produce json @Param id path string true "Product ID" @Success 200 {object} proto.GetProductResponse @Failure 400 {object} utils.ErrorResponse "Bad Request" @Failure 404 {object} utils.ErrorResponse "Not Found" @Failure 500 {object} utils.ErrorResponse "Internal Server Error" @Router /api/v1/products/{id} [get]

func GetProducts

func GetProducts(productClient grpc.ProductClient) gin.HandlerFunc

GetProducts fetches a list of products @Summary Get all products @Description Fetches a list of products @Tags Products @Accept json @Produce json @Param page query integer false "Page number" @Param limit query integer false "Number of items per page" @Param sort_by query string false "Sort by column" @Param sort_order query string false "Sort order (asc/desc)" @Param filter_column query string false "Filter column" @Param filter_operator query string false "Filter operator" @Param filter_value query string false "Filter value" @Success 200 {object} proto.ListProductsResponse @Failure 400 {object} utils.ErrorResponse "Bad Request" @Failure 500 {object} utils.ErrorResponse "Internal Server Error" @Router /api/v1/products [get]

func HandleWebhook

func HandleWebhook(cfg *config.Config, paymentClient grpc.PaymentClient) gin.HandlerFunc

HandleWebhook processes Stripe webhook events @Summary Process Stripe webhook @Description Processes incoming Stripe webhook events @Tags Payments @Accept json @Produce json @Success 200 {object} nil "OK" @Failure 400 {object} utils.ErrorResponse "Bad Request" @Failure 503 {object} utils.ErrorResponse "Service Unavailable" @Router /api/v1/webhook [post]

func HealthCheck

func HealthCheck(c *gin.Context)

HealthCheck handles health check requests. @Summary Health check @Description Check if the service is running @Tags Utility @Produce json @Success 200 {object} HealthResponse @Error 500 {object} ErrorResponse @Router /health [get]

func ListAllOrders

func ListAllOrders(orderClient grpc.OrderClient) gin.HandlerFunc

ListAllOrders retrieves all orders @Summary List all orders @Description Retrieves all orders @Tags Orders @Accept json @Produce json @Security ApiKeyAuth @Param Authorization header string true "Bearer token" @Param page query int false "Page number" @Param limit query int false "Page limit" @Param sort_by query string false "Sort by field" @Param sort_order query string false "Sort order (asc/desc)" @Param filter_column query string false "Filter column" @Param filter_operator query string false "Filter operator" @Param filter_value query string false "Filter value" @Success 200 {object} proto.ListAllOrdersResponse @Failure 400 {object} ErrorResponse @Failure 401 {object} ErrorResponse @Failure 403 {object} ErrorResponse @Failure 500 {object} ErrorResponse @Router /api/v1/admin/orders [get]

func ListCustomerReminders

func ListCustomerReminders(reminderClient grpc.ReminderClient) gin.HandlerFunc

ListCustomerReminders lists all reminders for a customer @Summary List customer reminders @Description List all reminders for a customer @Tags Reminders @Accept json @Produce json @Security ApiKeyAuth @Param Authorization header string true "Bearer token" @Param customer_id query string true "Customer ID" @Param page query int false "Page number" @Param limit query int false "Number of items per page" @Param sort_by query string false "Sort by field" @Param sort_order query string false "Sort order (asc/desc)" @Param filter_column query string false "Filter column" @Param filter_operator query string false "Filter operator" @Param filter_value query string false "Filter value" @Success 200 {object} proto.ListRemindersResponse @Failure 401 {object} utils.ErrorResponse @Failure 500 {object} utils.ErrorResponse @Router /api/v1/reminders [get]

func ListCustomersOrders

func ListCustomersOrders(orderClient grpc.OrderClient) gin.HandlerFunc

ListCustomersOrders retrieves all orders for a customer @Summary List all orders @Description Retrieves all orders for a customer @Tags Orders @Accept json @Produce json @Security ApiKeyAuth @Param Authorization header string true "Bearer token" @Param page query int false "Page number" @Param limit query int false "Page limit" @Param sort_by query string false "Sort by field" @Param sort_order query string false "Sort order (asc/desc)" @Param filter_column query string false "Filter column" @Param filter_operator query string false "Filter operator" @Param filter_value query string false "Filter value" @Success 200 {object} proto.ListCustomersOrdersResponse @Failure 400 {object} ErrorResponse @Failure 401 {object} ErrorResponse @Failure 500 {object} ErrorResponse @Router /api/v1/orders [get]

func ListReminderLogs

func ListReminderLogs(reminderClient grpc.ReminderClient) gin.HandlerFunc

ListReminderLogs lists all reminder logs @Summary List reminder logs @Description List all reminder logs @Tags Reminders @Accept json @Produce json @Security ApiKeyAuth @Param Authorization header string true "Bearer token" @Param reminder_id path string true "Reminder ID" @Param page query int false "Page number" @Param limit query int false "Number of items per page" @Param sort_by query string false "Sort by field" @Param sort_order query string false "Sort order (asc/desc)" @Param filter_column query string false "Filter column" @Param filter_operator query string false "Filter operator" @Param filter_value query string false "Filter value" @Success 200 {object} proto.ListReminderLogsResponse @Failure 401 {object} utils.ErrorResponse @Failure 500 {object} utils.ErrorResponse @Router /api/v1/reminders/{reminder_id}/logs [get]

func ListReminders

func ListReminders(reminderClient grpc.ReminderClient) gin.HandlerFunc

ListReminders lists all reminders @Summary List reminders @Description List all reminders @Tags Reminders @Accept json @Produce json @Security ApiKeyAuth @Param Authorization header string true "Bearer token" @Param page query int false "Page number" @Param limit query int false "Number of items per page" @Param sort_by query string false "Sort by field" @Param sort_order query string false "Sort order (asc/desc)" @Param filter_column query string false "Filter column" @Param filter_operator query string false "Filter operator" @Param filter_value query string false "Filter value" @Success 200 {object} proto.ListRemindersResponse @Failure 401 {object} utils.ErrorResponse @Failure 500 {object} utils.ErrorResponse @Router /api/v1/admin/reminders [get]

func Login

func Login(authClient grpc.AuthClient) gin.HandlerFunc

Login handles user login. @Summary Login @Description Login with the provided email/username and password @Tags Authentication @Accept json @Produce json @Param request body LoginRequest true "Login details" @Success 200 {object} proto.LoginResponse @Failure 400 {object} ErrorResponse @Failure 401 {object} ErrorResponse @Failure 404 {object} ErrorResponse @Failure 500 {object} ErrorResponse @Router /api/v1/login [post]

func PlaceOrder

func PlaceOrder(cfg *config.Config, orderClient grpc.OrderClient) gin.HandlerFunc

PlaceOrder creates a new order @Summary Place a new order @Description Creates new order with the given product ID and quantity @Tags Orders @Accept multipart/form-data @Produce json @Security ApiKeyAuth @Param Authorization header string true "Bearer token" @Param items formData string true "Order Items JSON" @Param prescription formData file false "Prescription Image" @Success 200 {object} proto.PlaceOrderResponse @Failure 400 {object} ErrorResponse @Failure 401 {object} ErrorResponse @Failure 409 {object} ErrorResponse @Failure 500 {object} ErrorResponse @Router /api/v1/orders [post]

func Register

func Register(authClient grpc.AuthClient) gin.HandlerFunc

Register handles user registration. @Summary Register a new user @Description Register a new user with the provided details @Tags Authentication @Accept json @Produce json @Param request body RegisterRequest true "User registration details" @Success 200 {object} proto.RegisterResponse @Failure 400 {object} ErrorResponse @Failure 409 {object} ErrorResponse @Failure 500 {object} ErrorResponse @Router /api/v1/register [post]

func ScheduleReminder

func ScheduleReminder(reminderClient grpc.ReminderClient) gin.HandlerFunc

ScheduleReminder is a function that schedules a reminder for a customer @Summary Schedule a reminder @Description Schedule a reminder for a customer @Tags Reminders @Accept json @Produce json @Security ApiKeyAuth @Param Authorization header string true "Bearer token" @Param request body ScheduleReminderRequest true "Reminder Details" @Success 200 {object} proto.ScheduleReminderResponse @Failure 400 {object} utils.ErrorResponse @Failure 401 {object} utils.ErrorResponse @Failure 500 {object} utils.ErrorResponse @Router /api/v1/reminders [post]

func ToggleReminder

func ToggleReminder(reminderClient grpc.ReminderClient) gin.HandlerFunc

ToggleReminder toggles a reminder @Summary Toggle a reminder @Description Toggles a reminder @Tags Reminders @Accept json @Produce json @Security ApiKeyAuth @Param Authorization header string true "Bearer token" @Param reminder_id path string true "Reminder ID" @Success 200 {object} proto.ToggleReminderResponse @Failure 401 {object} utils.ErrorResponse @Failure 500 {object} utils.ErrorResponse @Router /api/v1/reminders/{reminder_id} [patch]

func UpdateOrderStatus

func UpdateOrderStatus(orderClient grpc.OrderClient) gin.HandlerFunc

UpdateOrder updates an order by ID @Summary Update an order @Description Updates an order by ID @Tags Orders @Accept json @Produce json @Security ApiKeyAuth @Param Authorization header string true "Bearer token" @Param id path string true "Order ID" @Param request body OrderStatusRequest true "Order Details" @Success 200 {object} proto.UpdateOrderStatusResponse @Failure 400 {object} ErrorResponse @Failure 401 {object} ErrorResponse @Failure 403 {object} ErrorResponse @Failure 404 {object} ErrorResponse @Failure 500 {object} ErrorResponse @Router /api/v1/admin/orders/{id} [put]

func UpdateProduct

func UpdateProduct(cfg *config.Config, productClient grpc.ProductClient) gin.HandlerFunc

UpdateProduct updates a product by ID @Summary Update a product @Description Updates a product by ID @Tags Products @Accept json @Produce json @Security ApiKeyAuth @Param Authorization header string true "Bearer token" @Param id path string true "Product ID" @Param request body UpdateProductReq true "Product Details" @Success 200 {object} proto.UpdateProductResponse @Failure 400 {object} utils.ErrorResponse "Bad Request" @Failure 401 {object} utils.ErrorResponse "Unauthorized" @Failure 403 {object} utils.ErrorResponse "Forbidden" @Failure 404 {object} utils.ErrorResponse "Not Found" @Failure 500 {object} utils.ErrorResponse "Internal Server Error" @Router /api/v1/admin/products/{id} [put]

func UpdateReminder

func UpdateReminder(reminderClient grpc.ReminderClient) gin.HandlerFunc

UpdateReminder updates a reminder @Summary Update a reminder @Description Updates a reminder @Tags Reminders @Accept json @Produce json @Security ApiKeyAuth @Param Authorization header string true "Bearer token" @Param reminder_id path string true "Reminder ID" @Param request body ScheduleReminderRequest true "Reminder Details" @Success 200 {object} proto.UpdateReminderResponse @Failure 400 {object} utils.ErrorResponse @Failure 401 {object} utils.ErrorResponse @Failure 500 {object} utils.ErrorResponse @Router /api/v1/reminders/{reminder_id} [put]

func UpdateStock

func UpdateStock(productClient grpc.ProductClient) gin.HandlerFunc

UpdateStock updates the stock of a product by ID @Summary Update stock @Description Updates the stock of a product by ID @Tags Products @Accept json @Produce json @Security ApiKeyAuth @Param Authorization header string true "Bearer token" @Param id path string true "Product ID" @Param request body StockRequest true "Stock Details" @Success 200 {object} proto.UpdateStockResponse @Failure 400 {object} utils.ErrorResponse "Bad Request" @Failure 401 {object} utils.ErrorResponse "Unauthorized" @Failure 403 {object} utils.ErrorResponse "Forbidden" @Failure 404 {object} utils.ErrorResponse "Not Found" @Failure 500 {object} utils.ErrorResponse "Internal Server Error" @Router /api/v1/admin/products/{id}/stock [put]

Types

type ErrorResponse

type ErrorResponse struct {
	Type    string            `json:"type" example:"VALIDATION_ERROR"`
	Message string            `json:"message" example:"Invalid request format"`
	Details map[string]string `json:"details,omitempty" example:"field:error message"`
}

ErrorResponse represents an error response from the API @Description Error response

type HealthResponse

type HealthResponse struct {
	Status string `json:"status" example:"ok"`
}

HealthResponse represents the response for the health check endpoint. @Description Health check response

type LoginRequest

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

type Order

type Order struct {
	OrderRequest
	Prescription *multipart.FileHeader `form:"prescription" swaggerignore:"true"`
}

type OrderItem

type OrderItem struct {
	ProductID   string `json:"product_id" form:"product_id" binding:"required"`
	ProductName string `json:"product_name" form:"product_name" binding:"required"`
	Quantity    int    `json:"quantity" form:"quantity" binding:"required"`
}

type OrderRequest

type OrderRequest struct {
	Items []OrderItem `form:"items"`
}

type OrderStatusRequest

type OrderStatusRequest struct {
	Status string `json:"status"`
}

type Product

type Product struct {
	ProductRequest
	Image *multipart.FileHeader `form:"image" swaggerignore:"true"`
}

type ProductRequest

type ProductRequest struct {
	Name                 string  `json:"name" form:"name" binding:"required" example:"Paracetamol"`
	Description          string  `json:"description" form:"description" binding:"required" example:"Pain relief medication"`
	Price                float64 `json:"price" form:"price" binding:"required,gt=0" example:"9.99"`
	Stock                int32   `json:"stock" form:"stock" binding:"required,gt=0" example:"100"`
	RequiresPrescription bool    `json:"requires_prescription" form:"requires_prescription" example:"true"`
}

type ProductUpdate

type ProductUpdate struct {
	Name                 string  `json:"name" form:"name" binding:"required" example:"Paracetamol"`
	Description          string  `json:"description" form:"description" binding:"required" example:"Pain relief medication"`
	Price                float64 `json:"price" form:"price" binding:"required,gt=0" example:"9.99"`
	RequiresPrescription bool    `json:"requires_prescription" form:"requires_prescription" example:"true"`
}

type RegisterRequest

type RegisterRequest struct {
	Username    string `json:"username"`
	Email       string `json:"email"`
	Password    string `json:"password"`
	FirstName   string `json:"first_name"`
	LastName    string `json:"last_name"`
	Phone       string `json:"phone"`
	DateOfBirth string `json:"date_of_birth"`
	StreetLine1 string `json:"street_line1"`
	StreetLine2 string `json:"street_line2"`
	City        string `json:"city"`
	Province    string `json:"province"`
	PostalCode  string `json:"postal_code"`
	Country     string `json:"country"`
}

type ScheduleReminderRequest

type ScheduleReminderRequest struct {
	CustomerID   string `json:"customer_id" binding:"required"`
	OrderID      string `json:"order_id" binding:"required"`
	ProductID    string `json:"product_id" binding:"required"`
	ReminderDate string `json:"reminder_date" binding:"required"`
}

type StockRequest

type StockRequest struct {
	QuantityChange int32  `json:"quantity_change" binding:"required"`
	Reason         string `json:"reason" binding:"required"`
}

type SwaggerOrderRequest

type SwaggerOrderRequest struct {
	Items        []OrderItem `json:"items"`
	Prescription string      `json:"prescription" format:"binary"`
}

@Description Order placement request

type UpdateProductReq

type UpdateProductReq struct {
	ProductUpdate
	Image *multipart.FileHeader `form:"image" swaggerignore:"true"`
}

Jump to

Keyboard shortcuts

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