Add authors in themes
This commit is contained in:
parent
e628e7931c
commit
859dbc68cb
4 changed files with 24 additions and 17 deletions
|
@ -23,7 +23,8 @@ type exportedExercice struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type exportedTheme struct {
|
type exportedTheme struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
|
Authors string `json:"authors"`
|
||||||
Exercices map[string]exportedExercice `json:"exercices"`
|
Exercices map[string]exportedExercice `json:"exercices"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,6 +47,7 @@ func exportThemes() (interface{}, error) {
|
||||||
}
|
}
|
||||||
ret[fmt.Sprintf("%d", theme.Id)] = exportedTheme{
|
ret[fmt.Sprintf("%d", theme.Id)] = exportedTheme{
|
||||||
theme.Name,
|
theme.Name,
|
||||||
|
theme.Authors,
|
||||||
exos,
|
exos,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -108,7 +110,8 @@ func listTheme(args []string, body []byte) (interface{}, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
type uploadedTheme struct {
|
type uploadedTheme struct {
|
||||||
Name string
|
Name string
|
||||||
|
Authors string
|
||||||
}
|
}
|
||||||
|
|
||||||
func creationTheme(args []string, body []byte) (interface{}, error) {
|
func creationTheme(args []string, body []byte) (interface{}, error) {
|
||||||
|
@ -129,7 +132,7 @@ func creationTheme(args []string, body []byte) (interface{}, error) {
|
||||||
return nil, errors.New("Theme's name not filled")
|
return nil, errors.New("Theme's name not filled")
|
||||||
}
|
}
|
||||||
|
|
||||||
return fic.CreateTheme(ut.Name)
|
return fic.CreateTheme(ut.Name, ut.Authors)
|
||||||
} else {
|
} else {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,8 @@ CLOUDPASS=fic:'f>t\nV33R|(+?$i*'
|
||||||
|
|
||||||
new_theme() {
|
new_theme() {
|
||||||
NAME=`echo $1 | sed 's/"/\\\\"/g'`
|
NAME=`echo $1 | sed 's/"/\\\\"/g'`
|
||||||
curl -f -s -d "{\"name\": \"$NAME\"}" "${BASEURL}/api/themes/" |
|
AUTHORS=`echo $2 | sed 's/"/\\\\"/g'`
|
||||||
|
curl -f -s -d "{\"name\": \"$NAME\", \"authors\": \"$AUTHORS\"}" "${BASEURL}/api/themes/" |
|
||||||
grep -Eo '"id":[0-9]+,' | grep -Eo "[0-9]+"
|
grep -Eo '"id":[0-9]+,' | grep -Eo "[0-9]+"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,10 +44,12 @@ new_key() {
|
||||||
}
|
}
|
||||||
|
|
||||||
# Theme
|
# Theme
|
||||||
curl -f -s -X PROPFIND -u "${CLOUDPASS}" "${BASEURI}" | xmllint --format - | grep 'd:href' | sed -E 's/^.*>(.*)<.*$/\1/' | sed 1d | while read f; do basename "$f"; done | while read THEME_URI
|
curl -f -s -X PROPFIND -u "${CLOUDPASS}" "${BASEURI}" | xmllint --format - | grep 'd:href' | sed -E 's/^.*>(.*)<.*$/\1/' | sed 1d | tac | while read f; do basename "$f"; done | while read THEME_URI
|
||||||
do
|
do
|
||||||
|
THM_BASEURI="/${THEME_URI}/"
|
||||||
THEME_NAME=$(echo "${THEME_URI}" | sed -E 's/%20/ /g' | sed -E 's/%c3%a9/é/g' | sed -E 's/%c3%a8/è/g')
|
THEME_NAME=$(echo "${THEME_URI}" | sed -E 's/%20/ /g' | sed -E 's/%c3%a9/é/g' | sed -E 's/%c3%a8/è/g')
|
||||||
THEME_ID=`new_theme "$THEME_NAME"`
|
THEME_AUTHORS=$(curl -f -s -u "${CLOUDPASS}" "${BASEURI}${THM_BASEURI}/AUTHORS.txt" | sed 's/$/,/' | xargs)
|
||||||
|
THEME_ID=`new_theme "$THEME_NAME" "$THEME_AUTHORS"`
|
||||||
if [ -z "$THEME_ID" ]; then
|
if [ -z "$THEME_ID" ]; then
|
||||||
echo -e "\e[31;01m!!! An error occured during theme add\e[00m"
|
echo -e "\e[31;01m!!! An error occured during theme add\e[00m"
|
||||||
continue
|
continue
|
||||||
|
@ -56,7 +59,6 @@ do
|
||||||
|
|
||||||
LAST=null
|
LAST=null
|
||||||
EXO_NUM=0
|
EXO_NUM=0
|
||||||
THM_BASEURI="/${THEME_URI}/"
|
|
||||||
curl -f -s -X PROPFIND -u "${CLOUDPASS}" "${BASEURI}${THM_BASEURI}" | xmllint --format - | grep 'd:href' | sed -E 's/^.*>(.*)<.*$/\1/' | sed -E 's/%20/ /g' | sed -E 's/%c3%a9/é/g' | sed -E 's/%c3%a8/è/g' | sed 1d | while read f; do basename "$f"; done | while read EXO_NAME
|
curl -f -s -X PROPFIND -u "${CLOUDPASS}" "${BASEURI}${THM_BASEURI}" | xmllint --format - | grep 'd:href' | sed -E 's/^.*>(.*)<.*$/\1/' | sed -E 's/%20/ /g' | sed -E 's/%c3%a9/é/g' | sed -E 's/%c3%a8/è/g' | sed 1d | while read f; do basename "$f"; done | while read EXO_NAME
|
||||||
do
|
do
|
||||||
if ! echo $EXO_NAME | grep Exercice > /dev/null
|
if ! echo $EXO_NAME | grep Exercice > /dev/null
|
||||||
|
|
|
@ -23,7 +23,8 @@ func DBCreate() error {
|
||||||
_, err := db.Exec(`
|
_, err := db.Exec(`
|
||||||
CREATE TABLE IF NOT EXISTS themes(
|
CREATE TABLE IF NOT EXISTS themes(
|
||||||
id_theme INTEGER NOT NULL PRIMARY KEY,
|
id_theme INTEGER NOT NULL PRIMARY KEY,
|
||||||
name TEXT NOT NULL
|
name TEXT NOT NULL UNIQUE,
|
||||||
|
authors TEXT NOT NULL
|
||||||
);
|
);
|
||||||
CREATE TABLE IF NOT EXISTS teams(
|
CREATE TABLE IF NOT EXISTS teams(
|
||||||
id_team INTEGER NOT NULL PRIMARY KEY,
|
id_team INTEGER NOT NULL PRIMARY KEY,
|
||||||
|
|
|
@ -3,12 +3,13 @@ package fic
|
||||||
import ()
|
import ()
|
||||||
|
|
||||||
type Theme struct {
|
type Theme struct {
|
||||||
Id int64 `json:"id"`
|
Id int64 `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
|
Authors string `json:"authors"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetThemes() ([]Theme, error) {
|
func GetThemes() ([]Theme, error) {
|
||||||
if rows, err := DBQuery("SELECT id_theme, name FROM themes"); err != nil {
|
if rows, err := DBQuery("SELECT id_theme, name, authors FROM themes"); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
} else {
|
} else {
|
||||||
defer rows.Close()
|
defer rows.Close()
|
||||||
|
@ -16,7 +17,7 @@ func GetThemes() ([]Theme, error) {
|
||||||
var themes = make([]Theme, 0)
|
var themes = make([]Theme, 0)
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var t Theme
|
var t Theme
|
||||||
if err := rows.Scan(&t.Id, &t.Name); err != nil {
|
if err := rows.Scan(&t.Id, &t.Name, &t.Authors); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
themes = append(themes, t)
|
themes = append(themes, t)
|
||||||
|
@ -31,25 +32,25 @@ func GetThemes() ([]Theme, error) {
|
||||||
|
|
||||||
func GetTheme(id int) (Theme, error) {
|
func GetTheme(id int) (Theme, error) {
|
||||||
var t Theme
|
var t Theme
|
||||||
if err := DBQueryRow("SELECT id_theme, name FROM themes WHERE id_theme=?", id).Scan(&t.Id, &t.Name); err != nil {
|
if err := DBQueryRow("SELECT id_theme, name, authors FROM themes WHERE id_theme=?", id).Scan(&t.Id, &t.Name, &t.Authors); err != nil {
|
||||||
return t, err
|
return t, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return t, nil
|
return t, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateTheme(name string) (Theme, error) {
|
func CreateTheme(name string, authors string) (Theme, error) {
|
||||||
if res, err := DBExec("INSERT INTO themes (name) VALUES (?)", name); err != nil {
|
if res, err := DBExec("INSERT INTO themes (name, authors) VALUES (?, ?)", name, authors); err != nil {
|
||||||
return Theme{}, err
|
return Theme{}, err
|
||||||
} else if tid, err := res.LastInsertId(); err != nil {
|
} else if tid, err := res.LastInsertId(); err != nil {
|
||||||
return Theme{}, err
|
return Theme{}, err
|
||||||
} else {
|
} else {
|
||||||
return Theme{tid, name}, nil
|
return Theme{tid, name, authors}, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t Theme) Update() (int64, error) {
|
func (t Theme) Update() (int64, error) {
|
||||||
if res, err := DBExec("UPDATE themes SET name = ? WHERE id_theme = ?", t.Name, t.Id); err != nil {
|
if res, err := DBExec("UPDATE themes SET name = ?, authors = ? WHERE id_theme = ?", t.Name, t.Authors, t.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