You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
paopao-ce/internal/dao/tag.go

46 lines
909 B

3 years ago
package dao
import (
"github.com/rocboss/paopao-ce/internal/model"
"gorm.io/gorm"
)
3 years ago
func (d *dataServant) CreateTag(tag *model.Tag) (*model.Tag, error) {
return d.createTag(d.engine, tag)
}
func (d *dataServant) DeleteTag(tag *model.Tag) error {
return d.deleteTag(d.engine, tag)
}
func (d *dataServant) GetTags(conditions *model.ConditionsT, offset, limit int) ([]*model.Tag, error) {
return (&model.Tag{}).List(d.engine, conditions, offset, limit)
}
func (d *dataServant) createTag(db *gorm.DB, tag *model.Tag) (*model.Tag, error) {
3 years ago
t, err := tag.Get(d.engine)
if err != nil {
tag.QuoteNum = 1
return tag.Create(db)
3 years ago
}
// 更新
t.QuoteNum++
err = t.Update(db)
3 years ago
if err != nil {
return nil, err
}
return t, nil
}
func (d *dataServant) deleteTag(db *gorm.DB, tag *model.Tag) error {
tag, err := tag.Get(db)
3 years ago
if err != nil {
return err
}
tag.QuoteNum--
return tag.Update(db)
3 years ago
}