forked from nixcn/nixcn-cms
@@ -1,7 +1,6 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"nixcn-cms/data"
|
||||
"time"
|
||||
|
||||
@@ -9,17 +8,34 @@ import (
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
func Checkin(ctx *gin.Context) {
|
||||
func Checkin(c *gin.Context) {
|
||||
data := new(data.User)
|
||||
userId, ok := ctx.Get("user_id")
|
||||
userId, ok := c.Get("user_id")
|
||||
if !ok {
|
||||
ctx.JSON(http.StatusUnauthorized, gin.H{
|
||||
c.JSON(401, gin.H{
|
||||
"status": "unauthorized",
|
||||
})
|
||||
return
|
||||
}
|
||||
data.UpdateCheckin(userId.(uuid.UUID), time.Now())
|
||||
ctx.JSON(http.StatusOK, gin.H{
|
||||
|
||||
// Get event id from query
|
||||
eventIdOrig, ok := c.GetQuery("event_id")
|
||||
if !ok {
|
||||
c.JSON(403, 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",
|
||||
})
|
||||
}
|
||||
data.UpdateCheckin(userId.(uuid.UUID), eventId, time.Now())
|
||||
c.JSON(200, gin.H{
|
||||
"status": "success",
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user