Refactor checkin table to attendance table
Some checks failed
Build Backend (NixCN CMS) TeamCity build failed
Build Frontend (NixCN CMS) TeamCity build finished

Signed-off-by: Asai Neko <sugar@sne.moe>
This commit is contained in:
2026-01-01 14:08:59 +08:00
parent acd3c95c80
commit 304e1d95ed
10 changed files with 279 additions and 323 deletions

View File

@@ -1,13 +1,10 @@
package user
import (
"errors"
"nixcn-cms/data"
"time"
"github.com/gin-gonic/gin"
"github.com/google/uuid"
"gorm.io/gorm"
)
func Query(c *gin.Context) {
@@ -28,35 +25,20 @@ func Query(c *gin.Context) {
return
}
checkinData := new(data.Checkin)
checkin, err := checkinData.GetCheckin(userId.(uuid.UUID), eventId)
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 checkin == nil {
} else if attendance == nil {
c.JSON(404, gin.H{"status": "event checkin record not found"})
return
}
checkinTime := time.Now()
checkinData.EventId = eventId
checkinData.UserId = userId.(uuid.UUID)
checkinData.CheckinAt = checkinTime
err = checkinData.CreateCheckin()
if err != nil {
if errors.Is(err, gorm.ErrDuplicatedKey) {
c.JSON(409, gin.H{
"status": "already checked in",
})
return
}
c.JSON(500, gin.H{
"status": "database error",
})
} else if attendance.CheckinAt.IsZero() {
c.JSON(200, gin.H{"checkin_at": nil})
return
}
c.JSON(200, gin.H{
"checkin_time": checkinTime,
"checkin_at": attendance.CheckinAt,
})
}