Move event query to user query

Signed-off-by: Asai Neko <sugar@sne.moe>
This commit is contained in:
2025-12-28 01:07:49 +08:00
parent b3fe91444d
commit fb7ecaffe9
3 changed files with 2 additions and 2 deletions

View File

@@ -13,4 +13,5 @@ func Handler(r *gin.RouterGroup) {
r.POST("/checkin/submit", CheckinSubmit)
r.PATCH("/update", Update)
r.GET("/list", List)
r.GET("/query", Query)
}

36
service/user/query.go Normal file
View File

@@ -0,0 +1,36 @@
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
}
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
}
c.JSON(200, gin.H{
"checkin_time": data.Checkin[eventId],
})
}