Browse Source

add total badges

medal-v1
chenyifan01 2 years ago
parent
commit
4e2ec5ac73
3 changed files with 14 additions and 0 deletions
  1. +3
    -0
      models/badge_user.go
  2. +7
    -0
      routers/user/profile.go
  3. +4
    -0
      services/badge/user.go

+ 3
- 0
models/badge_user.go View File

@@ -142,6 +142,9 @@ func GetUserBadgesPaging(userId int64, opts GetUserBadgesOpts) ([]*Badge, error)
err := x.Join("INNER", "badge_user", "badge_user.badge_id = badge.id").Where(cond).OrderBy("badge_user.id desc").Limit(opts.PageSize, (opts.Page-1)*opts.PageSize).Find(&r)
return r, err
}
func CountUserBadges(userId int64) (int64, error) {
return x.Where("user_id = ?", userId).Count(&BadgeUser{})
}

func GetUserBadges(userId, categoryId int64) ([]*Badge, error) {
cond := builder.NewCond()


+ 7
- 0
routers/user/profile.go View File

@@ -97,12 +97,19 @@ func Profile(ctx *context.Context) {
ctx.ServerError("GetUserBadges", err)
return
}
// Count user badges
cnt, err := badge.CountUserBadges(ctxUser.ID)
if err != nil {
ctx.ServerError("CountUserBadges", err)
return
}

ctx.Data["Title"] = ctxUser.DisplayName()
ctx.Data["PageIsUserProfile"] = true
ctx.Data["Owner"] = ctxUser
ctx.Data["OpenIDs"] = openIDs
ctx.Data["RecentBadges"] = badges
ctx.Data["TotalBadges"] = cnt
ctx.Data["EnableHeatmap"] = setting.Service.EnableUserHeatmap
ctx.Data["HeatmapUser"] = ctxUser.Name
showPrivate := ctx.IsSigned && (ctx.User.IsAdmin || ctx.User.ID == ctxUser.ID)


+ 4
- 0
services/badge/user.go View File

@@ -60,6 +60,10 @@ func GetUserBadges(userId int64, opts models.ListOptions) ([]*models.Badge4UserS
return r, nil
}

func CountUserBadges(userId int64) (int64, error) {
return models.CountUserBadges(userId)
}

func GetUserAllBadges(userId int64) ([]models.UserAllBadgeInCategory, error) {
categoryList, err := models.GetBadgeCategoryList()
if err != nil {


Loading…
Cancel
Save