码农笔录博客源码
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

106 wiersze
2.2 KiB

6 lat temu
package service
import (
"beeblog/models"
"github.com/astaxie/beego/orm"
"errors"
6 lat temu
)
type NoteService struct {
}
6 lat temu
func (this *NoteService) EditNote(note *models.Note) error {
o := orm.NewOrm()
id, err := o.Update(note)
if err == nil {
note.Id = id
}
return err
}
6 lat temu
func (this *NoteService) SaveNote(note *models.Note) error {
6 lat temu
o := orm.NewOrm()
id, err := o.Insert(note)
if err == nil {
note.Id = id
}
return err
}
6 lat temu
func (this *NoteService) GetNote(note *models.Note) error {
6 lat temu
o := orm.NewOrm()
return o.Read(note)
}
6 lat temu
func (this *NoteService) DelNote(note *models.Note) error {
o := orm.NewOrm()
_, err := o.Delete(note)
return err
}
6 lat temu
func (this *NoteService) GetNoteByPid(pid int64) ([]*models.Note, error) {
6 lat temu
var notes []*models.Note
o := orm.NewOrm()
qs := o.QueryTable(models.Note{})
6 lat temu
_, err := qs.Filter("Pid", pid).All(&notes)
return notes, err
6 lat temu
}
6 lat temu
func (this *NoteService) CountNote(pid int64) (int64, error) {
o := orm.NewOrm()
totalCount, err := o.QueryTable(&models.Note{}).Filter("Pid", pid).Count()
if err != nil {
return 0, err
}
return totalCount, nil
}
6 lat temu
func (this *NoteService) SaveNoteColl(note *models.NoteColl) error {
6 lat temu
o := orm.NewOrm()
id, err := o.Insert(note)
if err == nil {
note.Id = id
}
return err
}
6 lat temu
func (this *NoteService) EditNoteColl(title string, id int64, uid int64) error {
o := orm.NewOrm()
noteColl := &models.NoteColl{Id: id}
if err := o.Read(noteColl); err != nil {
return err
}
if noteColl.UserId != uid {
return errors.New("403")
}
noteColl.Title = title
_, err := o.Update(noteColl, "Title")
return err
}
6 lat temu
func (this *NoteService) GetNoteColl(uid int64) ([]*models.NoteColl, error) {
6 lat temu
var notes []*models.NoteColl
o := orm.NewOrm()
qs := o.QueryTable(models.NoteColl{})
6 lat temu
_, err := qs.Filter("UserId", uid).All(&notes)
return notes, err
}
6 lat temu
func (this *NoteService) DelNoteColl(id int64, uid int64) error {
o := orm.NewOrm()
noteColl := &models.NoteColl{Id: id}
if err := o.Read(noteColl); err != nil {
return err
}
if uid != noteColl.UserId {
return errors.New("403")
}
_, err := o.QueryTable(models.Note{}).Filter("Pid", id).Delete()
if err == nil {
_, err = o.Delete(noteColl)
}
return err
}