From 083c3ee659c6c5542687f3bafae68cbc24dbc90f Mon Sep 17 00:00:00 2001 From: Joe Chen Date: Sat, 25 Jun 2022 18:07:39 +0800 Subject: db: refactor "action" table to use GORM (#7054) Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com> --- internal/route/user/auth.go | 4 ++-- internal/route/user/home.go | 12 ++++++++++-- internal/route/user/profile.go | 2 +- 3 files changed, 13 insertions(+), 5 deletions(-) (limited to 'internal/route/user') diff --git a/internal/route/user/auth.go b/internal/route/user/auth.go index cae46853..38751cb6 100644 --- a/internal/route/user/auth.go +++ b/internal/route/user/auth.go @@ -102,7 +102,7 @@ func Login(c *context.Context) { } // Display normal login page - loginSources, err := db.LoginSources.List(c.Req.Context(), db.ListLoginSourceOpts{OnlyActivated: true}) + loginSources, err := db.LoginSources.List(c.Req.Context(), db.ListLoginSourceOptions{OnlyActivated: true}) if err != nil { c.Error(err, "list activated login sources") return @@ -149,7 +149,7 @@ func afterLogin(c *context.Context, u *db.User, remember bool) { func LoginPost(c *context.Context, f form.SignIn) { c.Title("sign_in") - loginSources, err := db.LoginSources.List(c.Req.Context(), db.ListLoginSourceOpts{OnlyActivated: true}) + loginSources, err := db.LoginSources.List(c.Req.Context(), db.ListLoginSourceOptions{OnlyActivated: true}) if err != nil { c.Error(err, "list activated login sources") return diff --git a/internal/route/user/home.go b/internal/route/user/home.go index a7892075..a14572ed 100644 --- a/internal/route/user/home.go +++ b/internal/route/user/home.go @@ -53,9 +53,17 @@ func getDashboardContextUser(c *context.Context) *db.User { // The user could be organization so it is not always the logged in user, // which is why we have to explicitly pass the context user ID. func retrieveFeeds(c *context.Context, ctxUser *db.User, userID int64, isProfile bool) { - actions, err := db.GetFeeds(ctxUser, userID, c.QueryInt64("after_id"), isProfile) + afterID := c.QueryInt64("after_id") + + var err error + var actions []*db.Action + if ctxUser.IsOrganization() { + actions, err = db.Actions.ListByOrganization(c.Req.Context(), ctxUser.ID, userID, afterID) + } else { + actions, err = db.Actions.ListByUser(c.Req.Context(), ctxUser.ID, userID, afterID, isProfile) + } if err != nil { - c.Error(err, "get feeds") + c.Error(err, "list actions") return } diff --git a/internal/route/user/profile.go b/internal/route/user/profile.go index 3baee4e3..25127028 100644 --- a/internal/route/user/profile.go +++ b/internal/route/user/profile.go @@ -54,7 +54,7 @@ func Profile(c *context.Context, puser *context.ParamsUser) { c.Data["TabName"] = tab switch tab { case "activity": - retrieveFeeds(c, puser.User, -1, true) + retrieveFeeds(c, puser.User, c.UserID(), true) if c.Written() { return } -- cgit v1.2.3