Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
API: User expose counters
  • Loading branch information
6543 committed Jun 15, 2021
commit b6e9ba6c96327a104f8847fcafcd5bcaa67eb994
5 changes: 5 additions & 0 deletions modules/convert/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ func toUser(user *models.User, signed, authed bool) *api.User {
Location: user.Location,
Website: user.Website,
Description: user.Description,
// counter's
Followers: user.NumFollowers,
Following: user.NumFollowing,
StarredRepos: user.NumStars,
PublicRepos: int(models.CountUserRepositories(user.ID, false)),
}
// hide primary email if API caller is anonymous or user keep email private
if signed && (!user.KeepEmailPrivate || authed) {
Expand Down
6 changes: 6 additions & 0 deletions modules/structs/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ type User struct {
Website string `json:"website"`
// the user's description
Description string `json:"description"`

// user counts
Followers int `json:"followers_count"`
Following int `json:"following_count"`
StarredRepos int `json:"starred_repos_count"`
PublicRepos int `json:"public_repos_count"`
}

// MarshalJSON implements the json.Marshaler interface for User, adding field(s) for backward compatibility
Expand Down
21 changes: 21 additions & 0 deletions templates/swagger/v1_json.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -16275,6 +16275,17 @@
"format": "email",
"x-go-name": "Email"
},
"followers_count": {
"description": "user counts",
"type": "integer",
"format": "int64",
"x-go-name": "Followers"
},
"following_count": {
"type": "integer",
"format": "int64",
"x-go-name": "Following"
},
"full_name": {
"description": "the user's full name",
"type": "string",
Expand Down Expand Up @@ -16316,11 +16327,21 @@
"type": "boolean",
"x-go-name": "ProhibitLogin"
},
"public_repos_count": {
"type": "integer",
"format": "int64",
"x-go-name": "PublicRepos"
},
"restricted": {
"description": "Is user restricted",
"type": "boolean",
"x-go-name": "Restricted"
},
"starred_repos_count": {
"type": "integer",
"format": "int64",
"x-go-name": "StarredRepos"
},
"website": {
"description": "the user's website",
"type": "string",
Expand Down