fix
This commit is contained in:
84
backend-old/internal/model/entity/album.go
Normal file
84
backend-old/internal/model/entity/album.go
Normal file
@ -0,0 +1,84 @@
|
||||
package entity
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// Album 相册实体
|
||||
type Album struct {
|
||||
ID uint `json:"id" gorm:"primarykey"`
|
||||
Title string `json:"title" gorm:"not null;size:200"`
|
||||
Description string `json:"description" gorm:"type:text"`
|
||||
Slug string `json:"slug" gorm:"uniqueIndex;size:255"`
|
||||
CoverPhotoID *uint `json:"cover_photo_id" gorm:"index"`
|
||||
UserID uint `json:"user_id" gorm:"not null;index"`
|
||||
CategoryID *uint `json:"category_id" gorm:"index"`
|
||||
IsPublic bool `json:"is_public" gorm:"default:true;index"`
|
||||
IsFeatured bool `json:"is_featured" gorm:"default:false;index"`
|
||||
Password string `json:"-" gorm:"size:255"` // 私密相册密码
|
||||
ViewCount int `json:"view_count" gorm:"default:0;index"`
|
||||
LikeCount int `json:"like_count" gorm:"default:0;index"`
|
||||
PhotoCount int `json:"photo_count" gorm:"default:0;index"`
|
||||
SortOrder int `json:"sort_order" gorm:"default:0;index"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
DeletedAt gorm.DeletedAt `json:"deleted_at" gorm:"index"`
|
||||
|
||||
// 关联
|
||||
User User `json:"user,omitempty" gorm:"foreignKey:UserID"`
|
||||
Category *Category `json:"category,omitempty" gorm:"foreignKey:CategoryID"`
|
||||
CoverPhoto *Photo `json:"cover_photo,omitempty" gorm:"foreignKey:CoverPhotoID"`
|
||||
Photos []Photo `json:"photos,omitempty" gorm:"foreignKey:AlbumID"`
|
||||
}
|
||||
|
||||
// AlbumStats 相册统计信息
|
||||
type AlbumStats struct {
|
||||
Total int64 `json:"total"` // 总相册数
|
||||
Published int64 `json:"published"` // 已发布相册数
|
||||
Private int64 `json:"private"` // 私有相册数
|
||||
Featured int64 `json:"featured"` // 精选相册数
|
||||
TotalViews int64 `json:"total_views"` // 总浏览量
|
||||
TotalLikes int64 `json:"total_likes"` // 总点赞数
|
||||
TotalPhotos int64 `json:"total_photos"` // 总照片数
|
||||
CategoryCounts map[string]int64 `json:"category_counts"` // 各分类相册数量
|
||||
}
|
||||
|
||||
// TableName 指定表名
|
||||
func (Album) TableName() string {
|
||||
return "albums"
|
||||
}
|
||||
|
||||
// HasPassword 检查是否设置了密码
|
||||
func (a *Album) HasPassword() bool {
|
||||
return a.Password != ""
|
||||
}
|
||||
|
||||
// IsEmpty 检查相册是否为空
|
||||
func (a *Album) IsEmpty() bool {
|
||||
return a.PhotoCount == 0
|
||||
}
|
||||
|
||||
// CanViewBy 检查指定用户是否可以查看相册
|
||||
func (a *Album) CanViewBy(user *User) bool {
|
||||
// 公开相册
|
||||
if a.IsPublic && !a.HasPassword() {
|
||||
return true
|
||||
}
|
||||
|
||||
// 相册所有者或管理员
|
||||
if user != nil && (user.ID == a.UserID || user.IsAdmin()) {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// CanEditBy 检查指定用户是否可以编辑相册
|
||||
func (a *Album) CanEditBy(user *User) bool {
|
||||
if user == nil {
|
||||
return false
|
||||
}
|
||||
return user.ID == a.UserID || user.IsAdmin()
|
||||
}
|
||||
Reference in New Issue
Block a user