Commit f1aecf6b authored by zauberstuhl's avatar zauberstuhl
Browse files

Fix uint calculation and not every person has a pod e.g local users

parent 7a390505
......@@ -19,6 +19,7 @@ package controllers
import (
"github.com/revel/revel"
"git.feneas.org/ganggo/ganggo/app/helpers"
"git.feneas.org/ganggo/ganggo/app/models"
)
......@@ -32,7 +33,6 @@ func (p Profile) Index(guid string) revel.Result {
func (p Profile) IndexPagination(guid string, page uint) revel.Result {
var (
offset uint = ((page - 1) * 10)
posts models.Posts
person models.Person
)
......@@ -48,7 +48,7 @@ func (p Profile) IndexPagination(guid string, page uint) revel.Result {
p.ViewArgs["currentUser"] = user
}
err = posts.FindAllByUserAndPersonID(user, person.ID, offset)
err = posts.FindAllByUserAndPersonID(user, person.ID, helpers.PageOffset(page))
if err != nil {
p.Log.Error("Cannot find posts", "error", err)
return p.RenderError(err)
......
......@@ -34,7 +34,6 @@ func (s Search) Index(text string) revel.Result {
}
func (s Search) IndexPagination(text string, page uint) revel.Result {
var offset uint = ((page - 1) * 10)
text = strings.Replace(text, "'", "", -1)
text = strings.Replace(text, "\"", "", -1)
......@@ -46,7 +45,7 @@ func (s Search) IndexPagination(text string, page uint) revel.Result {
s.ViewArgs["currentUser"] = user
var posts models.Posts
err = posts.FindAllByUserAndText(user, text, offset)
err = posts.FindAllByUserAndText(user, text, helpers.PageOffset(page))
if err != nil {
s.Log.Error("Cannot find posts", "error", err)
return s.RenderError(err)
......
......@@ -19,6 +19,7 @@ package controllers
import (
"github.com/revel/revel"
"git.feneas.org/ganggo/ganggo/app/helpers"
"git.feneas.org/ganggo/ganggo/app/models"
)
......@@ -28,7 +29,7 @@ type Stream struct {
func (s Stream) Index(view string, page uint) revel.Result {
var posts models.Posts
var offset uint = ((page - 1) * 10)
var offset = helpers.PageOffset(page)
user, err := models.CurrentUser(s.Controller)
if err == nil {
......
......@@ -20,6 +20,7 @@ package controllers
import (
"sort"
"github.com/revel/revel"
"git.feneas.org/ganggo/ganggo/app/helpers"
"git.feneas.org/ganggo/ganggo/app/models"
)
......@@ -35,7 +36,6 @@ func (t Tag) IndexPagination(name string, page uint) revel.Result {
var (
posts models.Posts
tag models.Tag
offset uint = ((page - 1) * 10)
)
user, err := models.CurrentUser(t.Controller)
......@@ -43,7 +43,7 @@ func (t Tag) IndexPagination(name string, page uint) revel.Result {
t.ViewArgs["currentUser"] = user
}
err = tag.FindByName(name, user, offset)
err = tag.FindByName(name, user, helpers.PageOffset(page))
if err != nil || len(tag.ShareableTaggings) <= 0 {
return t.NotFound(
revel.MessageFunc(t.Request.Locale, "errors.controller.post_not_found"),
......
......@@ -19,6 +19,13 @@ package helpers
import "github.com/revel/revel"
func PageOffset(page uint) uint {
if page == 0 {
return page
}
return (page - 1) * 10
}
func IsLocalHandle(handle string) bool {
revel.Config.SetSection("ganggo")
localhost, found := revel.Config.String("address")
......
......@@ -49,10 +49,7 @@ func (person *Person) AfterFind(db *gorm.DB) error {
return nil
}
err := db.Model(person).Related(&person.Pod).Error
if err != nil && person.UserID <= 0 {
return err
}
db.Model(person).Related(&person.Pod)
return db.Model(person).Related(&person.Profile).Error
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment