Files
nixcn-cms/service/user/query.go
2025-12-28 01:11:51 +08:00

44 lines
849 B
Go

package user
import (
"nixcn-cms/data"
"time"
"github.com/gin-gonic/gin"
"github.com/google/uuid"
)
func Query(c *gin.Context) {
userId, ok := c.Get("user_id")
if !ok {
c.JSON(400, gin.H{"status": "could not found user_id"})
return
}
eventId, ok := c.GetQuery("event_id")
if !ok {
c.JSON(400, gin.H{"status": "could not found event_id"})
return
}
data := new(data.User)
err := data.GetByUserId(userId.(uuid.UUID))
if err != nil {
c.JSON(404, gin.H{"status": "cannot found user"})
return
}
if data.Checkin[eventId] == nil {
c.JSON(404, gin.H{"status": "cannot found user checked in"})
return
}
var checkinTime *time.Time
if data.Checkin[eventId].(*time.Time).IsZero() {
checkinTime = nil
} else {
checkinTime = data.Checkin[eventId].(*time.Time)
}
c.JSON(200, gin.H{
"checkin_time": checkinTime,
})
}