Skip to content

Commit b6e9ba6

Browse files
committed
API: User expose counters
1 parent b8e4ce7 commit b6e9ba6

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

modules/convert/user.go

+5
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ func toUser(user *models.User, signed, authed bool) *api.User {
4848
Location: user.Location,
4949
Website: user.Website,
5050
Description: user.Description,
51+
// counter's
52+
Followers: user.NumFollowers,
53+
Following: user.NumFollowing,
54+
StarredRepos: user.NumStars,
55+
PublicRepos: int(models.CountUserRepositories(user.ID, false)),
5156
}
5257
// hide primary email if API caller is anonymous or user keep email private
5358
if signed && (!user.KeepEmailPrivate || authed) {

modules/structs/user.go

+6
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ type User struct {
4343
Website string `json:"website"`
4444
// the user's description
4545
Description string `json:"description"`
46+
47+
// user counts
48+
Followers int `json:"followers_count"`
49+
Following int `json:"following_count"`
50+
StarredRepos int `json:"starred_repos_count"`
51+
PublicRepos int `json:"public_repos_count"`
4652
}
4753

4854
// MarshalJSON implements the json.Marshaler interface for User, adding field(s) for backward compatibility

templates/swagger/v1_json.tmpl

+21
Original file line numberDiff line numberDiff line change
@@ -16275,6 +16275,17 @@
1627516275
"format": "email",
1627616276
"x-go-name": "Email"
1627716277
},
16278+
"followers_count": {
16279+
"description": "user counts",
16280+
"type": "integer",
16281+
"format": "int64",
16282+
"x-go-name": "Followers"
16283+
},
16284+
"following_count": {
16285+
"type": "integer",
16286+
"format": "int64",
16287+
"x-go-name": "Following"
16288+
},
1627816289
"full_name": {
1627916290
"description": "the user's full name",
1628016291
"type": "string",
@@ -16316,11 +16327,21 @@
1631616327
"type": "boolean",
1631716328
"x-go-name": "ProhibitLogin"
1631816329
},
16330+
"public_repos_count": {
16331+
"type": "integer",
16332+
"format": "int64",
16333+
"x-go-name": "PublicRepos"
16334+
},
1631916335
"restricted": {
1632016336
"description": "Is user restricted",
1632116337
"type": "boolean",
1632216338
"x-go-name": "Restricted"
1632316339
},
16340+
"starred_repos_count": {
16341+
"type": "integer",
16342+
"format": "int64",
16343+
"x-go-name": "StarredRepos"
16344+
},
1632416345
"website": {
1632516346
"description": "the user's website",
1632616347
"type": "string",

0 commit comments

Comments
 (0)