Reorder checkin api location (move to event)
Signed-off-by: Asai Neko <sugar@sne.moe>
This commit is contained in:
@@ -9,6 +9,6 @@ import (
|
|||||||
func Handler(r *gin.RouterGroup) {
|
func Handler(r *gin.RouterGroup) {
|
||||||
r.GET("/redirect", Redirect, middleware.JWTAuth(false))
|
r.GET("/redirect", Redirect, middleware.JWTAuth(false))
|
||||||
r.POST("/magic", Magic)
|
r.POST("/magic", Magic)
|
||||||
r.POST("/refresh", Refresh)
|
|
||||||
r.POST("/token", Token)
|
r.POST("/token", Token)
|
||||||
|
r.POST("/refresh", Refresh)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package user
|
package event
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"nixcn-cms/data"
|
"nixcn-cms/data"
|
||||||
@@ -57,3 +57,43 @@ func CheckinSubmit(c *gin.Context) {
|
|||||||
|
|
||||||
c.JSON(200, gin.H{"status": "success"})
|
c.JSON(200, gin.H{"status": "success"})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CheckinQuery(c *gin.Context) {
|
||||||
|
userIdOrig, ok := c.Get("user_id")
|
||||||
|
if !ok {
|
||||||
|
c.JSON(403, gin.H{"status": "userid error"})
|
||||||
|
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})
|
||||||
|
}
|
||||||
@@ -9,4 +9,7 @@ import (
|
|||||||
func Handler(r *gin.RouterGroup) {
|
func Handler(r *gin.RouterGroup) {
|
||||||
r.Use(middleware.JWTAuth(true), middleware.Permission(10))
|
r.Use(middleware.JWTAuth(true), middleware.Permission(10))
|
||||||
r.GET("/info", Info)
|
r.GET("/info", Info)
|
||||||
|
r.GET("/checkin", Checkin)
|
||||||
|
r.GET("/checkin/query", CheckinQuery)
|
||||||
|
r.POST("/checkin/submit", CheckinSubmit, middleware.Permission(20))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,11 +9,8 @@ import (
|
|||||||
func Handler(r *gin.RouterGroup) {
|
func Handler(r *gin.RouterGroup) {
|
||||||
r.Use(middleware.JWTAuth(true), middleware.Permission(5))
|
r.Use(middleware.JWTAuth(true), middleware.Permission(5))
|
||||||
r.GET("/info", Info)
|
r.GET("/info", Info)
|
||||||
r.GET("/checkin", Checkin)
|
|
||||||
r.POST("/checkin/submit", CheckinSubmit, middleware.Permission(20))
|
|
||||||
r.PATCH("/update", Update)
|
r.PATCH("/update", Update)
|
||||||
r.GET("/list", List)
|
r.GET("/list", List, middleware.Permission(20))
|
||||||
r.GET("/query", Query)
|
|
||||||
r.POST("/full", Full, middleware.Permission(40))
|
r.POST("/full", Full, middleware.Permission(40))
|
||||||
r.POST("/create", Create, middleware.Permission(50))
|
r.POST("/create", Create, middleware.Permission(50))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,48 +0,0 @@
|
|||||||
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(403, gin.H{"status": "userid error"})
|
|
||||||
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})
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user