]> source.dussan.org Git - gitea.git/commitdiff
[API] User expose counters (#16167)
author6543 <6543@obermui.de>
Thu, 17 Jun 2021 07:17:35 +0000 (09:17 +0200)
committerGitHub <noreply@github.com>
Thu, 17 Jun 2021 07:17:35 +0000 (09:17 +0200)
modules/convert/user.go
modules/structs/user.go
templates/swagger/v1_json.tmpl

index 088ede5add5079cdbb2c5b0d0b60cc9453e9228a..c588f5f2f076b9661e8c0b86360116ad75066f1c 100644 (file)
@@ -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) {
index 2dbc5305382ab52e78b998456b1e770515b2dfc3..de2e68c2a2e304534673d791fdc59ce00cbbf472 100644 (file)
@@ -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
index 4f54b9049216e1191641514772e4466ff3662b5a..23e133376778d5962d3dc415b503459fc0e62d80 100644 (file)
           "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",
           "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",