feat: add incrment of views
This commit is contained in:
@@ -26,6 +26,21 @@ func (m *postsModel) Prepare() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *postsModel) IncrViewCount(ctx context.Context, id int64) error {
|
||||
tbl := table.Posts
|
||||
|
||||
stmt := tbl.UPDATE(tbl.Views).SET(tbl.Views.ADD(Int64(1))).WHERE(tbl.ID.EQ(Int64(id)))
|
||||
m.log.Infof("sql: %s", stmt.DebugSql())
|
||||
|
||||
var post model.Posts
|
||||
err := stmt.QueryContext(ctx, db, &post)
|
||||
if err != nil {
|
||||
m.log.Errorf("error updating post view count: %v", err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetByID
|
||||
func (m *postsModel) GetByID(ctx context.Context, id int64, cond ...conds.Cond) (*model.Posts, error) {
|
||||
tbl := table.Posts
|
||||
|
||||
Reference in New Issue
Block a user