Merge branch 'master' of https://git.trj.tw/golang/mtfosbot
This commit is contained in:
commit
c21d43a691
@ -46,7 +46,7 @@ func (p *DonateSetting) InsertOrUpdate() (err error) {
|
|||||||
"end_date" = :end_date,
|
"end_date" = :end_date,
|
||||||
"target_amount" = :target_amount,
|
"target_amount" = :target_amount,
|
||||||
"title" = :title,
|
"title" = :title,
|
||||||
"start_amount" = :start_amount`
|
"start_amount" = :start_amount, "mtime" = now()`
|
||||||
_, err = x.NamedExec(query, p)
|
_, err = x.NamedExec(query, p)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ func (p *FacebookPage) AddPage() (err error) {
|
|||||||
|
|
||||||
// UpdatePost -
|
// UpdatePost -
|
||||||
func (p *FacebookPage) UpdatePost(postID string) (err error) {
|
func (p *FacebookPage) UpdatePost(postID string) (err error) {
|
||||||
query := `update "public"."facebook_page" set "lastpost" = $1 where id = $2`
|
query := `update "public"."facebook_page" set "lastpost" = $1, "mtime" = now() where id = $2`
|
||||||
_, err = x.Exec(query, postID, p.ID)
|
_, err = x.Exec(query, postID, p.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
@ -32,8 +32,27 @@ func AddLineMessageLog(g, u, msg, t string) (msglog *LineMessageLog, err error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetLineMessageLogCount -
|
// GetLineMessageLogCount -
|
||||||
func GetLineMessageLogCount() (c int, err error) {
|
func GetLineMessageLogCount(where ...interface{}) (c int, err error) {
|
||||||
err = x.Get(&c, `select count(*) as c from "public"."line_message_log"`)
|
query := `select count(*) as c from "public"."line_message_log"`
|
||||||
|
values := make([]interface{}, 0)
|
||||||
|
if len(where) > 0 {
|
||||||
|
if whereMap, ok := where[0].(map[string]string); ok {
|
||||||
|
str := ""
|
||||||
|
idx := 1
|
||||||
|
for k, v := range whereMap {
|
||||||
|
if len(str) > 0 {
|
||||||
|
str += " and "
|
||||||
|
}
|
||||||
|
str += fmt.Sprintf(` "%s" = $%d`, k, idx)
|
||||||
|
idx++
|
||||||
|
values = append(values, v)
|
||||||
|
}
|
||||||
|
if len(str) > 0 {
|
||||||
|
query += " where " + str
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
err = x.Get(&c, query, values...)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,7 +85,7 @@ func (p *TwitchChannel) Add() (err error) {
|
|||||||
|
|
||||||
// UpdateStream -
|
// UpdateStream -
|
||||||
func (p *TwitchChannel) UpdateStream(streamID string) (err error) {
|
func (p *TwitchChannel) UpdateStream(streamID string) (err error) {
|
||||||
query := `update "public"."twitch_channel" set "laststream" = $1 where "id" = $2`
|
query := `update "public"."twitch_channel" set "laststream" = $1, "mtime" = now() where "id" = $2`
|
||||||
_, err = x.Exec(query, streamID, p.ID)
|
_, err = x.Exec(query, streamID, p.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
@ -96,7 +96,7 @@ func (p *TwitchChannel) UpdateStream(streamID string) (err error) {
|
|||||||
|
|
||||||
// UpdateName -
|
// UpdateName -
|
||||||
func (p *TwitchChannel) UpdateName(name string) (err error) {
|
func (p *TwitchChannel) UpdateName(name string) (err error) {
|
||||||
_, err = x.Exec(`update "public"."twitch_channel" set "name" = $1 where "id" = $2`, name, p.ID)
|
_, err = x.Exec(`update "public"."twitch_channel" set "name" = $1, "mtime" = now() where "id" = $2`, name, p.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -107,14 +107,14 @@ func (p *TwitchChannel) UpdateName(name string) (err error) {
|
|||||||
// UpdateJoin -
|
// UpdateJoin -
|
||||||
func (p *TwitchChannel) UpdateJoin(join bool) (err error) {
|
func (p *TwitchChannel) UpdateJoin(join bool) (err error) {
|
||||||
p.Join = join
|
p.Join = join
|
||||||
_, err = x.NamedExec(`update "public"."twitch_channel" set "join" = :join where "id" = :id`, p)
|
_, err = x.NamedExec(`update "public"."twitch_channel" set "join" = :join, "mtime" = now() where "id" = :id`, p)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateOpayID -
|
// UpdateOpayID -
|
||||||
func (p *TwitchChannel) UpdateOpayID(id string) (err error) {
|
func (p *TwitchChannel) UpdateOpayID(id string) (err error) {
|
||||||
p.OpayID = id
|
p.OpayID = id
|
||||||
_, err = x.NamedExec(`update "public"."twitch_channel" set "opayid" = :opayid where "id" = :id`, p)
|
_, err = x.NamedExec(`update "public"."twitch_channel" set "opayid" = :opayid, "mtime" = now() where "id" = :id`, p)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,14 +57,14 @@ func (p *YoutubeChannel) Add() (err error) {
|
|||||||
// UpdateLastVideo -
|
// UpdateLastVideo -
|
||||||
func (p *YoutubeChannel) UpdateLastVideo(vid string) (err error) {
|
func (p *YoutubeChannel) UpdateLastVideo(vid string) (err error) {
|
||||||
p.LastVideo = vid
|
p.LastVideo = vid
|
||||||
_, err = x.NamedExec(`update "public"."youtube_channel" set "lastvideo" = :lastvideo where "id" = :id`, p)
|
_, err = x.NamedExec(`update "public"."youtube_channel" set "lastvideo" = :lastvideo, "mtime" = now() where "id" = :id`, p)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateExpire -
|
// UpdateExpire -
|
||||||
func (p *YoutubeChannel) UpdateExpire(t int64) (err error) {
|
func (p *YoutubeChannel) UpdateExpire(t int64) (err error) {
|
||||||
p.Expire = t
|
p.Expire = t
|
||||||
_, err = x.NamedExec(`update "public"."youtube_channel" set "expire" = :expire where "id" = :id`, p)
|
_, err = x.NamedExec(`update "public"."youtube_channel" set "expire" = :expire, "mtime" = now() where "id" = :id`, p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"git.trj.tw/golang/mtfosbot/model"
|
"git.trj.tw/golang/mtfosbot/model"
|
||||||
@ -49,8 +50,17 @@ func GetLineMessageLog(c *context.Context) {
|
|||||||
g := c.DefaultQuery("group", "")
|
g := c.DefaultQuery("group", "")
|
||||||
u := c.DefaultQuery("user", "")
|
u := c.DefaultQuery("user", "")
|
||||||
|
|
||||||
count, err := model.GetLineMessageLogCount()
|
where := make(map[string]string)
|
||||||
|
if len(g) > 0 {
|
||||||
|
where["group"] = g
|
||||||
|
}
|
||||||
|
if len(u) > 0 {
|
||||||
|
where["user"] = u
|
||||||
|
}
|
||||||
|
|
||||||
|
count, err := model.GetLineMessageLogCount(where)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
fmt.Println("count error :::: ", err)
|
||||||
c.ServerError(nil)
|
c.ServerError(nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user