fix: 实现空间 TotalReads 统计,修复 selectMention 闭包
- P0-2: posts/show.html selectMention 闭包 var→let 修复 - P0-3: GetUserStats 增加 SUM(views_count) 统计,替换硬编码 int64(0) - 更新 Fix_List.md 标注 P0-1/2/3 已修复
This commit is contained in:
@ -55,7 +55,7 @@ type spaceUseCase interface {
|
||||
GetSpaceUser(uid uint) (*model.User, error)
|
||||
GetPostsByUser(uid uint, page, pageSize int) ([]model.Post, int64, error)
|
||||
CountUserPosts(uid uint) (int64, error)
|
||||
GetUserStats(uid uint) (likes, favorites int64, err error)
|
||||
GetUserStats(uid uint) (likes, favorites, reads int64, err error)
|
||||
UpdateUser(user *model.User) error
|
||||
}
|
||||
|
||||
|
||||
@ -81,7 +81,7 @@ func (ctrl *SpaceController) ShowSpace(c *gin.Context) {
|
||||
|
||||
// 构建基础数据(含用户统计)
|
||||
postCount, _ := ctrl.spaceService.CountUserPosts(uint(uid))
|
||||
totalLikes, totalFavorites, _ := ctrl.spaceService.GetUserStats(uint(uid))
|
||||
totalLikes, totalFavorites, totalReads, _ := ctrl.spaceService.GetUserStats(uint(uid))
|
||||
|
||||
data := gin.H{
|
||||
"Title": spaceUser.Username + " 的空间",
|
||||
@ -93,7 +93,7 @@ func (ctrl *SpaceController) ShowSpace(c *gin.Context) {
|
||||
"PostCount": postCount,
|
||||
"TotalLikes": totalLikes,
|
||||
"TotalFavorites": totalFavorites,
|
||||
"TotalReads": int64(0), // 暂无阅读量统计
|
||||
"TotalReads": totalReads,
|
||||
}
|
||||
|
||||
// ---- 根据 Tab 加载对应数据 ----
|
||||
|
||||
@ -93,18 +93,19 @@ func (r *PostRepo) CountUserPosts(userID uint) (int64, error) {
|
||||
return count, err
|
||||
}
|
||||
|
||||
// GetUserStats 获取用户的文章统计数据(总获赞/总收藏)
|
||||
func (r *PostRepo) GetUserStats(userID uint) (likes, favorites int64, err error) {
|
||||
// GetUserStats 获取用户的文章统计数据(总获赞/总收藏/总阅读)
|
||||
func (r *PostRepo) GetUserStats(userID uint) (likes, favorites, reads int64, err error) {
|
||||
type stats struct {
|
||||
TotalLikes int64
|
||||
TotalLikes int64
|
||||
TotalFavorites int64
|
||||
TotalReads int64
|
||||
}
|
||||
var s stats
|
||||
err = r.db.Model(&model.Post{}).
|
||||
Select("COALESCE(SUM(likes_count), 0) AS total_likes, COALESCE(SUM(favorites_count), 0) AS total_favorites").
|
||||
Select("COALESCE(SUM(likes_count), 0) AS total_likes, COALESCE(SUM(favorites_count), 0) AS total_favorites, COALESCE(SUM(views_count), 0) AS total_reads").
|
||||
Where("user_id = ? AND status = ? AND deleted_at IS NULL", userID, model.PostStatusApproved).
|
||||
Scan(&s).Error
|
||||
return s.TotalLikes, s.TotalFavorites, err
|
||||
return s.TotalLikes, s.TotalFavorites, s.TotalReads, err
|
||||
}
|
||||
|
||||
// FindByUserIDAndStatus 分页查询某用户指定状态的帖子(空 status=全状态)
|
||||
|
||||
@ -56,7 +56,7 @@ type spaceUserStore interface {
|
||||
type spacePostStore interface {
|
||||
FindByUserID(userID uint, offset, limit int) ([]model.Post, int64, error)
|
||||
CountUserPosts(userID uint) (int64, error)
|
||||
GetUserStats(userID uint) (likes, favorites int64, err error)
|
||||
GetUserStats(userID uint) (likes, favorites, reads int64, err error)
|
||||
}
|
||||
|
||||
// postAdminStatStore AdminService 所需的帖子统计接口(ISP:2 个方法)
|
||||
|
||||
@ -29,8 +29,8 @@ func (s *SpaceService) CountUserPosts(uid uint) (int64, error) {
|
||||
return s.postRepo.CountUserPosts(uid)
|
||||
}
|
||||
|
||||
// GetUserStats 获取用户文章统计数据(总获赞、总收藏)
|
||||
func (s *SpaceService) GetUserStats(uid uint) (likes, favorites int64, err error) {
|
||||
// GetUserStats 获取用户文章统计数据(总获赞、总收藏、总阅读)
|
||||
func (s *SpaceService) GetUserStats(uid uint) (likes, favorites, reads int64, err error) {
|
||||
return s.postRepo.GetUserStats(uid)
|
||||
}
|
||||
|
||||
|
||||
@ -934,8 +934,8 @@
|
||||
dropdown.style.left = (rect.left + window.scrollX) + 'px';
|
||||
dropdown.style.width = Math.max(rect.width, 200) + 'px';
|
||||
|
||||
for (var i = 0; i < users.length; i++) {
|
||||
var u = users[i];
|
||||
for (let i = 0; i < users.length; i++) {
|
||||
let u = users[i];
|
||||
var item = document.createElement('div');
|
||||
item.className = 'mention-item';
|
||||
item.innerHTML = '<span class="mention-username">' + escapeHtml(u.username) + '</span><span class="mention-uid">' + escapeHtml(u.uid) + '</span>';
|
||||
|
||||
Reference in New Issue
Block a user