add twitch apis , bar api not ok
This commit is contained in:
+36
-1
@@ -1,6 +1,7 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -10,8 +11,42 @@ type DonateSetting struct {
|
||||
StartDate time.Time `db:"start_date" cc:"start_date"`
|
||||
EndDate time.Time `db:"end_date" cc:"end_date"`
|
||||
TargetAmount int `db:"target_amount" cc:"target_amount"`
|
||||
StartAmount int `db:"start_amount" cc:"start_amount"`
|
||||
Title string `db:"title" cc:"title"`
|
||||
Type string `db:"type" cc:"type"`
|
||||
Ctime time.Time `db:"ctime" cc:"ctime"`
|
||||
Mtime time.Time `db:"mtime" cc:"ctime"`
|
||||
Mtime time.Time `db:"mtime" cc:"mtime"`
|
||||
}
|
||||
|
||||
// GetDonateSettingByChannel -
|
||||
func GetDonateSettingByChannel(id string) (ds *DonateSetting, err error) {
|
||||
query := `select ds.*
|
||||
from "public"."donate_setting" ds
|
||||
left join "public"."twitch_channel" ch
|
||||
on ch.id = ds.twitch
|
||||
where
|
||||
ch.id = $1`
|
||||
row := x.QueryRowx(query, id)
|
||||
ds = &DonateSetting{}
|
||||
err = row.StructScan(ds)
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, nil
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// InsertOrUpdate -
|
||||
func (p *DonateSetting) InsertOrUpdate() (err error) {
|
||||
query := `insert into "public"."donate_setting"
|
||||
("twitch", "start_date", "end_date", "target_amount", "title", "start_amount") values
|
||||
(:twitch, now(), :end_date, :target_amount, :title, :start_amount)
|
||||
on CONFLICT ("twitch") DO UPDATE
|
||||
set
|
||||
"start_date" = now(),
|
||||
"end_date" = :end_date,
|
||||
"target_amount" = :target_amount,
|
||||
"title" = :title,
|
||||
"start_amount" = :start_amount`
|
||||
_, err = x.NamedExec(query, p)
|
||||
return
|
||||
}
|
||||
|
||||
+16
-2
@@ -20,12 +20,12 @@ type TwitchChannel struct {
|
||||
OpayID string `db:"opayid" cc:"opayid"`
|
||||
Ctime time.Time `db:"ctime" cc:"ctime"`
|
||||
Mtime time.Time `db:"mtime" cc:"ctime"`
|
||||
Groups []*TwitchGroup `db:"-"`
|
||||
Groups []*TwitchGroup `db:"-" cc:"-"`
|
||||
}
|
||||
|
||||
// GetAllTwitchChannel -
|
||||
func GetAllTwitchChannel() (channels []*TwitchChannel, err error) {
|
||||
err = x.Select(&channels, `select * from "public"."twitch_channel"`)
|
||||
err = x.Select(&channels, `select * from "public"."twitch_channel" order by "name" desc`)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -95,6 +95,20 @@ func (p *TwitchChannel) UpdateName(name string) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
// UpdateJoin -
|
||||
func (p *TwitchChannel) UpdateJoin(join bool) (err error) {
|
||||
p.Join = join
|
||||
_, err = x.NamedExec(`update "public"."twitch_channel" set "join" = :join where "id" = :id`, p)
|
||||
return
|
||||
}
|
||||
|
||||
// UpdateOpayID -
|
||||
func (p *TwitchChannel) UpdateOpayID(id string) (err error) {
|
||||
p.OpayID = id
|
||||
_, err = x.NamedExec(`update "public"."twitch_channel" set "opayid" = :opayid where "id" = :id`, p)
|
||||
return
|
||||
}
|
||||
|
||||
// GetGroups -
|
||||
func (p *TwitchChannel) GetGroups() (err error) {
|
||||
query := `select g.*, rt.tmpl as tmpl from "public"."twitch_channel" tw
|
||||
|
||||
Reference in New Issue
Block a user