libfic: Add new row in exercices table, to store relative path to exercice
This commit is contained in:
parent
bfd7126e1e
commit
38a0f4c9b5
3 changed files with 15 additions and 12 deletions
|
@ -101,7 +101,7 @@ func createExercice(theme fic.Theme, body []byte) (interface{}, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return theme.AddExercice(ue.Title, ue.Statement, depend, ue.Gain, ue.VideoURI)
|
return theme.AddExercice(ue.Title, ue.Path, ue.Statement, depend, ue.Gain, ue.VideoURI)
|
||||||
}
|
}
|
||||||
|
|
||||||
type uploadedKey struct {
|
type uploadedKey struct {
|
||||||
|
@ -124,6 +124,7 @@ func createExerciceKey(exercice fic.Exercice, body []byte) (interface{}, error)
|
||||||
|
|
||||||
type uploadedHint struct {
|
type uploadedHint struct {
|
||||||
Title string
|
Title string
|
||||||
|
Path string
|
||||||
Content string
|
Content string
|
||||||
Cost int64
|
Cost int64
|
||||||
URI string
|
URI string
|
||||||
|
|
|
@ -92,6 +92,7 @@ CREATE TABLE IF NOT EXISTS exercices(
|
||||||
id_exercice INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
id_exercice INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||||||
id_theme INTEGER NOT NULL,
|
id_theme INTEGER NOT NULL,
|
||||||
title VARCHAR(255) NOT NULL,
|
title VARCHAR(255) NOT NULL,
|
||||||
|
path VARCHAR(255) NOT NULL,
|
||||||
statement TEXT NOT NULL,
|
statement TEXT NOT NULL,
|
||||||
depend INTEGER,
|
depend INTEGER,
|
||||||
gain INTEGER NOT NULL,
|
gain INTEGER NOT NULL,
|
||||||
|
|
|
@ -10,6 +10,7 @@ var PartialValidation bool
|
||||||
type Exercice struct {
|
type Exercice struct {
|
||||||
Id int64 `json:"id"`
|
Id int64 `json:"id"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
|
Path string `json:"path"`
|
||||||
Statement string `json:"statement"`
|
Statement string `json:"statement"`
|
||||||
Depend *int64 `json:"depend"`
|
Depend *int64 `json:"depend"`
|
||||||
Gain int64 `json:"gain"`
|
Gain int64 `json:"gain"`
|
||||||
|
@ -19,7 +20,7 @@ type Exercice struct {
|
||||||
|
|
||||||
func GetExercice(id int64) (Exercice, error) {
|
func GetExercice(id int64) (Exercice, error) {
|
||||||
var e Exercice
|
var e Exercice
|
||||||
if err := DBQueryRow("SELECT id_exercice, title, statement, depend, gain, coefficient_cur, video_uri FROM exercices WHERE id_exercice = ?", id).Scan(&e.Id, &e.Title, &e.Statement, &e.Depend, &e.Gain, &e.Coefficient, &e.VideoURI); err != nil {
|
if err := DBQueryRow("SELECT id_exercice, title, path, statement, depend, gain, coefficient_cur, video_uri FROM exercices WHERE id_exercice = ?", id).Scan(&e.Id, &e.Title, &e.Path, &e.Statement, &e.Depend, &e.Gain, &e.Coefficient, &e.VideoURI); err != nil {
|
||||||
return Exercice{}, err
|
return Exercice{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,7 +29,7 @@ func GetExercice(id int64) (Exercice, error) {
|
||||||
|
|
||||||
func (t Theme) GetExercice(id int) (Exercice, error) {
|
func (t Theme) GetExercice(id int) (Exercice, error) {
|
||||||
var e Exercice
|
var e Exercice
|
||||||
if err := DBQueryRow("SELECT id_exercice, title, statement, depend, gain, coefficient_cur, video_uri FROM exercices WHERE id_theme = ? AND id_exercice = ?", t.Id, id).Scan(&e.Id, &e.Title, &e.Statement, &e.Depend, &e.Gain, &e.Coefficient, &e.VideoURI); err != nil {
|
if err := DBQueryRow("SELECT id_exercice, title, path, statement, depend, gain, coefficient_cur, video_uri FROM exercices WHERE id_theme = ? AND id_exercice = ?", t.Id, id).Scan(&e.Id, &e.Title, &e.Path, &e.Statement, &e.Depend, &e.Gain, &e.Coefficient, &e.VideoURI); err != nil {
|
||||||
return Exercice{}, err
|
return Exercice{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,7 +37,7 @@ func (t Theme) GetExercice(id int) (Exercice, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetExercices() ([]Exercice, error) {
|
func GetExercices() ([]Exercice, error) {
|
||||||
if rows, err := DBQuery("SELECT id_exercice, title, statement, depend, gain, coefficient_cur, video_uri FROM exercices"); err != nil {
|
if rows, err := DBQuery("SELECT id_exercice, title, path, statement, depend, gain, coefficient_cur, video_uri FROM exercices"); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
} else {
|
} else {
|
||||||
defer rows.Close()
|
defer rows.Close()
|
||||||
|
@ -44,7 +45,7 @@ func GetExercices() ([]Exercice, error) {
|
||||||
var exos = make([]Exercice, 0)
|
var exos = make([]Exercice, 0)
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var e Exercice
|
var e Exercice
|
||||||
if err := rows.Scan(&e.Id, &e.Title, &e.Statement, &e.Depend, &e.Gain, &e.Coefficient, &e.VideoURI); err != nil {
|
if err := rows.Scan(&e.Id, &e.Title, &e.Path, &e.Statement, &e.Depend, &e.Gain, &e.Coefficient, &e.VideoURI); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
exos = append(exos, e)
|
exos = append(exos, e)
|
||||||
|
@ -58,7 +59,7 @@ func GetExercices() ([]Exercice, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t Theme) GetExercices() ([]Exercice, error) {
|
func (t Theme) GetExercices() ([]Exercice, error) {
|
||||||
if rows, err := DBQuery("SELECT id_exercice, title, statement, depend, gain, coefficient_cur, video_uri FROM exercices WHERE id_theme = ?", t.Id); err != nil {
|
if rows, err := DBQuery("SELECT id_exercice, title, path, statement, depend, gain, coefficient_cur, video_uri FROM exercices WHERE id_theme = ?", t.Id); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
} else {
|
} else {
|
||||||
defer rows.Close()
|
defer rows.Close()
|
||||||
|
@ -66,7 +67,7 @@ func (t Theme) GetExercices() ([]Exercice, error) {
|
||||||
var exos = make([]Exercice, 0)
|
var exos = make([]Exercice, 0)
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var e Exercice
|
var e Exercice
|
||||||
if err := rows.Scan(&e.Id, &e.Title, &e.Statement, &e.Depend, &e.Gain, &e.Coefficient, &e.VideoURI); err != nil {
|
if err := rows.Scan(&e.Id, &e.Title, &e.Path, &e.Statement, &e.Depend, &e.Gain, &e.Coefficient, &e.VideoURI); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
exos = append(exos, e)
|
exos = append(exos, e)
|
||||||
|
@ -79,28 +80,28 @@ func (t Theme) GetExercices() ([]Exercice, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t Theme) AddExercice(title string, statement string, depend *Exercice, gain int64, videoURI string) (Exercice, error) {
|
func (t Theme) AddExercice(title string, path string, statement string, depend *Exercice, gain int64, videoURI string) (Exercice, error) {
|
||||||
var dpd interface{}
|
var dpd interface{}
|
||||||
if depend == nil {
|
if depend == nil {
|
||||||
dpd = nil
|
dpd = nil
|
||||||
} else {
|
} else {
|
||||||
dpd = depend.Id
|
dpd = depend.Id
|
||||||
}
|
}
|
||||||
if res, err := DBExec("INSERT INTO exercices (id_theme, title, statement, depend, gain, video_uri) VALUES (?, ?, ?, ?, ?, ?)", t.Id, title, statement, dpd, gain, videoURI); err != nil {
|
if res, err := DBExec("INSERT INTO exercices (id_theme, title, path, statement, depend, gain, video_uri) VALUES (?, ?, ?, ?, ?, ?, ?)", t.Id, title, path, statement, dpd, gain, videoURI); err != nil {
|
||||||
return Exercice{}, err
|
return Exercice{}, err
|
||||||
} else if eid, err := res.LastInsertId(); err != nil {
|
} else if eid, err := res.LastInsertId(); err != nil {
|
||||||
return Exercice{}, err
|
return Exercice{}, err
|
||||||
} else {
|
} else {
|
||||||
if depend == nil {
|
if depend == nil {
|
||||||
return Exercice{eid, title, statement, nil, gain, 1.0, videoURI}, nil
|
return Exercice{eid, title, path, statement, nil, gain, 1.0, videoURI}, nil
|
||||||
} else {
|
} else {
|
||||||
return Exercice{eid, title, statement, &depend.Id, gain, 1.0, videoURI}, nil
|
return Exercice{eid, title, path, statement, &depend.Id, gain, 1.0, videoURI}, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e Exercice) Update() (int64, error) {
|
func (e Exercice) Update() (int64, error) {
|
||||||
if res, err := DBExec("UPDATE exercices SET title = ?, statement = ?, depend = ?, gain = ?, coefficient_cur = ?, video_uri = ? WHERE id_exercice = ?", e.Title, e.Statement, e.Depend, e.Gain, e.Coefficient, e.VideoURI, e.Id); err != nil {
|
if res, err := DBExec("UPDATE exercices SET title = ?, path = ?, statement = ?, depend = ?, gain = ?, coefficient_cur = ?, video_uri = ? WHERE id_exercice = ?", e.Title, e.Path, e.Statement, e.Depend, e.Gain, e.Coefficient, e.VideoURI, e.Id); err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
} else if nb, err := res.RowsAffected(); err != nil {
|
} else if nb, err := res.RowsAffected(); err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
|
|
Reference in a new issue