refactor: BaseModel 主键列名统一 uid→id
- BaseModel 移除 gorm column:uid 和 json:uid 标签,统一为 id - 更新 8 个 repository 文件中 28 处 raw SQL 列引用 (uid→id) - 更新 3 个前端 JS 文件中 14 处 API 响应字段引用 (uid→id) - 添加数据库迁移 SQL 脚本 (docs/migrations/001_uid_to_id.sql)
This commit is contained in:
@ -35,7 +35,7 @@ func (r *CommentRepo) SearchUsersByLevel(keyword string, minLevel int, limit int
|
||||
threshold := model.LevelThresholds[minLevel]
|
||||
|
||||
err := r.db.Table("users").
|
||||
Select("uid, username, exp").
|
||||
Select("id, username, exp").
|
||||
Where("username LIKE ? AND exp >= ? AND deleted_at IS NULL", "%"+keyword+"%", threshold).
|
||||
Order("exp DESC").
|
||||
Limit(limit).
|
||||
@ -59,7 +59,7 @@ func (r *CommentRepo) SearchUsersByLevel(keyword string, minLevel int, limit int
|
||||
// GetUserUIDByID 通过 uint ID 获取 user 的 UID 字符串
|
||||
func (r *CommentRepo) GetUserUIDByID(userID uint) (string, error) {
|
||||
var uid uint
|
||||
err := r.db.Table("users").Select("uid").Where("uid = ?", userID).Scan(&uid).Error
|
||||
err := r.db.Table("users").Select("id").Where("id = ?", userID).Scan(&uid).Error
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@ -69,7 +69,7 @@ func (r *CommentRepo) GetUserUIDByID(userID uint) (string, error) {
|
||||
// GetUsernameByID 通过 userID 获取用户名(用于通知内容)
|
||||
func (r *CommentRepo) GetUsernameByID(userID uint) (string, error) {
|
||||
var username string
|
||||
err := r.db.Table("users").Select("username").Where("uid = ?", userID).Scan(&username).Error
|
||||
err := r.db.Table("users").Select("username").Where("id = ?", userID).Scan(&username).Error
|
||||
return username, err
|
||||
}
|
||||
|
||||
@ -112,7 +112,7 @@ func (r *CommentRepo) AggregateCommentsByAuthor(userID uint, since string) ([]se
|
||||
func (r *CommentRepo) ListAllComments(keyword string, showDeleted bool, offset, limit int) ([]model.AdminCommentRow, int64, error) {
|
||||
var total int64
|
||||
q := r.db.Table("comments").
|
||||
Joins("LEFT JOIN users ON users.uid = comments.user_id").
|
||||
Joins("LEFT JOIN users ON users.id = comments.user_id").
|
||||
Joins("LEFT JOIN posts ON posts.id = comments.post_id")
|
||||
|
||||
if !showDeleted {
|
||||
|
||||
Reference in New Issue
Block a user