-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Add badge capabilities to users #20607
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
81eee46
Add badge capabilities to users
techknowlogick 9098907
add migration
techknowlogick 8c8f020
placate lint
techknowlogick fe202ce
Merge branch 'main' into badges
techknowlogick f316b19
Merge branch 'main' into badges
jolheiser 4e94f51
placate lint
techknowlogick 1a71413
Merge branch 'badges' of github.com:techknowlogick/gitea into badges
techknowlogick 4e0c639
Update templates/user/profile.tmpl
techknowlogick 6dafa31
Update models/user/badge.go
techknowlogick 0145a5e
Update models/user/badge.go
techknowlogick bf0763a
Merge branch 'main' into badges
techknowlogick 8ccfd7a
update per suggestions
techknowlogick 5a0887b
update per suggestions
techknowlogick 9f4b043
update per suggestions - add index
techknowlogick b7ed05e
Update web_src/less/_user.less
techknowlogick bfaa6f4
Update templates/user/profile.tmpl
techknowlogick 78fabd3
Merge branch 'main' into badges
techknowlogick af6c1f5
Merge branch 'main' into badges
techknowlogick File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright 2022 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package migrations | ||
|
||
import ( | ||
"xorm.io/xorm" | ||
) | ||
|
||
func creatUserBadgesTable(x *xorm.Engine) error { | ||
type Badge struct { | ||
ID int64 `xorm:"pk autoincr"` | ||
Description string | ||
ImageURL string | ||
} | ||
|
||
type userBadge struct { | ||
ID int64 `xorm:"pk autoincr"` | ||
BadgeID int64 | ||
lunny marked this conversation as resolved.
Show resolved
Hide resolved
|
||
UserID int64 | ||
techknowlogick marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
if err := x.Sync2(new(Badge)); err != nil { | ||
return err | ||
} | ||
return x.Sync2(new(userBadge)) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright 2022 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package user | ||
|
||
import ( | ||
"context" | ||
|
||
"code.gitea.io/gitea/models/db" | ||
) | ||
|
||
// Badge represents a user badge | ||
type Badge struct { | ||
ID int64 `xorm:"pk autoincr"` | ||
Description string | ||
ImageURL string | ||
} | ||
|
||
type userBadge struct { | ||
ID int64 `xorm:"pk autoincr"` | ||
BadgeID int64 | ||
UserID int64 | ||
} | ||
techknowlogick marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
func init() { | ||
db.RegisterModel(new(Badge)) | ||
db.RegisterModel(new(userBadge)) | ||
} | ||
|
||
// GetUserFollowers returns range of user's followers. | ||
func GetUserBadges(ctx context.Context, u *User) ([]*Badge, int64, error) { | ||
techknowlogick marked this conversation as resolved.
Show resolved
Hide resolved
|
||
sess := db.GetEngine(ctx). | ||
Select("`badge`.*"). | ||
Join("LEFT", "user_badge", "`user_badge`.badge_id=badge.id"). | ||
techknowlogick marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Where("user_badge.user_id=?", u.ID) | ||
|
||
badges := make([]*Badge, 0, 8) | ||
count, err := sess.FindAndCount(&badges) | ||
return badges, count, err | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.