2022-08-08 23:58:38 +02:00
|
|
|
package data
|
|
|
|
|
2022-08-09 00:07:32 +02:00
|
|
|
import (
|
|
|
|
"database/sql"
|
|
|
|
"errors"
|
|
|
|
)
|
2022-08-08 23:58:38 +02:00
|
|
|
|
|
|
|
var (
|
2023-03-04 21:25:45 +01:00
|
|
|
ErrRecordNotFound = errors.New("record not found")
|
|
|
|
ErrChannelRecordAlreadyExists = errors.New("channel already in database")
|
|
|
|
ErrEditConflict = errors.New("edit conflict")
|
|
|
|
ErrCommandRecordAlreadyExists = errors.New("command already exists")
|
|
|
|
ErrLastFMUserRecordAlreadyExists = errors.New("lastfm connection already set")
|
|
|
|
ErrUserAlreadyExists = errors.New("user already in database")
|
2022-08-08 23:58:38 +02:00
|
|
|
)
|
2022-08-09 00:07:32 +02:00
|
|
|
|
|
|
|
// struct Models wraps the models, making them callable
|
|
|
|
// as app.models.Channels.Get(login)
|
|
|
|
type Models struct {
|
|
|
|
Channels interface {
|
|
|
|
Insert(channel *Channel) error
|
|
|
|
Get(login string) (*Channel, error)
|
2022-08-09 23:19:08 +02:00
|
|
|
GetAll() ([]*Channel, error)
|
2022-08-10 18:16:39 +02:00
|
|
|
GetJoinable() ([]string, error)
|
2022-08-09 19:50:46 +02:00
|
|
|
Delete(login string) error
|
2022-08-09 00:07:32 +02:00
|
|
|
}
|
2022-08-09 22:34:12 +02:00
|
|
|
Users interface {
|
2023-03-05 20:43:35 +01:00
|
|
|
Insert(login, twitchId string) error
|
2022-08-09 22:34:12 +02:00
|
|
|
Get(login string) (*User, error)
|
2023-03-05 21:07:41 +01:00
|
|
|
Check(twitchId string) (*User, error)
|
2022-08-10 00:14:54 +02:00
|
|
|
SetLevel(login string, level int) error
|
2023-03-05 21:07:41 +01:00
|
|
|
GetLevel(twitchId string) (int, error)
|
2023-03-04 23:37:31 +01:00
|
|
|
SetLocation(login, location string) error
|
2023-03-05 21:57:08 +01:00
|
|
|
GetLocation(twitchId string) (string, error)
|
2023-03-05 18:42:34 +01:00
|
|
|
SetLastFM(login, lastfmUser string) error
|
|
|
|
GetLastFM(login string) (string, error)
|
2022-08-09 21:25:44 +02:00
|
|
|
Delete(login string) error
|
|
|
|
}
|
2022-08-11 01:18:04 +02:00
|
|
|
Commands interface {
|
|
|
|
Get(name string) (*Command, error)
|
2022-08-17 14:45:35 +02:00
|
|
|
Insert(command *Command) error
|
2022-08-17 20:57:25 +02:00
|
|
|
Update(command *Command) error
|
2022-08-11 20:35:22 +02:00
|
|
|
SetLevel(name string, level int) error
|
2022-08-15 00:53:41 +02:00
|
|
|
SetCategory(name, category string) error
|
2023-03-04 02:29:29 +01:00
|
|
|
SetHelp(name, helptext string) error
|
2022-08-11 01:18:04 +02:00
|
|
|
Delete(name string) error
|
|
|
|
}
|
2022-08-21 21:04:27 +02:00
|
|
|
Timers interface {
|
|
|
|
Get(name string) (*Timer, error)
|
2022-08-22 02:12:54 +02:00
|
|
|
Insert(timer *Timer) error
|
2022-08-27 17:38:03 +02:00
|
|
|
Update(timer *Timer) error
|
2022-08-22 03:06:23 +02:00
|
|
|
GetAll() ([]*Timer, error)
|
2022-08-24 21:00:09 +02:00
|
|
|
Delete(name string) error
|
2022-08-21 21:04:27 +02:00
|
|
|
}
|
2022-08-09 00:07:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewModels(db *sql.DB) Models {
|
|
|
|
return Models{
|
2023-03-05 19:28:14 +01:00
|
|
|
Channels: ChannelModel{DB: db},
|
|
|
|
Users: UserModel{DB: db},
|
|
|
|
Commands: CommandModel{DB: db},
|
|
|
|
Timers: TimerModel{DB: db},
|
2022-08-09 00:07:32 +02:00
|
|
|
}
|
|
|
|
}
|