mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-12-30 18:16:36 +08:00
增加用户系统文章相关管理
This commit is contained in:
63
internal/db/models/posts/post_dao.go
Normal file
63
internal/db/models/posts/post_dao.go
Normal file
@@ -0,0 +1,63 @@
|
||||
package posts
|
||||
|
||||
import (
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/iwind/TeaGo/Tea"
|
||||
"github.com/iwind/TeaGo/dbs"
|
||||
)
|
||||
|
||||
const (
|
||||
PostStateEnabled = 1 // 已启用
|
||||
PostStateDisabled = 0 // 已禁用
|
||||
)
|
||||
|
||||
type PostDAO dbs.DAO
|
||||
|
||||
func NewPostDAO() *PostDAO {
|
||||
return dbs.NewDAO(&PostDAO{
|
||||
DAOObject: dbs.DAOObject{
|
||||
DB: Tea.Env,
|
||||
Table: "edgePosts",
|
||||
Model: new(Post),
|
||||
PkName: "id",
|
||||
},
|
||||
}).(*PostDAO)
|
||||
}
|
||||
|
||||
var SharedPostDAO *PostDAO
|
||||
|
||||
func init() {
|
||||
dbs.OnReady(func() {
|
||||
SharedPostDAO = NewPostDAO()
|
||||
})
|
||||
}
|
||||
|
||||
// EnablePost 启用条目
|
||||
func (this *PostDAO) EnablePost(tx *dbs.Tx, postId int64) error {
|
||||
_, err := this.Query(tx).
|
||||
Pk(postId).
|
||||
Set("state", PostStateEnabled).
|
||||
Update()
|
||||
return err
|
||||
}
|
||||
|
||||
// DisablePost 禁用条目
|
||||
func (this *PostDAO) DisablePost(tx *dbs.Tx, postId int64) error {
|
||||
_, err := this.Query(tx).
|
||||
Pk(postId).
|
||||
Set("state", PostStateDisabled).
|
||||
Update()
|
||||
return err
|
||||
}
|
||||
|
||||
// FindEnabledPost 查找启用中的条目
|
||||
func (this *PostDAO) FindEnabledPost(tx *dbs.Tx, postId int64) (*Post, error) {
|
||||
result, err := this.Query(tx).
|
||||
Pk(postId).
|
||||
State(PostStateEnabled).
|
||||
Find()
|
||||
if result == nil {
|
||||
return nil, err
|
||||
}
|
||||
return result.(*Post), err
|
||||
}
|
||||
Reference in New Issue
Block a user