30 lines
762 B
Go
30 lines
762 B
Go
package httpapi
|
|
|
|
import (
|
|
"calllinesystem/server/internal/model"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
type ticketPeopleTotals struct {
|
|
TicketCount int64 `gorm:"column:ticket_count"`
|
|
PeopleCount int64 `gorm:"column:people_count"`
|
|
}
|
|
|
|
func queueTotals(db *gorm.DB, projectID, sessionID, status string) (ticketPeopleTotals, error) {
|
|
var totals ticketPeopleTotals
|
|
err := db.Model(&model.QueueTicket{}).
|
|
Select("count(*) AS ticket_count, COALESCE(sum(party_size), 0) AS people_count").
|
|
Where("project_id = ? AND queue_session_id = ? AND status = ?", projectID, sessionID, status).
|
|
Scan(&totals).Error
|
|
return totals, err
|
|
}
|
|
|
|
func ticketsPartySize(tickets []model.QueueTicket) int {
|
|
total := 0
|
|
for _, ticket := range tickets {
|
|
total += ticket.PartySize
|
|
}
|
|
return total
|
|
}
|