feat: add endpoints for retrieving stock alerts and anomaly items, including database queries and models
This commit is contained in:
@@ -41,3 +41,53 @@ func DashboardSummary(c *gin.Context) error {
|
||||
response.Ok(c, "Success", summary)
|
||||
return nil
|
||||
}
|
||||
|
||||
// @Summary Get stock alerts
|
||||
// @Description Retrieve list of components that are low on stock (total_quantity <= min_quantity)
|
||||
// @Tags dashboard
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {object} response.SuccessResponse{data=[]models.StockAlert}
|
||||
// @Failure 500 {object} response.ErrorResponse
|
||||
// @Router /v1/dashboard/stock-alerts [get]
|
||||
func DashboardStockAlerts(c *gin.Context) error {
|
||||
alerts, err := repositories.GetStockAlerts(c.Request.Context(), global.Queries)
|
||||
if err != nil {
|
||||
log.Err(err).Msg("Error when Get Stock Alerts")
|
||||
response.InternalServerError(c, http.StatusInternalServerError, "Failed to get stock alerts")
|
||||
return nil
|
||||
}
|
||||
response.Ok(c, "Success", alerts)
|
||||
return nil
|
||||
}
|
||||
|
||||
// @Summary Get anomaly items
|
||||
// @Description Retrieve list of component items with abnormal status (damaged, expired, long_unused, pending_inspection)
|
||||
// @Tags dashboard
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param warehouse_id query int false "Filter by warehouse ID"
|
||||
// @Success 200 {object} response.SuccessResponse{data=[]models.AnomalyItem}
|
||||
// @Failure 400 {object} response.ErrorResponse
|
||||
// @Failure 500 {object} response.ErrorResponse
|
||||
// @Router /v1/dashboard/anomalies [get]
|
||||
func DashboardAnomalies(c *gin.Context) error {
|
||||
var warehouseID pgtype.Int8
|
||||
if raw := c.Query("warehouse_id"); raw != "" {
|
||||
id, err := strconv.ParseInt(raw, 10, 64)
|
||||
if err != nil {
|
||||
response.BadRequestError(c, http.StatusBadRequest, "Invalid warehouse_id")
|
||||
return nil
|
||||
}
|
||||
warehouseID = pgtype.Int8{Int64: id, Valid: true}
|
||||
}
|
||||
|
||||
anomalies, err := repositories.GetAnomalyItems(c.Request.Context(), global.Queries, warehouseID)
|
||||
if err != nil {
|
||||
log.Err(err).Msg("Error when Get Anomaly Items")
|
||||
response.InternalServerError(c, http.StatusInternalServerError, "Failed to get anomaly items")
|
||||
return nil
|
||||
}
|
||||
response.Ok(c, "Success", anomalies)
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user