50 lines
1.0 KiB
Go
50 lines
1.0 KiB
Go
package socket
|
|
|
|
import (
|
|
"JISQueueing/common"
|
|
"JISQueueing/db"
|
|
"github.com/gorilla/websocket"
|
|
"strings"
|
|
)
|
|
|
|
func onKioskMessage(who *websocket.Conn, msg string) {
|
|
message := strings.SplitN(msg, " ", 2)
|
|
switch message[0] {
|
|
case "query":
|
|
if len(message) < 2 {
|
|
return
|
|
}
|
|
email := strings.TrimSpace(message[1])
|
|
visitor, err := db.GetVisitor(email)
|
|
if err == db.ErrVisitorNotFound {
|
|
who.WriteMessage(websocket.TextMessage, []byte("error query "+err.Error()))
|
|
return
|
|
}
|
|
|
|
who.WriteMessage(websocket.TextMessage, []byte("success query "+visitor.Name))
|
|
|
|
case "new":
|
|
arg := strings.SplitN(msg, " ", 3)
|
|
if len(arg) < 3 {
|
|
return
|
|
}
|
|
|
|
_, visitor := db.NewVisitor(common.Visitor{
|
|
Email: strings.TrimSpace(arg[1]),
|
|
Name: strings.TrimSpace(arg[2]),
|
|
FirstTicket: -1,
|
|
})
|
|
newTicket(db.NewTicket(visitor), who)
|
|
|
|
default:
|
|
who.WriteMessage(websocket.TextMessage, []byte("error command not found"))
|
|
}
|
|
}
|
|
|
|
func onKioskDisconnect(who *websocket.Conn) {
|
|
|
|
}
|
|
|
|
func onNewKiosk(who *websocket.Conn) {
|
|
}
|