@@ -15,7 +15,7 @@ import (
1515 "github.com/mindoc-org/mindoc/utils"
1616)
1717
18- //博文表
18+ // 博文表
1919type Blog struct {
2020 BlogId int `orm:"pk;auto;unique;column(blog_id)" json:"blog_id"`
2121 //文章标题
@@ -89,7 +89,7 @@ func NewBlog() *Blog {
8989 }
9090}
9191
92- //根据文章ID查询文章
92+ // 根据文章ID查询文章
9393func (b * Blog ) Find (blogId int ) (* Blog , error ) {
9494 o := orm .NewOrm ()
9595
@@ -102,7 +102,7 @@ func (b *Blog) Find(blogId int) (*Blog, error) {
102102 return b .Link ()
103103}
104104
105- //从缓存中读取文章
105+ // 从缓存中读取文章
106106func (b * Blog ) FindFromCache (blogId int ) (blog * Blog , err error ) {
107107 key := fmt .Sprintf ("blog-id-%d" , blogId )
108108 var temp Blog
@@ -126,7 +126,7 @@ func (b *Blog) FindFromCache(blogId int) (blog *Blog, err error) {
126126 return
127127}
128128
129- //查找指定用户的指定文章
129+ // 查找指定用户的指定文章
130130func (b * Blog ) FindByIdAndMemberId (blogId , memberId int ) (* Blog , error ) {
131131 o := orm .NewOrm ()
132132
@@ -139,7 +139,7 @@ func (b *Blog) FindByIdAndMemberId(blogId, memberId int) (*Blog, error) {
139139 return b .Link ()
140140}
141141
142- //根据文章标识查询文章
142+ // 根据文章标识查询文章
143143func (b * Blog ) FindByIdentify (identify string ) (* Blog , error ) {
144144 o := orm .NewOrm ()
145145
@@ -151,7 +151,7 @@ func (b *Blog) FindByIdentify(identify string) (*Blog, error) {
151151 return b , nil
152152}
153153
154- //获取指定文章的链接内容
154+ // 获取指定文章的链接内容
155155func (b * Blog ) Link () (* Blog , error ) {
156156 o := orm .NewOrm ()
157157 //如果是链接文章,则需要从链接的项目中查找文章内容
@@ -211,14 +211,14 @@ func (b *Blog) Link() (*Blog, error) {
211211 return b , nil
212212}
213213
214- //判断指定的文章标识是否存在
214+ // 判断指定的文章标识是否存在
215215func (b * Blog ) IsExist (identify string ) bool {
216216 o := orm .NewOrm ()
217217
218218 return o .QueryTable (b .TableNameWithPrefix ()).Filter ("blog_identify" , identify ).Exist ()
219219}
220220
221- //保存文章
221+ // 保存文章
222222func (b * Blog ) Save (cols ... string ) error {
223223 o := orm .NewOrm ()
224224
@@ -239,7 +239,7 @@ func (b *Blog) Save(cols ...string) error {
239239 b .Modified = time .Now ()
240240 _ , err = o .Update (b , cols ... )
241241 key := fmt .Sprintf ("blog-id-%d" , b .BlogId )
242- cache .Delete (key )
242+ _ = cache .Delete (key )
243243
244244 } else {
245245
@@ -250,7 +250,7 @@ func (b *Blog) Save(cols ...string) error {
250250 return err
251251}
252252
253- //过滤文章的危险标签,处理文章外链以及图片.
253+ // 过滤文章的危险标签,处理文章外链以及图片.
254254func (b * Blog ) Processor () * Blog {
255255
256256 b .BlogRelease = utils .SafetyProcessor (b .BlogRelease )
@@ -285,7 +285,7 @@ func (b *Blog) Processor() *Blog {
285285 return b
286286}
287287
288- //分页查询文章列表
288+ // 分页查询文章列表
289289func (b * Blog ) FindToPager (pageIndex , pageSize int , memberId int , status string ) (blogList []* Blog , totalCount int , err error ) {
290290
291291 o := orm .NewOrm ()
@@ -297,10 +297,14 @@ func (b *Blog) FindToPager(pageIndex, pageSize int, memberId int, status string)
297297 if memberId > 0 {
298298 query = query .Filter ("member_id" , memberId )
299299 }
300- if status != "" {
300+ if status != "" && status != "all" {
301301 query = query .Filter ("blog_status" , status )
302302 }
303303
304+ if status == "" {
305+ query = query .Filter ("blog_status__ne" , "private" )
306+ }
307+
304308 _ , err = query .OrderBy ("-order_index" , "-blog_id" ).Offset (offset ).Limit (pageSize ).All (& blogList )
305309
306310 if err != nil {
@@ -326,8 +330,11 @@ func (b *Blog) FindToPager(pageIndex, pageSize int, memberId int, status string)
326330 return
327331}
328332
329- //删除文章
333+ // 删除文章
330334func (b * Blog ) Delete (blogId int ) error {
335+ // 删除文章缓存
336+ key := fmt .Sprintf ("blog-id-%d" , blogId )
337+ _ = cache .Delete (key )
331338 o := orm .NewOrm ()
332339
333340 _ , err := o .QueryTable (b .TableNameWithPrefix ()).Filter ("blog_id" , blogId ).Delete ()
@@ -337,7 +344,7 @@ func (b *Blog) Delete(blogId int) error {
337344 return err
338345}
339346
340- //查询下一篇文章
347+ // 查询下一篇文章
341348func (b * Blog ) QueryNext (blogId int ) (* Blog , error ) {
342349 o := orm .NewOrm ()
343350 blog := NewBlog ()
@@ -355,7 +362,7 @@ func (b *Blog) QueryNext(blogId int) (*Blog, error) {
355362 return blog , err
356363}
357364
358- //查询下一篇文章
365+ // 查询下一篇文章
359366func (b * Blog ) QueryPrevious (blogId int ) (* Blog , error ) {
360367 o := orm .NewOrm ()
361368 blog := NewBlog ()
@@ -373,7 +380,7 @@ func (b *Blog) QueryPrevious(blogId int) (*Blog, error) {
373380 return blog , err
374381}
375382
376- //关联文章附件
383+ // 关联文章附件
377384func (b * Blog ) LinkAttach () (err error ) {
378385
379386 o := orm .NewOrm ()
0 commit comments