瀏覽代碼

Added API Version and URLs to User API

Yoginth 7 年之前
父節點
當前提交
2ddaaf1fc5

+ 5 - 0
gitote.go

@@ -24,8 +24,12 @@ import (
 // AppVer represents the version of Gitote
 const AppVer = "1.0.0-prod-rc.4"
 
+// APIVer represents the API version of Gitote
+const APIVer = "v1"
+
 func init() {
 	setting.AppVer = AppVer
+	setting.APIVer = APIVer
 }
 
 func main() {
@@ -33,6 +37,7 @@ func main() {
 	app.Name = "Gitote"
 	app.Usage = "Software version control made simple"
 	app.Version = AppVer
+	app.APIVersion = APIVer
 	app.Commands = []cli.Command{
 		cmd.Web,
 		cmd.Serv,

+ 19 - 15
models/user.go

@@ -152,21 +152,25 @@ func (u *User) IDStr() string {
 
 func (u *User) APIFormat() *api.User {
 	return &api.User{
-		ID:           u.ID,
-		UserName:     u.Name,
-		FullName:     u.FullName,
-		Website:      u.Website,
-		Company:      u.Company,
-		Location:     u.Location,
-		Description:  u.Description,
-		Email:        u.Email,
-		IsAdmin:      u.IsAdmin,
-		NumRepos:     u.NumRepos,
-		Created:      u.Created,
-		Updated:      u.Updated,
-		NumFollowing: u.NumFollowing,
-		NumFollowers: u.NumFollowers,
-		AvatarUrl:    u.AvatarLink(),
+		ID:               u.ID,
+		UserName:         u.Name,
+		FullName:         u.FullName,
+		Website:          u.Website,
+		Company:          u.Company,
+		Location:         u.Location,
+		Description:      u.Description,
+		Email:            u.Email,
+		IsAdmin:          u.IsAdmin,
+		NumRepos:         u.NumRepos,
+		Created:          u.Created,
+		Updated:          u.Updated,
+		NumFollowing:     u.NumFollowing,
+		NumFollowers:     u.NumFollowers,
+		AvatarUrl:        u.AvatarLink(),
+		FollowersURL:     setting.AppURL + "api/" + setting.APIVer + "/users/" + u.Name + "/followers",
+		FollowingURL:     setting.AppURL + "api/" + setting.APIVer + "/users/" + u.Name + "/following",
+		OrganizationsURL: setting.AppURL + "api/" + setting.APIVer + "/users/" + u.Name + "/orgs",
+		ReposURL:         setting.AppURL + "api/" + setting.APIVer + "/users/" + u.Name + "/repos",
 	}
 }
 

+ 1 - 0
pkg/setting/setting.go

@@ -49,6 +49,7 @@ var (
 
 	// App settings
 	AppVer         string
+	APIVer         string
 	AppName        string
 	AppURL         string
 	AppSubURL      string

+ 3 - 0
pkg/template/template.go

@@ -43,6 +43,9 @@ func NewFuncMap() []template.FuncMap {
 		"AppVer": func() string {
 			return setting.AppVer
 		},
+		"APIVer": func() string {
+			return setting.APIVer
+		},
 		"AppDomain": func() string {
 			return setting.Domain
 		},

+ 1 - 0
routes/dev/template.go

@@ -10,6 +10,7 @@ func TemplatePreview(c *context.Context) {
 	c.Data["User"] = models.User{Name: "Yoginth"}
 	c.Data["AppName"] = setting.AppName
 	c.Data["AppVer"] = setting.AppVer
+	c.Data["APIVer"] = setting.APIVer
 	c.Data["AppURL"] = setting.AppURL
 	c.Data["Code"] = "123456789"
 	c.Data["ActiveCodeLives"] = setting.Service.ActiveCodeLives / 60

+ 2 - 0
vendor/github.com/urfave/cli/app.go

@@ -37,6 +37,8 @@ type App struct {
 	ArgsUsage string
 	// Version of the program
 	Version string
+	// Version of the API
+	APIVersion string
 	// Description of the program
 	Description string
 	// List of commands to execute

+ 19 - 15
vendor/gitlab.com/gitote/go-gitote-client/user.go

@@ -8,21 +8,25 @@ import (
 
 // User represents a API user.
 type User struct {
-	ID           int64     `json:"id"`
-	UserName     string    `json:"login"`
-	FullName     string    `json:"full_name"`
-	Website      string    `json:"website"`
-	Email        string    `json:"email"`
-	Company      string    `json:"company"`
-	Location     string    `json:"location"`
-	Description  string    `json:"bio"`
-	IsAdmin      bool      `json:"site_admin"`
-	NumRepos     int       `json:"repos"`
-	Created      time.Time `json:"created_at"`
-	Updated      time.Time `json:"updated_at"`
-	NumFollowing int       `json:"following"`
-	NumFollowers int       `json:"followers"`
-	AvatarUrl    string    `json:"avatar_url"`
+	ID               int64     `json:"id"`
+	UserName         string    `json:"login"`
+	FullName         string    `json:"full_name"`
+	Website          string    `json:"website"`
+	Email            string    `json:"email"`
+	Company          string    `json:"company"`
+	Location         string    `json:"location"`
+	Description      string    `json:"bio"`
+	IsAdmin          bool      `json:"site_admin"`
+	NumRepos         int       `json:"repos"`
+	Created          time.Time `json:"created_at"`
+	Updated          time.Time `json:"updated_at"`
+	NumFollowing     int       `json:"following"`
+	NumFollowers     int       `json:"followers"`
+	AvatarUrl        string    `json:"avatar_url"`
+	FollowersURL     string    `json:"followers_url"`
+	FollowingURL     string    `json:"following_url"`
+	OrganizationsURL string    `json:"organizations_url"`
+	ReposURL         string    `json:"repos_url"`
 }
 
 // MarshalJSON implements the json.Marshaler interface for User