Skip to content

Commit c9d053f

Browse files
authored
[API] User expose counters (#16167)
1 parent 9469e14 commit c9d053f

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

modules/convert/user.go

+4
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ 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,
5155
}
5256
// hide primary email if API caller is anonymous or user keep email private
5357
if signed && (!user.KeepEmailPrivate || authed) {

modules/structs/user.go

+5
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ 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"`
4651
}
4752

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

templates/swagger/v1_json.tmpl

+16
Original file line numberDiff line numberDiff line change
@@ -16345,6 +16345,17 @@
1634516345
"format": "email",
1634616346
"x-go-name": "Email"
1634716347
},
16348+
"followers_count": {
16349+
"description": "user counts",
16350+
"type": "integer",
16351+
"format": "int64",
16352+
"x-go-name": "Followers"
16353+
},
16354+
"following_count": {
16355+
"type": "integer",
16356+
"format": "int64",
16357+
"x-go-name": "Following"
16358+
},
1634816359
"full_name": {
1634916360
"description": "the user's full name",
1635016361
"type": "string",
@@ -16391,6 +16402,11 @@
1639116402
"type": "boolean",
1639216403
"x-go-name": "Restricted"
1639316404
},
16405+
"starred_repos_count": {
16406+
"type": "integer",
16407+
"format": "int64",
16408+
"x-go-name": "StarredRepos"
16409+
},
1639416410
"website": {
1639516411
"description": "the user's website",
1639616412
"type": "string",

0 commit comments

Comments
 (0)