Files
nixcn-cms/service/user/checkin.go
Asai Neko acd3c95c80
Some checks failed
Build Backend (NixCN CMS) TeamCity build failed
Build Frontend (NixCN CMS) TeamCity build finished
Refactor mass data structure
Signed-off-by: Asai Neko <sugar@sne.moe>
2026-01-01 13:31:28 +08:00

87 lines
1.4 KiB
Go

package user
import (
"nixcn-cms/data"
"github.com/gin-gonic/gin"
"github.com/google/uuid"
)
func Checkin(c *gin.Context) {
data := new(data.Checkin)
userId, ok := c.Get("user_id")
if !ok {
c.JSON(401, gin.H{
"status": "unauthorized",
})
return
}
// Get event id from query
eventIdOrig, ok := c.GetQuery("event_id")
if !ok {
c.JSON(400, gin.H{
"status": "undefinded event id",
})
return
}
// Parse event id to uuid
eventId, err := uuid.Parse(eventIdOrig)
if err != nil {
c.JSON(500, gin.H{
"status": "error parsing string to uuid",
})
return
}
data.UserId = userId.(uuid.UUID)
code, err := data.GenCheckinCode(eventId)
if err != nil {
c.JSON(500, gin.H{
"status": "error generating code",
})
return
}
c.JSON(200, gin.H{
"checkin_code": code,
})
}
func CheckinSubmit(c *gin.Context) {
userId, ok := c.Get("user_id")
if !ok {
c.JSON(403, gin.H{
"status": "unauthorized",
})
}
userData := new(data.User)
userData.GetByUserId(userId.(uuid.UUID))
if userData.PermissionLevel <= 20 {
c.JSON(403, gin.H{
"status": "access denied",
})
return
}
var req struct {
ChekinCode string `json:"checkin_code"`
}
c.ShouldBindJSON(&req)
checkinData := new(data.Checkin)
userId, err := checkinData.VerifyCheckinCode(req.ChekinCode)
if err != nil {
c.JSON(400, gin.H{
"status": "error verify checkin code",
})
return
}
c.JSON(200, gin.H{
"status": "success",
})
}