add pre group one bot setting

This commit is contained in:
Jay
2019-06-25 17:02:03 +08:00
parent c605b2d9e9
commit 8c432b9b68
13 changed files with 185 additions and 56 deletions
+37
View File
@@ -0,0 +1,37 @@
package model
import (
"database/sql"
"errors"
"time"
)
// LineBot -
type LineBot struct {
ID string `db:"id" cc:"id"`
Name string `db:"name" cc:"name"`
AccessToken string `db:"access_token" cc:"access_token"`
Secret string `db:"secret" cc:"secret"`
Ctime time.Time `db:"ctime" cc:"ctime"`
Mtime time.Time `db:"mtime" cc:"mtime"`
}
// GetBotInfo -
func GetBotInfo(id string) (bot *LineBot, err error) {
if len(id) == 0 {
return nil, errors.New("id is emptu")
}
query := `select
"id", "name", "access_token", "secret", "ctime", "mtime"
from public."line_bot"
where
"id" = $1`
bot = &LineBot{}
err = x.Get(bot, query, id)
if err == sql.ErrNoRows {
return nil, nil
}
return
}
+23 -6
View File
@@ -2,17 +2,19 @@ package model
import (
"database/sql"
"errors"
"time"
)
// LineGroup - struct
type LineGroup struct {
ID string `db:"id" cc:"id"`
Name string `db:"name" cc:"name"`
Notify bool `db:"notify" cc:"notify"`
Owner string `db:"owner" cc:"owner"`
Ctime time.Time `db:"ctime" cc:"ctime"`
Mtime time.Time `db:"mtime" cc:"ctime"`
ID string `db:"id" cc:"id"`
Name string `db:"name" cc:"name"`
Notify bool `db:"notify" cc:"notify"`
Owner string `db:"owner" cc:"owner"`
Ctime time.Time `db:"ctime" cc:"ctime"`
Mtime time.Time `db:"mtime" cc:"ctime"`
BotID sql.NullString `db:"bot_id" cc:"bot_id"`
}
// CheckGroup -
@@ -75,3 +77,18 @@ func (p *LineGroup) DeleteGroup() (err error) {
_, err = x.Exec(`delete from "public"."line_group" where "id" = $1`, p.ID)
return
}
// GetBot - get group binding bot
func (p *LineGroup) GetBot() (bot *LineBot, err error) {
id, err := p.BotID.Value()
if err != nil {
return nil, err
}
var botid string
var ok bool
if botid, ok = id.(string); !ok {
return nil, errors.New("botid get fail")
}
bot, err = GetBotInfo(botid)
return
}