sum7/warehost
sum7
/
warehost
Archived
1
0
Fork 0

[BUGFIX] blog get right post and order of posts

This commit is contained in:
Martin Geno 2017-04-23 09:45:23 +02:00
parent 14ff889bba
commit e3886606fc
No known key found for this signature in database
GPG Key ID: F0D39A37E925E941
1 changed files with 6 additions and 2 deletions

View File

@ -8,6 +8,8 @@ import (
"strings" "strings"
"text/template" "text/template"
"github.com/jinzhu/gorm"
liblog "dev.sum7.eu/sum7/warehost/lib/log" liblog "dev.sum7.eu/sum7/warehost/lib/log"
web "dev.sum7.eu/sum7/warehost/modul/web" web "dev.sum7.eu/sum7/warehost/modul/web"
) )
@ -106,9 +108,11 @@ func handlerfunc(w http.ResponseWriter, r *http.Request) {
if !dbconnection.Where(page).First(&page).RecordNotFound() { if !dbconnection.Where(page).First(&page).RecordNotFound() {
page.URL = urlObj page.URL = urlObj
} else { } else {
if !dbconnection.Where(blog).Preload("Posts").First(&blog).RecordNotFound() { if !dbconnection.Where(blog).Preload("Posts", func(db *gorm.DB) *gorm.DB {
return db.Order("createat DESC")
}).First(&blog).RecordNotFound() {
blogpost.BlogID = blog.ID blogpost.BlogID = blog.ID
if urlObj.Path != blogpost.Title && ((blog.PostURL == 0 && len(urlParts) > 1) || (blog.PostURL == 1 && len(urlParts) > 2)) { if (blog.PostURL == 0 && len(urlParts) > 1) || (blog.PostURL == 1 && len(urlParts) > 2) {
db := dbconnection.Where(blogpost).Where("LOWER(title) = LOWER(?)", urlParts[len(urlParts)-1]) db := dbconnection.Where(blogpost).Where("LOWER(title) = LOWER(?)", urlParts[len(urlParts)-1])
if blog.PostURL == 1 { if blog.PostURL == 1 {
db = db.Where("to_char(createat,'YYYY-MM') = ?", strings.Join(urlParts[len(urlParts)-3:len(urlParts)-1], "-")) db = db.Where("to_char(createat,'YYYY-MM') = ?", strings.Join(urlParts[len(urlParts)-3:len(urlParts)-1], "-"))