package user import ( "nixcn-cms/data" "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 } eventIdOrig, ok := c.GetQuery("event_id") if !ok { c.JSON(400, gin.H{"status": "could not found event_id"}) return } eventId, err := uuid.Parse(eventIdOrig) if err != nil { c.JSON(400, gin.H{"status": "event_id is not valid"}) return } attendanceData := new(data.Attendance) attendance, err := attendanceData.GetAttendance(userId.(uuid.UUID), eventId) if err != nil { c.JSON(500, gin.H{"status": "database error"}) return } else if attendance == nil { c.JSON(404, gin.H{"status": "event checkin record not found"}) return } else if attendance.CheckinAt.IsZero() { c.JSON(200, gin.H{"checkin_at": nil}) return } c.JSON(200, gin.H{ "checkin_at": attendance.CheckinAt, }) }