51 lines
1.0 KiB
Go
51 lines
1.0 KiB
Go
package user
|
|
|
|
import (
|
|
"nixcn-cms/data"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
func Query(c *gin.Context) {
|
|
userIdOrig, ok := c.Get("user_id")
|
|
if !ok {
|
|
c.JSON(400, gin.H{"status": "could not found user_id"})
|
|
return
|
|
}
|
|
userId, err := uuid.Parse(userIdOrig.(string))
|
|
if err != nil {
|
|
c.JSON(500, gin.H{
|
|
"status": "failed to parse uuid",
|
|
})
|
|
}
|
|
|
|
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, 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,
|
|
})
|
|
}
|