Change internal variable representation vs JSON one
This commit is contained in:
parent
8cf2a36fe1
commit
e89af34c5c
6 changed files with 61 additions and 61 deletions
22
admin/key.go
22
admin/key.go
|
|
@ -5,14 +5,14 @@ import (
|
|||
)
|
||||
|
||||
type Key struct {
|
||||
id int64
|
||||
id_exercice int64
|
||||
Type string
|
||||
Value [64]byte
|
||||
Id int64 `json:"id"`
|
||||
IdExercice int64 `json:"idExercice"`
|
||||
Type string `json:"type"`
|
||||
Value [64]byte `json:"value"`
|
||||
}
|
||||
|
||||
func (e Exercice) GetKeys() ([]Key, error) {
|
||||
if rows, err := DBQuery("SELECT id_key, type, value FROM exercice_keys WHERE id_exercice = ?", e.id); err != nil {
|
||||
if rows, err := DBQuery("SELECT id_key, type, value FROM exercice_keys WHERE id_exercice = ?", e.Id); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
defer rows.Close()
|
||||
|
|
@ -20,8 +20,8 @@ func (e Exercice) GetKeys() ([]Key, error) {
|
|||
var keys = make([]Key, 0)
|
||||
for rows.Next() {
|
||||
var k Key
|
||||
k.id_exercice = e.id
|
||||
if err := rows.Scan(&k.id, &k.id_exercice, &k.Type, &k.Value); err != nil {
|
||||
k.IdExercice = e.Id
|
||||
if err := rows.Scan(&k.Id, &k.IdExercice, &k.Type, &k.Value); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
keys = append(keys, k)
|
||||
|
|
@ -39,17 +39,17 @@ func (e Exercice) AddRawKey(name string, raw_value string) (Key, error) {
|
|||
}
|
||||
|
||||
func (e Exercice) AddKey(name string, value [64]byte) (Key, error) {
|
||||
if res, err := DBExec("INSERT INTO exercice_keys (id_exercice, type, value) VALUES (?, ?, ?)", e.id, name, value); err != nil {
|
||||
if res, err := DBExec("INSERT INTO exercice_keys (id_exercice, type, value) VALUES (?, ?, ?)", e.Id, name, value); err != nil {
|
||||
return Key{}, err
|
||||
} else if kid, err := res.LastInsertId(); err != nil {
|
||||
return Key{}, err
|
||||
} else {
|
||||
return Key{kid, e.id, name, value}, nil
|
||||
return Key{kid, e.Id, name, value}, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (k Key) Update() (int64, error) {
|
||||
if res, err := DBExec("UPDATE exercice_keys SET id_exercice = ?, type = ?, value = ? WHERE id_key = ?", k.id_exercice, k.Type, k.Value, k.id); err != nil {
|
||||
if res, err := DBExec("UPDATE exercice_keys SET id_exercice = ?, type = ?, value = ? WHERE id_key = ?", k.IdExercice, k.Type, k.Value, k.Id); err != nil {
|
||||
return 0, err
|
||||
} else if nb, err := res.RowsAffected(); err != nil {
|
||||
return 0, err
|
||||
|
|
@ -59,7 +59,7 @@ func (k Key) Update() (int64, error) {
|
|||
}
|
||||
|
||||
func (k Key) Delete() (int64, error) {
|
||||
if res, err := DBExec("DELETE FROM exercice_keys WHERE id_key = ?", k.id); err != nil {
|
||||
if res, err := DBExec("DELETE FROM exercice_keys WHERE id_key = ?", k.Id); err != nil {
|
||||
return 0, err
|
||||
} else if nb, err := res.RowsAffected(); err != nil {
|
||||
return 0, err
|
||||
|
|
|
|||
Reference in a new issue