Refactor checkin table to attendance table
Signed-off-by: Asai Neko <sugar@sne.moe>
This commit is contained in:
@@ -8,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
func Info(c *gin.Context) {
|
||||
event := new(data.Event)
|
||||
eventData := new(data.Event)
|
||||
eventIdOrig, ok := c.GetQuery("event_id")
|
||||
if !ok {
|
||||
c.JSON(400, gin.H{
|
||||
@@ -26,7 +26,7 @@ func Info(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
err = event.GetEventById(eventId)
|
||||
event, err := eventData.GetEventById(eventId)
|
||||
if err != nil {
|
||||
c.JSON(404, gin.H{
|
||||
"status": "event id not found",
|
||||
@@ -35,9 +35,8 @@ func Info(c *gin.Context) {
|
||||
}
|
||||
|
||||
c.JSON(200, gin.H{
|
||||
"name": event.Name,
|
||||
"start_time": event.StartTime,
|
||||
"end_time": event.EndTime,
|
||||
"joined_users": event.JoinedUsers,
|
||||
"name": event.Name,
|
||||
"start_time": event.StartTime,
|
||||
"end_time": event.EndTime,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
func Checkin(c *gin.Context) {
|
||||
data := new(data.Checkin)
|
||||
data := new(data.Attendance)
|
||||
userId, ok := c.Get("user_id")
|
||||
if !ok {
|
||||
c.JSON(401, gin.H{
|
||||
@@ -71,8 +71,8 @@ func CheckinSubmit(c *gin.Context) {
|
||||
}
|
||||
c.ShouldBindJSON(&req)
|
||||
|
||||
checkinData := new(data.Checkin)
|
||||
userId, err := checkinData.VerifyCheckinCode(req.ChekinCode)
|
||||
attendanceData := new(data.Attendance)
|
||||
err := attendanceData.VerifyCheckinCode(req.ChekinCode)
|
||||
if err != nil {
|
||||
c.JSON(400, gin.H{
|
||||
"status": "error verify checkin code",
|
||||
|
||||
@@ -29,7 +29,6 @@ func Info(c *gin.Context) {
|
||||
c.JSON(200, gin.H{
|
||||
"user_id": user.UserId,
|
||||
"email": user.Email,
|
||||
"type": user.Type,
|
||||
"nickname": user.Nickname,
|
||||
"subtitle": user.Subtitle,
|
||||
"avatar": user.Avatar,
|
||||
|
||||
@@ -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,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -36,10 +36,6 @@ func Update(c *gin.Context) {
|
||||
user.Email = ReqInfo.Email
|
||||
user.Nickname = ReqInfo.Nickname
|
||||
user.Subtitle = ReqInfo.Subtitle
|
||||
// Cant change user type under permission 2
|
||||
if user.PermissionLevel >= 2 {
|
||||
user.Type = ReqInfo.Type
|
||||
}
|
||||
|
||||
// Update user info
|
||||
user.UpdateByUserID(userId.(uuid.UUID))
|
||||
|
||||
Reference in New Issue
Block a user