add models
This commit is contained in:
parent
1e2026e21a
commit
c1f0ae6b9b
@ -25,6 +25,15 @@ type DiscordChannelModel struct {
|
||||
Mtime time.Time `db:"mtime"`
|
||||
}
|
||||
|
||||
// DiscordManageRoleModel -
|
||||
type DiscordManageRoleModel struct {
|
||||
Server string `db:"server"`
|
||||
RoleID string `db:"role_id"`
|
||||
RoleName string `db:"role_name"`
|
||||
Ctime time.Time `db:"ctime"`
|
||||
Mtime time.Time `db:"mtime"`
|
||||
}
|
||||
|
||||
// NewDiscordServer -
|
||||
func NewDiscordServer(id, name string, permission int) (ds *DiscordServerModel, err error) {
|
||||
if len(id) == 0 || len(name) == 0 {
|
||||
@ -96,7 +105,36 @@ func (p *DiscordServerModel) GetChannel(id string) (ch *DiscordChannelModel, err
|
||||
if len(id) == 0 {
|
||||
return nil, errors.New("id is empty")
|
||||
}
|
||||
// TODO: not finish
|
||||
db := models.GetConn()
|
||||
ch = &DiscordChannelModel{}
|
||||
query := `select "id", "server", "enable_cmd", "enable_notify", "ctime", "mtime" from discord_channel where "id" = $1 and "server" = $2`
|
||||
err = db.Get(ch, query, id, p.ID)
|
||||
return
|
||||
}
|
||||
|
||||
// GetRoleList -
|
||||
func (p *DiscordServerModel) GetRoleList() (list []*DiscordManageRoleModel, err error) {
|
||||
db := models.GetConn()
|
||||
query := `select "server", "role_id", "role_name", "ctime", "mtime" from "discord_manage_role" where "server" = $1`
|
||||
err = db.Select(&list, query, p.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// GetRole -
|
||||
func (p *DiscordServerModel) GetRole(roleID string) (role *DiscordManageRoleModel, err error) {
|
||||
if len(roleID) == 0 {
|
||||
return nil, errors.New("id is empty")
|
||||
}
|
||||
db := models.GetConn()
|
||||
role = &DiscordManageRoleModel{}
|
||||
query := `select "server", "role_id", "role_name", "ctime", "mtime" from "discord_manage_role" where "server" = $1 and "rold_id" = $2`
|
||||
err = db.Get(role, query, p.ID, roleID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user