From c9d053f0caa14e6fec4d04c009c79c9a0940c450 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Thu, 17 Jun 2021 09:17:35 +0200 Subject: [PATCH] [API] User expose counters (#16167) --- modules/convert/user.go | 4 ++++ modules/structs/user.go | 5 +++++ templates/swagger/v1_json.tmpl | 16 ++++++++++++++++ 3 files changed, 25 insertions(+) diff --git a/modules/convert/user.go b/modules/convert/user.go index 088ede5ad..c588f5f2f 100644 --- a/modules/convert/user.go +++ b/modules/convert/user.go @@ -48,6 +48,10 @@ 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, } // hide primary email if API caller is anonymous or user keep email private if signed && (!user.KeepEmailPrivate || authed) { diff --git a/modules/structs/user.go b/modules/structs/user.go index 2dbc53053..de2e68c2a 100644 --- a/modules/structs/user.go +++ b/modules/structs/user.go @@ -43,6 +43,11 @@ 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"` } // MarshalJSON implements the json.Marshaler interface for User, adding field(s) for backward compatibility diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index 4f54b9049..23e133376 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -16345,6 +16345,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", @@ -16391,6 +16402,11 @@ "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",