Added measurements, and devices statsh
Added stats endpoints
This commit is contained in:
@@ -3,6 +3,7 @@ package controllers
|
||||
import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"gitlab.com/pactual1/backend/database/invoice"
|
||||
@@ -104,3 +105,38 @@ func convertToResponseModel(invoices []models.Invoice) []models.ListInvoiceRespo
|
||||
}
|
||||
return listInvoiceResponses
|
||||
}
|
||||
|
||||
|
||||
func GetInvoiceCountByStatus(c *gin.Context) {
|
||||
companyID := c.DefaultQuery("company_id", "0")
|
||||
startTimeStr := c.DefaultQuery("start_time", "")
|
||||
endTimeStr := c.DefaultQuery("end_time", "")
|
||||
|
||||
// Convert to uint and time.Time
|
||||
companyIDUint, err := strconv.ParseUint(companyID, 10, 64)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"error": "Invalid companyID",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// Convert string to Unix timestamp
|
||||
startUnix, _ := strconv.ParseInt(startTimeStr, 10, 64)
|
||||
endUnix, _ := strconv.ParseInt(endTimeStr, 10, 64)
|
||||
|
||||
// Convert Unix timestamps to time.Time
|
||||
startTime := time.Unix(startUnix, 0)
|
||||
endTime := time.Unix(endUnix, 0)
|
||||
|
||||
activeCount, executedCount, monthly, err := invoice.CountInvoicesByMultipleStatuses(uint(companyIDUint), startTime, endTime)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{
|
||||
"error": "Internal Server Error",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{"data": models.ActiveInvoiceResponse{Claimed: activeCount, Issued : executedCount, MonthlyInvoices: monthly}})
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user