add facebook page model method
This commit is contained in:
+32
-4
@@ -2,12 +2,18 @@ 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"`
|
||||
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 -
|
||||
@@ -18,3 +24,25 @@ func GetAllFacebookPage() (pages []*FacebookPage, err error) {
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user