mtfosbot/model/facebook_page.go

49 lines
1.1 KiB
Go

package model
import "time"
type FBGroups struct {
*LineGroup
Tmpl string `db:"tmpl"`
}
// FacebookPage - struct
type FacebookPage struct {
ID string `db:"id" cc:"id"`
LastPost string `db:"lastpost" cc:"lastpost"`
Ctime time.Time `db:"ctime" cc:"ctime"`
Mtime time.Time `db:"mtime" cc:"ctime"`
Groups []*FBGroups `db:"-"`
}
// GetAllFacebookPage -
func GetAllFacebookPage() (pages []*FacebookPage, err error) {
err = x.Select(&pages, `select * from "public"."facebook_page"`)
if err != nil {
return nil, err
}
return
}
func (p *FacebookPage) UpdatePost(postID string) (err error) {
query := `update "public"."facebook_page" set "lastpost" = $1 where id = $2`
_, err = x.Exec(query, postID, p.ID)
if err != nil {
return
}
p.LastPost = postID
return
}
func (p *FacebookPage) GetGroups() (err error) {
query := `select g.*, rt.tmpl as tmpl from "public"."facebook_page" p
left join "public"."line_fb_rt" rt
on rt."facebook" = p.id
left join "public"."line_group" g
on g.id = rt."line"
where
p.id = $1`
err = x.Select(&p.Groups, query, p.ID)
return
}