fic: Exercice can have heading.jpg
This commit is contained in:
parent
f366d6b8c1
commit
abe5ad61d4
5 changed files with 42 additions and 11 deletions
|
@ -25,6 +25,7 @@ type Exercice struct {
|
|||
IdTheme int64 `json:"id_theme"`
|
||||
Language string `json:"lang,omitempty"`
|
||||
Title string `json:"title"`
|
||||
Image string `json:"image"`
|
||||
// Disabled indicates if the exercice is available to players now or not
|
||||
Disabled bool `json:"disabled"`
|
||||
// WIP indicates if the exercice is in development or not
|
||||
|
@ -73,7 +74,7 @@ func (e *Exercice) AnalyzeTitle() {
|
|||
func getExercice(table, condition string, args ...interface{}) (*Exercice, error) {
|
||||
var e Exercice
|
||||
var tmpgain float64
|
||||
if err := DBQueryRow("SELECT id_exercice, id_theme, title, disabled, url_id, path, statement, overview, headline, issue, issue_kind, depend, gain, coefficient_cur, video_uri, resolution, seealso, finished FROM "+table+" "+condition, args...).Scan(&e.Id, &e.IdTheme, &e.Title, &e.Disabled, &e.URLId, &e.Path, &e.Statement, &e.Overview, &e.Headline, &e.Issue, &e.IssueKind, &e.Depend, &tmpgain, &e.Coefficient, &e.VideoURI, &e.Resolution, &e.SeeAlso, &e.Finished); err != nil {
|
||||
if err := DBQueryRow("SELECT id_exercice, id_theme, title, image, disabled, url_id, path, statement, overview, headline, issue, issue_kind, depend, gain, coefficient_cur, video_uri, resolution, seealso, finished FROM "+table+" "+condition, args...).Scan(&e.Id, &e.IdTheme, &e.Title, &e.Image, &e.Disabled, &e.URLId, &e.Path, &e.Statement, &e.Overview, &e.Headline, &e.Issue, &e.IssueKind, &e.Depend, &tmpgain, &e.Coefficient, &e.VideoURI, &e.Resolution, &e.SeeAlso, &e.Finished); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
e.Gain = int64(math.Trunc(tmpgain))
|
||||
|
@ -113,7 +114,7 @@ func GetDiscountedExercice(id int64) (*Exercice, error) {
|
|||
|
||||
// getExercices returns the list of all challenges present in the database.
|
||||
func getExercices(table string) ([]*Exercice, error) {
|
||||
if rows, err := DBQuery("SELECT id_exercice, id_theme, title, disabled, url_id, path, statement, overview, headline, issue, issue_kind, depend, gain, coefficient_cur, video_uri, resolution, seealso, finished FROM " + table + " ORDER BY path ASC"); err != nil {
|
||||
if rows, err := DBQuery("SELECT id_exercice, id_theme, title, image, disabled, url_id, path, statement, overview, headline, issue, issue_kind, depend, gain, coefficient_cur, video_uri, resolution, seealso, finished FROM " + table + " ORDER BY path ASC"); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
defer rows.Close()
|
||||
|
@ -122,7 +123,7 @@ func getExercices(table string) ([]*Exercice, error) {
|
|||
for rows.Next() {
|
||||
e := &Exercice{}
|
||||
var tmpgain float64
|
||||
if err := rows.Scan(&e.Id, &e.IdTheme, &e.Title, &e.Disabled, &e.URLId, &e.Path, &e.Statement, &e.Overview, &e.Headline, &e.Issue, &e.IssueKind, &e.Depend, &tmpgain, &e.Coefficient, &e.VideoURI, &e.Resolution, &e.SeeAlso, &e.Finished); err != nil {
|
||||
if err := rows.Scan(&e.Id, &e.IdTheme, &e.Title, &e.Image, &e.Disabled, &e.URLId, &e.Path, &e.Statement, &e.Overview, &e.Headline, &e.Issue, &e.IssueKind, &e.Depend, &tmpgain, &e.Coefficient, &e.VideoURI, &e.Resolution, &e.SeeAlso, &e.Finished); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
e.Gain = int64(math.Trunc(tmpgain))
|
||||
|
@ -151,7 +152,7 @@ func GetDiscountedExercices() ([]*Exercice, error) {
|
|||
|
||||
// GetExercices returns the list of all challenges in the Theme.
|
||||
func (t *Theme) GetExercices() ([]*Exercice, error) {
|
||||
if rows, err := DBQuery("SELECT id_exercice, id_theme, title, disabled, url_id, path, statement, overview, headline, issue, issue_kind, depend, gain, coefficient_cur, video_uri, resolution, seealso, finished FROM exercices WHERE id_theme = ? ORDER BY path ASC", t.Id); err != nil {
|
||||
if rows, err := DBQuery("SELECT id_exercice, id_theme, title, image, disabled, url_id, path, statement, overview, headline, issue, issue_kind, depend, gain, coefficient_cur, video_uri, resolution, seealso, finished FROM exercices WHERE id_theme = ? ORDER BY path ASC", t.Id); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
defer rows.Close()
|
||||
|
@ -159,7 +160,7 @@ func (t *Theme) GetExercices() ([]*Exercice, error) {
|
|||
exos := []*Exercice{}
|
||||
for rows.Next() {
|
||||
e := &Exercice{}
|
||||
if err := rows.Scan(&e.Id, &e.IdTheme, &e.Title, &e.Disabled, &e.URLId, &e.Path, &e.Statement, &e.Overview, &e.Headline, &e.Issue, &e.IssueKind, &e.Depend, &e.Gain, &e.Coefficient, &e.VideoURI, &e.Resolution, &e.SeeAlso, &e.Finished); err != nil {
|
||||
if err := rows.Scan(&e.Id, &e.IdTheme, &e.Title, &e.Image, &e.Disabled, &e.URLId, &e.Path, &e.Statement, &e.Overview, &e.Headline, &e.Issue, &e.IssueKind, &e.Depend, &e.Gain, &e.Coefficient, &e.VideoURI, &e.Resolution, &e.SeeAlso, &e.Finished); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
e.AnalyzeTitle()
|
||||
|
@ -222,7 +223,7 @@ func (t *Theme) addExercice(e *Exercice) (err error) {
|
|||
if e.WIP {
|
||||
wip = "%"
|
||||
}
|
||||
if res, err := DBExec("INSERT INTO exercices (id_theme, title, disabled, url_id, path, statement, overview, finished, headline, issue, depend, gain, video_uri, resolution, seealso, issue_kind, coefficient_cur) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, "+ik+", "+cc+")", t.Id, wip+e.Title, e.Disabled, e.URLId, e.Path, e.Statement, e.Overview, e.Finished, e.Headline, e.Issue, e.Depend, e.Gain, e.VideoURI, e.Resolution, e.SeeAlso); err != nil {
|
||||
if res, err := DBExec("INSERT INTO exercices (id_theme, title, image, disabled, url_id, path, statement, overview, finished, headline, issue, depend, gain, video_uri, resolution, seealso, issue_kind, coefficient_cur) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, "+ik+", "+cc+")", t.Id, wip+e.Title, e.Image, e.Disabled, e.URLId, e.Path, e.Statement, e.Overview, e.Finished, e.Headline, e.Issue, e.Depend, e.Gain, e.VideoURI, e.Resolution, e.SeeAlso); err != nil {
|
||||
return err
|
||||
} else if eid, err := res.LastInsertId(); err != nil {
|
||||
return err
|
||||
|
@ -234,7 +235,7 @@ func (t *Theme) addExercice(e *Exercice) (err error) {
|
|||
}
|
||||
|
||||
// AddExercice creates and fills a new struct Exercice and registers it into the database.
|
||||
func (t *Theme) AddExercice(title string, wip bool, urlId string, path string, statement string, overview string, headline string, depend *Exercice, gain int64, videoURI string, resolution string, seealso string, finished string) (e *Exercice, err error) {
|
||||
func (t *Theme) AddExercice(title string, image string, wip bool, urlId string, path string, statement string, overview string, headline string, depend *Exercice, gain int64, videoURI string, resolution string, seealso string, finished string) (e *Exercice, err error) {
|
||||
var dpd *int64 = nil
|
||||
if depend != nil {
|
||||
dpd = &depend.Id
|
||||
|
@ -242,6 +243,7 @@ func (t *Theme) AddExercice(title string, wip bool, urlId string, path string, s
|
|||
|
||||
e = &Exercice{
|
||||
Title: title,
|
||||
Image: image,
|
||||
Disabled: false,
|
||||
WIP: wip,
|
||||
URLId: urlId,
|
||||
|
@ -269,7 +271,7 @@ func (e *Exercice) Update() (int64, error) {
|
|||
wip = "%"
|
||||
}
|
||||
|
||||
if res, err := DBExec("UPDATE exercices SET title = ?, disabled = ?, url_id = ?, path = ?, statement = ?, overview = ?, headline = ?, issue = ?, issue_kind = ?, depend = ?, gain = ?, coefficient_cur = ?, video_uri = ?, resolution = ?, seealso = ?, finished = ? WHERE id_exercice = ?", wip+e.Title, e.Disabled, e.URLId, e.Path, e.Statement, e.Overview, e.Headline, e.Issue, e.IssueKind, e.Depend, e.Gain, e.Coefficient, e.VideoURI, e.Resolution, e.SeeAlso, e.Finished, e.Id); err != nil {
|
||||
if res, err := DBExec("UPDATE exercices SET title = ?, image = ?, disabled = ?, url_id = ?, path = ?, statement = ?, overview = ?, headline = ?, issue = ?, issue_kind = ?, depend = ?, gain = ?, coefficient_cur = ?, video_uri = ?, resolution = ?, seealso = ?, finished = ? WHERE id_exercice = ?", wip+e.Title, e.Image, e.Disabled, e.URLId, e.Path, e.Statement, e.Overview, e.Headline, e.Issue, e.IssueKind, e.Depend, e.Gain, e.Coefficient, e.VideoURI, e.Resolution, e.SeeAlso, e.Finished, e.Id); err != nil {
|
||||
return 0, err
|
||||
} else if nb, err := res.RowsAffected(); err != nil {
|
||||
return 0, err
|
||||
|
|
Reference in a new issue