diff --git a/service/archivesrv.go b/service/archivesrv.go index 8595889a..08e4cfd7 100644 --- a/service/archivesrv.go +++ b/service/archivesrv.go @@ -29,7 +29,7 @@ type archiveService struct { func (srv *archiveService) GetArchives(blogID uint64) []*model.Archive { var ret []*model.Archive - if err := db.Where(" blog_id = ? AND article_count > 0", blogID).Order(" year DESC, month DESC").Find(&ret).Error; nil != err { + if err := db.Where(" blog_id = ? AND article_count > 0", blogID).Order("year DESC, month DESC").Find(&ret).Error; nil != err { logger.Error("get archives failed: " + err.Error()) } diff --git a/service/articlesrv.go b/service/articlesrv.go index ede71bac..6d8b0e17 100644 --- a/service/articlesrv.go +++ b/service/articlesrv.go @@ -46,7 +46,7 @@ const ( func (srv *articleService) GetPlatMostViewArticles(size int) (ret []*model.Article) { if err := db.Model(&model.Article{}).Select(" id, created_at, author_id, title, path, view_count, comment_count, blog_id "). Where(" status = ?", model.ArticleStatusOK). - Order(" view_count DESC, created_at DESC").Limit(size).Find(&ret).Error; nil != err { + Order("view_count DESC, created_at DESC").Limit(size).Find(&ret).Error; nil != err { logger.Errorf("get platform most view articles failed: " + err.Error()) } @@ -79,7 +79,7 @@ func (srv *articleService) GetArchiveArticles(archiveID uint64, page int, blogID if err := db.Model(&model.Article{}). Where(" id IN (?) AND status = ? AND blog_id = ?", articleIDs, model.ArticleStatusOK, blogID). - Order(" topped DESC, created_at DESC").Count(&count). + Order("topped DESC, created_at DESC").Count(&count). Offset(offset).Limit(pageSize). Find(&ret).Error; nil != err { logger.Errorf("get archive articles failed: " + err.Error()) @@ -92,7 +92,7 @@ func (srv *articleService) GetArchiveArticles(archiveID uint64, page int, blogID func (srv *articleService) GetPreviousArticle(id uint64, blogID uint64) *model.Article { ret := &model.Article{} - if err := db.Where(" id < ? AND blog_id = ?", id, blogID).Order(" created_at DESC").Limit(1).Find(ret).Error; nil != err { + if err := db.Where("id < ? AND blog_id = ?", id, blogID).Order("created_at DESC").Limit(1).Find(ret).Error; nil != err { return nil } @@ -191,7 +191,7 @@ func (srv *articleService) ConsoleGetArticles(keyword string, page int, blogID u if err := db.Model(&model.Article{}).Select(" id , created_at , author_id , title , tags , path , topped , view_count , comment_count "). Where(where, whereArgs...). - Order(" topped DESC, created_at DESC").Count(&count). + Order("topped DESC, created_at DESC").Count(&count). Offset(offset).Limit(adminConsoleArticleListPageSize).Find(&ret).Error; nil != err { logger.Errorf("get articles failed: " + err.Error()) } @@ -215,7 +215,7 @@ func (srv *articleService) GetArticles(keyword string, page int, blogID uint64) if err := db.Model(&model.Article{}).Select(" id , created_at , author_id , title , abstract , content , tags , path , topped , view_count , comment_count "). Where(where, whereArgs...). - Order(" topped DESC, created_at DESC").Count(&count). + Order("topped DESC, created_at DESC").Count(&count). Offset(offset).Limit(pageSize). Find(&ret).Error; nil != err { logger.Errorf("get articles failed: " + err.Error()) @@ -244,7 +244,7 @@ func (srv *articleService) GetCategoryArticles(categoryID uint64, page int, blog count := 0 rels = []*model.Correlation{} if err := db.Model(&model.Correlation{}).Where(" id2 IN (?) AND type = ? AND blog_id = ?", tagIDs, model.CorrelationArticleTag, blogID). - Order(" id DESC").Count(&count).Offset(offset).Limit(pageSize). + Order("id DESC").Count(&count).Offset(offset).Limit(pageSize). Find(&rels).Error; nil != err { return } @@ -281,7 +281,7 @@ func (srv *articleService) GetTagArticles(tagID uint64, page int, blogID uint64) if err := db.Model(&model.Article{}). Where(" id IN (?) AND status = ? AND blog_id = ?", articleIDs, model.ArticleStatusOK, blogID). - Order(" topped DESC, created_at DESC").Count(&count).Offset(offset).Limit(pageSize). + Order("topped DESC, created_at DESC").Count(&count).Offset(offset).Limit(pageSize). Find(&ret).Error; nil != err { logger.Errorf("get tag articles failed: " + err.Error()) } @@ -298,7 +298,7 @@ func (srv *articleService) GetAuthorArticles(authorID uint64, page int, blogID u if err := db.Model(&model.Article{}). Where(" author_id = ? AND status = ? AND blog_id = ?", authorID, model.ArticleStatusOK, blogID). - Order(" topped DESC, created_at DESC").Count(&count). + Order("topped DESC, created_at DESC").Count(&count). Offset(offset).Limit(pageSize). Find(&ret).Error; nil != err { logger.Errorf("get author articles failed: " + err.Error()) @@ -312,7 +312,7 @@ func (srv *articleService) GetAuthorArticles(authorID uint64, page int, blogID u func (srv *articleService) GetMostViewArticles(size int, blogID uint64) (ret []*model.Article) { if err := db.Model(&model.Article{}).Select(" id , created_at , author_id , title , path "). Where(" status = ? AND blog_id = ?", model.ArticleStatusOK, blogID). - Order(" view_count DESC, created_at DESC").Limit(size).Find(&ret).Error; nil != err { + Order("view_count DESC, created_at DESC").Limit(size).Find(&ret).Error; nil != err { logger.Errorf("get most view articles failed: " + err.Error()) } @@ -322,7 +322,7 @@ func (srv *articleService) GetMostViewArticles(size int, blogID uint64) (ret []* func (srv *articleService) GetMostCommentArticles(size int, blogID uint64) (ret []*model.Article) { if err := db.Model(&model.Article{}).Select(" id , created_at , author_id , title , path "). Where(" status = ? AND blog_id = ?", model.ArticleStatusOK, blogID). - Order(" comment_count DESC, id DESC").Limit(size).Find(&ret).Error; nil != err { + Order("comment_count DESC, id DESC").Limit(size).Find(&ret).Error; nil != err { logger.Errorf("get most comment articles failed: " + err.Error()) } diff --git a/service/categorysrv.go b/service/categorysrv.go index 7c9b373e..91ca9551 100644 --- a/service/categorysrv.go +++ b/service/categorysrv.go @@ -172,7 +172,7 @@ func (srv *categoryService) GetCategoriesByTag(tagTitle string, blogID uint64) ( func (srv *categoryService) ConsoleGetCategories(page int, blogID uint64) (ret []*model.Category, pagination *util.Pagination) { offset := (page - 1) * adminConsoleCategoryListPageSize count := 0 - if err := db.Model(&model.Category{}).Order(" number ASC, id DESC"). + if err := db.Model(&model.Category{}).Order("number ASC, id DESC"). Where(" blog_id = ?", blogID). Count(&count).Offset(offset).Limit(adminConsoleCategoryListPageSize).Find(&ret).Error; nil != err { logger.Errorf("get categories failed: " + err.Error()) @@ -184,7 +184,7 @@ func (srv *categoryService) ConsoleGetCategories(page int, blogID uint64) (ret [ } func (srv *categoryService) GetCategories(size int, blogID uint64) (ret []*model.Category) { - if err := db.Where(" blog_id = ?", blogID).Order(" number asc").Limit(size).Find(&ret).Error; nil != err { + if err := db.Where("blog_id = ?", blogID).Order("number asc").Limit(size).Find(&ret).Error; nil != err { logger.Errorf("get categories failed: " + err.Error()) } diff --git a/service/commentsrv.go b/service/commentsrv.go index 4fa26926..e9528bcb 100644 --- a/service/commentsrv.go +++ b/service/commentsrv.go @@ -106,7 +106,7 @@ func (srv *commentService) ConsoleGetComments(keyword string, page int, blogID u } if err := db.Model(&model.Comment{}). - Where(where, whereArgs...).Order(" created_at DESC"). + Where(where, whereArgs...).Order("created_at DESC"). Count(&count).Offset(offset).Limit(adminConsoleCommentListPageSize).Find(&ret).Error; nil != err { logger.Errorf("get comments failed: " + err.Error()) } @@ -119,7 +119,7 @@ func (srv *commentService) ConsoleGetComments(keyword string, page int, blogID u func (srv *commentService) GetRecentComments(size int, blogID uint64) (ret []*model.Comment) { if err := db.Model(&model.Comment{}).Select(" id , created_at , content , author_id , article_id , author_name , author_avatar_url , author_url "). Where(" blog_id = ?", blogID). - Order(" created_at DESC, id DESC").Limit(size).Find(&ret).Error; nil != err { + Order("created_at DESC, id DESC").Limit(size).Find(&ret).Error; nil != err { logger.Errorf("get recent comments failed: " + err.Error()) } @@ -129,7 +129,7 @@ func (srv *commentService) GetRecentComments(size int, blogID uint64) (ret []*mo func (srv *commentService) GetArticleComments(articleID uint64, page int, blogID uint64) (ret []*model.Comment, pagination *util.Pagination) { offset := (page - 1) * themeCommentListPageSize count := 0 - if err := db.Model(&model.Comment{}).Order(" id ASC"). + if err := db.Model(&model.Comment{}).Order("id ASC"). Where(" article_id = ? AND blog_id = ?", articleID, blogID). Count(&count).Offset(offset).Limit(themeCommentListPageSize).Find(&ret).Error; nil != err { logger.Errorf("get comments failed: " + err.Error()) diff --git a/service/navigationsrv.go b/service/navigationsrv.go index b31e6ece..dce82dab 100644 --- a/service/navigationsrv.go +++ b/service/navigationsrv.go @@ -98,8 +98,8 @@ func (srv *navigationService) UpdateNavigation(navigation *model.Navigation) err func (srv *navigationService) ConsoleGetNavigations(page int, blogID uint64) (ret []*model.Navigation, pagination *util.Pagination) { offset := (page - 1) * adminConsoleNavigationListPageSize count := 0 - if err := db.Model(&model.Navigation{}).Order(" number ASC, id DESC"). - Where(" blog_id = ?", blogID). + if err := db.Model(&model.Navigation{}).Order("number ASC, id DESC"). + Where("blog_id = ?", blogID). Count(&count).Offset(offset).Limit(adminConsoleNavigationListPageSize).Find(&ret).Error; nil != err { logger.Errorf("get navigations failed: " + err.Error()) } @@ -110,8 +110,8 @@ func (srv *navigationService) ConsoleGetNavigations(page int, blogID uint64) (re } func (srv *navigationService) GetNavigations(blogID uint64) (ret []*model.Navigation) { - if err := db.Model(&model.Navigation{}).Order(" number ASC, id DESC"). - Where(" blog_id = ?", blogID).Find(&ret).Error; nil != err { + if err := db.Model(&model.Navigation{}).Order("number ASC, id DESC"). + Where("blog_id = ?", blogID).Find(&ret).Error; nil != err { logger.Errorf("get navigations failed: " + err.Error()) } diff --git a/service/tagsrv.go b/service/tagsrv.go index 4cd7dd27..22ec631b 100644 --- a/service/tagsrv.go +++ b/service/tagsrv.go @@ -43,7 +43,7 @@ func (srv *tagService) ConsoleGetTags(keyword string, page int, blogID uint64) ( whereArgs = append(whereArgs, "%"+keyword+"%") } - if err := db.Model(&model.Tag{}).Order(" id DESC"). + if err := db.Model(&model.Tag{}).Order("id DESC"). Where(where, whereArgs...). Count(&count).Offset(offset).Limit(adminConsoleTagListPageSize).Find(&ret).Error; nil != err { logger.Errorf("get tags failed: " + err.Error()) @@ -55,7 +55,7 @@ func (srv *tagService) ConsoleGetTags(keyword string, page int, blogID uint64) ( } func (srv *tagService) GetTags(size int, blogID uint64) (ret []*model.Tag) { - if err := db.Where(" blog_id = ?", blogID).Order(" article_count DESC, id DESC").Limit(size).Find(&ret).Error; nil != err { + if err := db.Where(" blog_id = ?", blogID).Order("article_count DESC, id DESC").Limit(size).Find(&ret).Error; nil != err { logger.Errorf("get tags failed: " + err.Error()) } diff --git a/service/usersrv.go b/service/usersrv.go index 4a3f3119..79f6c000 100644 --- a/service/usersrv.go +++ b/service/usersrv.go @@ -56,7 +56,7 @@ func (srv *userService) GetBlogAdmin(blogID uint64) *model.User { func (srv *userService) GetPlatformAdmin() *model.User { rel := &model.Correlation{ID1: 1} - if err := db.Where(rel).Order("id2 asc").First(rel).Error; nil != err { + if err := db.Where(rel).Order("id2 ASC").First(rel).Error; nil != err { logger.Errorf("can't get platform admin: " + err.Error()) return nil @@ -258,7 +258,7 @@ func (srv *userService) AddUserToBlog(userID, blogID uint64) error { func (srv *userService) GetTopBlogs(size int) (ret []*UserBlog) { var users []*model.User - if err := db.Model(&model.User{}).Order(" total_article_count DESC, id DESC").Limit(size). + if err := db.Model(&model.User{}).Order("total_article_count DESC, id DESC").Limit(size). Find(&users).Error; nil != err { return }