mirror of
https://github.com/wgh136/nysoure.git
synced 2025-09-27 12:17:24 +00:00
Add user file statistic.
This commit is contained in:
@@ -2,33 +2,36 @@ package model
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type User struct {
|
||||
gorm.Model
|
||||
Username string `gorm:"uniqueIndex;not null"`
|
||||
PasswordHash []byte
|
||||
IsAdmin bool
|
||||
CanUpload bool
|
||||
AvatarVersion int
|
||||
UploadsCount int
|
||||
CommentsCount int
|
||||
Resources []Resource `gorm:"foreignKey:UserID"`
|
||||
Bio string
|
||||
Username string `gorm:"uniqueIndex;not null"`
|
||||
PasswordHash []byte
|
||||
IsAdmin bool
|
||||
CanUpload bool
|
||||
AvatarVersion int
|
||||
ResourcesCount int
|
||||
FilesCount int
|
||||
CommentsCount int
|
||||
Resources []Resource `gorm:"foreignKey:UserID"`
|
||||
Bio string
|
||||
}
|
||||
|
||||
type UserView struct {
|
||||
ID uint `json:"id"`
|
||||
Username string `json:"username"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
AvatarPath string `json:"avatar_path"`
|
||||
IsAdmin bool `json:"is_admin"`
|
||||
CanUpload bool `json:"can_upload"`
|
||||
UploadsCount int `json:"uploads_count"`
|
||||
CommentsCount int `json:"comments_count"`
|
||||
Bio string `json:"bio"`
|
||||
ID uint `json:"id"`
|
||||
Username string `json:"username"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
AvatarPath string `json:"avatar_path"`
|
||||
IsAdmin bool `json:"is_admin"`
|
||||
CanUpload bool `json:"can_upload"`
|
||||
ResourcesCount int `json:"resources_count"`
|
||||
FilesCount int `json:"files_count"`
|
||||
CommentsCount int `json:"comments_count"`
|
||||
Bio string `json:"bio"`
|
||||
}
|
||||
|
||||
type UserViewWithToken struct {
|
||||
@@ -38,15 +41,16 @@ type UserViewWithToken struct {
|
||||
|
||||
func (u User) ToView() UserView {
|
||||
return UserView{
|
||||
ID: u.ID,
|
||||
Username: u.Username,
|
||||
CreatedAt: u.CreatedAt,
|
||||
AvatarPath: fmt.Sprintf("/api/user/avatar/%d?v=%d", u.ID, u.AvatarVersion),
|
||||
IsAdmin: u.IsAdmin,
|
||||
CanUpload: u.CanUpload || u.IsAdmin,
|
||||
UploadsCount: u.UploadsCount,
|
||||
CommentsCount: u.CommentsCount,
|
||||
Bio: u.Bio,
|
||||
ID: u.ID,
|
||||
Username: u.Username,
|
||||
CreatedAt: u.CreatedAt,
|
||||
AvatarPath: fmt.Sprintf("/api/user/avatar/%d?v=%d", u.ID, u.AvatarVersion),
|
||||
IsAdmin: u.IsAdmin,
|
||||
CanUpload: u.CanUpload || u.IsAdmin,
|
||||
ResourcesCount: u.ResourcesCount,
|
||||
FilesCount: u.FilesCount,
|
||||
CommentsCount: u.CommentsCount,
|
||||
Bio: u.Bio,
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user