From 4690f6e13d9190bad35a1d94ee6f882ab86d9ab1 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Thu, 11 Feb 2016 18:02:33 +0100 Subject: jingle cut list diff --git a/rddb/rddb.go b/rddb/rddb.go index e17f3fb..a645fa2 100644 --- a/rddb/rddb.go +++ b/rddb/rddb.go @@ -167,29 +167,41 @@ type getJingleListRequest struct { response chan<- getJingleListResult } +type getJingleCutListResult struct { + active CartListEntry + inactive CartListEntry + err error +} + +type getJingleCutListRequest struct { + jingle JingleListEntry + response chan<- getJingleCutListResult +} + type DB struct { - conf *config - dbh *sql.DB - passwordCache map[string]string - getPasswordChan chan getPasswordRequest - getPasswordStmt *sql.Stmt - getGroupOfCartChan chan getGroupOfCartRequest - getGroupOfCartStmt *sql.Stmt - getShowInfoChan chan getShowInfoRequest - getShowInfoStmt *sql.Stmt - checkMusicGroupChan chan checkMusicGroupRequest - checkMusicGroupStmt *sql.Stmt - getMusicInfoChan chan getMusicInfoRequest - getMusicInfoStmt *sql.Stmt - getShowListChan chan getShowListRequest - getShowListStmt *sql.Stmt - getShowCartListChan chan getShowCartListRequest - getCartInfoStmt *sql.Stmt - getCutInfoStmt *sql.Stmt - getJingleListChan chan getJingleListRequest - getJingleListStmt *sql.Stmt - quit chan bool - done chan bool + conf *config + dbh *sql.DB + passwordCache map[string]string + getPasswordChan chan getPasswordRequest + getPasswordStmt *sql.Stmt + getGroupOfCartChan chan getGroupOfCartRequest + getGroupOfCartStmt *sql.Stmt + getShowInfoChan chan getShowInfoRequest + getShowInfoStmt *sql.Stmt + checkMusicGroupChan chan checkMusicGroupRequest + checkMusicGroupStmt *sql.Stmt + getMusicInfoChan chan getMusicInfoRequest + getMusicInfoStmt *sql.Stmt + getShowListChan chan getShowListRequest + getShowListStmt *sql.Stmt + getShowCartListChan chan getShowCartListRequest + getCartInfoStmt *sql.Stmt + getCutInfoStmt *sql.Stmt + getJingleListChan chan getJingleListRequest + getJingleListStmt *sql.Stmt + getJingleCutListChan chan getJingleCutListRequest + quit chan bool + done chan bool } func (db *DB) init() (err error) { @@ -483,6 +495,16 @@ func (db *DB) getJingleList(username string) (result getJingleListResult) { return } +func (db *DB) getJingleCutList(jingle JingleListEntry) (result getJingleCutListResult) { + if result.active, result.err = db.getCartInfo(uint(jingle.ActiveCart)); result.err != nil { + return + } + if result.inactive, result.err = db.getCartInfo(uint(jingle.InactiveCart)); result.err != nil { + return + } + return +} + func (db *DB) dispatchRequests() { defer func() { db.done <- true }() for { @@ -505,6 +527,8 @@ func (db *DB) dispatchRequests() { req.response <- db.getShowCartList(req.show) case req := <-db.getJingleListChan: req.response <- db.getJingleList(req.username) + case req := <-db.getJingleCutListChan: + req.response <- db.getJingleCutList(req.jingle) } } } @@ -513,14 +537,15 @@ func (db *DB) dispatchRequests() { // Public Interface type DBChan struct { - getPasswordChan chan<- getPasswordRequest - getGroupOfCartChan chan<- getGroupOfCartRequest - getShowInfoChan chan<- getShowInfoRequest - checkMusicGroupChan chan<- checkMusicGroupRequest - getMusicInfoChan chan<- getMusicInfoRequest - getShowListChan chan<- getShowListRequest - getShowCartListChan chan<- getShowCartListRequest - getJingleListChan chan<- getJingleListRequest + getPasswordChan chan<- getPasswordRequest + getGroupOfCartChan chan<- getGroupOfCartRequest + getShowInfoChan chan<- getShowInfoRequest + checkMusicGroupChan chan<- checkMusicGroupRequest + getMusicInfoChan chan<- getMusicInfoRequest + getShowListChan chan<- getShowListRequest + getShowCartListChan chan<- getShowCartListRequest + getJingleListChan chan<- getJingleListRequest + getJingleCutListChan chan<- getJingleCutListRequest } func (db *DBChan) GetPassword(username string, cached bool) (string, error) { @@ -663,6 +688,17 @@ func (db *DBChan) GetJingleList(username string) (JingleList, error) { return res.jingles, nil } +func (db *DBChan) GetJingleCutList(jingle JingleListEntry) (CartListEntry, CartListEntry, error) { + resCh := make(chan getJingleCutListResult) + req := getJingleCutListRequest{} + req.jingle = jingle + req.response = resCh + db.getJingleCutListChan <- req + + res := <-resCh + return res.active, res.inactive, res.err +} + func (db *DB) GetInterface() *DBChan { ch := &DBChan{} ch.getPasswordChan = db.getPasswordChan @@ -673,6 +709,7 @@ func (db *DB) GetInterface() *DBChan { ch.getShowListChan = db.getShowListChan ch.getShowCartListChan = db.getShowCartListChan ch.getJingleListChan = db.getJingleListChan + ch.getJingleCutListChan = db.getJingleCutListChan return ch } @@ -730,6 +767,7 @@ func NewDB(configfile string) (db *DB, err error) { db.getShowListChan = make(chan getShowListRequest, 10) db.getShowCartListChan = make(chan getShowCartListRequest, 10) db.getJingleListChan = make(chan getJingleListRequest, 10) + db.getJingleCutListChan = make(chan getJingleCutListRequest, 10) if err = db.init(); err != nil { return -- cgit v0.10.2