From ea765d25e21a5e2ff67ff39891962f5f23facda8 Mon Sep 17 00:00:00 2001 From: Unknown Date: Thu, 13 Mar 2014 02:09:36 -0400 Subject: [PATCH] Update action struct --- models/action.go | 31 ++++++++++++------------------- routers/user/user.go | 17 +++-------------- web.go | 7 +------ 3 files changed, 16 insertions(+), 39 deletions(-) diff --git a/models/action.go b/models/action.go index cae093ecb..810f24b65 100644 --- a/models/action.go +++ b/models/action.go @@ -5,7 +5,6 @@ package models import ( - "encoding/json" "time" ) @@ -21,30 +20,24 @@ const ( // An Action represents type Action struct { - Id int64 - UserId int64 - OpType int - RepoId int64 - Content string - Created time.Time `xorm:"created"` -} - -type NewRepoContent struct { + Id int64 + UserId int64 UserName string + OpType int + RepoId int64 RepoName string + Content string + Created time.Time `xorm:"created"` } // NewRepoAction inserts action for create repository. func NewRepoAction(user *User, repo *Repository) error { - content, err := json.Marshal(&NewRepoContent{user.Name, repo.Name}) - if err != nil { - return err - } - _, err = orm.InsertOne(&Action{ - UserId: user.Id, - OpType: OP_CREATE_REPO, - RepoId: repo.Id, - Content: string(content), + _, err := orm.InsertOne(&Action{ + UserId: user.Id, + UserName: user.Name, + OpType: OP_CREATE_REPO, + RepoId: repo.Id, + RepoName: repo.Name, }) return err } diff --git a/routers/user/user.go b/routers/user/user.go index ae9dd9029..59177a47b 100644 --- a/routers/user/user.go +++ b/routers/user/user.go @@ -5,7 +5,6 @@ package user import ( - "bytes" "net/http" "github.com/codegangsta/martini" @@ -167,20 +166,10 @@ func Delete(data base.TmplData, req *http.Request, session sessions.Session, r r r.HTML(200, "user/delete", data) } -func Feeds(form auth.FeedsForm, r render.Render) string { +func Feeds(form auth.FeedsForm, r render.Render) { actions, err := models.GetFeeds(form.UserId, form.Offset) if err != nil { - return err.Error() + r.JSON(500, err) } - - length := len(actions) - buf := bytes.NewBuffer([]byte("[")) - for i, action := range actions { - buf.WriteString(action.Content) - if i < length-1 { - buf.WriteString(",") - } - } - buf.WriteString("]") - return buf.String() + r.JSON(200, actions) } diff --git a/web.go b/web.go index 8e5bbaef0..9b7eff883 100644 --- a/web.go +++ b/web.go @@ -30,10 +30,7 @@ var CmdWeb = cli.Command{ Description: ` gogs web`, Action: runWeb, - Flags: []cli.Flag{ - //cli.BoolFlag{"update, u", "update pakcage(s) and dependencies if any"}, - //cli.BoolFlag{"verbose, v", "show process details"}, - }, + Flags: []cli.Flag{}, } var AppHelpers template.FuncMap = map[string]interface{}{ @@ -78,8 +75,6 @@ func runWeb(*cli.Context) { //m.Get("/:username/:reponame", repo.Repo) - //m.Get("/:username/:reponame", repo.Repo) - listenAddr := fmt.Sprintf("%s:%s", base.Cfg.MustValue("server", "HTTP_ADDR"), base.Cfg.MustValue("server", "HTTP_PORT", "3000"))