forked from nixcn/nixcn-cms
Migrate checkin to user service
Signed-off-by: Asai Neko <sugar@sne.moe>
This commit is contained in:
41
service/user/info.go
Normal file
41
service/user/info.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"nixcn-cms/data"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
func Info(c *gin.Context) {
|
||||
data := new(data.User)
|
||||
userId, ok := c.Get("user_id")
|
||||
if !ok {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{
|
||||
"status": "user not found",
|
||||
})
|
||||
return
|
||||
}
|
||||
err := data.GetByUserId(userId.(uuid.UUID))
|
||||
if err != nil {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{
|
||||
"status": "user not found",
|
||||
})
|
||||
return
|
||||
}
|
||||
var checkinTime any = nil
|
||||
if !data.Checkin.IsZero() {
|
||||
checkinTime = data.Checkin
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"user_id": data.UserId,
|
||||
"email": data.Email,
|
||||
"type": data.Type,
|
||||
"nickname": data.Nickname,
|
||||
"subtitle": data.Subtitle,
|
||||
"avatar": data.Avatar,
|
||||
"checkin": checkinTime,
|
||||
"permission_level": data.PermissionLevel,
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user