Paket data zu db umbenannt, den type Question zur SQL-Abfrage hinzugefügt, um Duplikate zu vermeiden und db.OpenDB() zu db.Open() umbenannt
This commit is contained in:
parent
6359caf3e9
commit
35d565ec7d
@ -1,42 +0,0 @@
|
|||||||
package data
|
|
||||||
|
|
||||||
import "streifling.com/jason/sicherheitsunterweisung/packages/types"
|
|
||||||
|
|
||||||
func InitQuestions() []types.Question {
|
|
||||||
Q := make([]types.Question, 0)
|
|
||||||
|
|
||||||
Q = append(Q, types.Question{
|
|
||||||
Text: "Wie viel ist 1+1?",
|
|
||||||
Answers: []types.Answer{
|
|
||||||
{ID: 0, Text: "1"},
|
|
||||||
{ID: 1, Text: "2"},
|
|
||||||
{ID: 2, Text: "3"},
|
|
||||||
{ID: 3, Text: "4"},
|
|
||||||
},
|
|
||||||
Correct: 1,
|
|
||||||
})
|
|
||||||
|
|
||||||
Q = append(Q, types.Question{
|
|
||||||
Text: "Wie viel ist 2+2?",
|
|
||||||
Answers: []types.Answer{
|
|
||||||
{ID: 0, Text: "1"},
|
|
||||||
{ID: 1, Text: "2"},
|
|
||||||
{ID: 2, Text: "3"},
|
|
||||||
{ID: 3, Text: "4"},
|
|
||||||
},
|
|
||||||
Correct: 3,
|
|
||||||
})
|
|
||||||
|
|
||||||
Q = append(Q, types.Question{
|
|
||||||
Text: "Wie viel ist 1+2?",
|
|
||||||
Answers: []types.Answer{
|
|
||||||
{ID: 0, Text: "1"},
|
|
||||||
{ID: 1, Text: "2"},
|
|
||||||
{ID: 2, Text: "3"},
|
|
||||||
{ID: 3, Text: "4"},
|
|
||||||
},
|
|
||||||
Correct: 2,
|
|
||||||
})
|
|
||||||
|
|
||||||
return Q
|
|
||||||
}
|
|
@ -1,4 +1,4 @@
|
|||||||
package data
|
package db
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
@ -8,10 +8,9 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"streifling.com/jason/sicherheitsunterweisung/packages/types"
|
|
||||||
|
|
||||||
"github.com/go-sql-driver/mysql"
|
"github.com/go-sql-driver/mysql"
|
||||||
"golang.org/x/term"
|
"golang.org/x/term"
|
||||||
|
"streifling.com/jason/sicherheitsunterweisung/packages/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DB struct {
|
type DB struct {
|
||||||
@ -60,7 +59,7 @@ func getCredentials() (string, string, error) {
|
|||||||
return user, pass, nil
|
return user, pass, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func OpenDB(dbName string) (*DB, error) {
|
func Open(dbName string) (*DB, error) {
|
||||||
var err error
|
var err error
|
||||||
db := new(DB)
|
db := new(DB)
|
||||||
|
|
||||||
@ -155,7 +154,7 @@ func (db *DB) WriteAllDataOfBriefing(b *types.Briefing, sp *[]*types.Participant
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *DB) GetAllOverviewTableData() (*[]*types.OverviewTableData, error) {
|
func (db *DB) GetAllOverviewTableData() ([]*types.OverviewTableData, error) {
|
||||||
rows, err := db.Query(`
|
rows, err := db.Query(`
|
||||||
SELECT
|
SELECT
|
||||||
i.first_name,
|
i.first_name,
|
||||||
@ -173,8 +172,12 @@ func (db *DB) GetAllOverviewTableData() (*[]*types.OverviewTableData, error) {
|
|||||||
ON b.id = g.briefing_id
|
ON b.id = g.briefing_id
|
||||||
INNER JOIN participants AS p
|
INNER JOIN participants AS p
|
||||||
ON p.id = g.participant_id
|
ON p.id = g.participant_id
|
||||||
|
INNER JOIN questions AS q
|
||||||
|
ON q.id = g.question_id
|
||||||
INNER JOIN instructors AS i
|
INNER JOIN instructors AS i
|
||||||
ON i.id = b.instructor_id
|
ON i.id = b.instructor_id
|
||||||
|
WHERE
|
||||||
|
q.id = 1
|
||||||
ORDER BY
|
ORDER BY
|
||||||
b.id DESC,
|
b.id DESC,
|
||||||
p.id
|
p.id
|
||||||
@ -207,7 +210,7 @@ func (db *DB) GetAllOverviewTableData() (*[]*types.OverviewTableData, error) {
|
|||||||
data = append(data, otd)
|
data = append(data, otd)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &data, nil
|
return data, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *DB) GetOverviewTableDataByName(n string) (*[]*types.OverviewTableData, error) {
|
func (db *DB) GetOverviewTableDataByName(n string) (*[]*types.OverviewTableData, error) {
|
||||||
@ -231,6 +234,7 @@ func (db *DB) GetOverviewTableDataByName(n string) (*[]*types.OverviewTableData,
|
|||||||
INNER JOIN instructors AS i
|
INNER JOIN instructors AS i
|
||||||
ON i.id = b.instructor_id
|
ON i.id = b.instructor_id
|
||||||
WHERE
|
WHERE
|
||||||
|
q.id = 1 AND
|
||||||
i.first_name LIKE ? OR
|
i.first_name LIKE ? OR
|
||||||
i.last_name LIKE ? OR
|
i.last_name LIKE ? OR
|
||||||
p.first_name LIKE ? OR
|
p.first_name LIKE ? OR
|
Loading…
x
Reference in New Issue
Block a user