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
|
|
@ -8,15 +8,15 @@ import (
|
|||
)
|
||||
|
||||
type EFile struct {
|
||||
id int64
|
||||
Path string
|
||||
id_exercice int64
|
||||
Name string
|
||||
Checksum []byte
|
||||
Id int64 `json:"id"`
|
||||
Path string `json:"path"`
|
||||
IdExercice int64 `json:"idExercice"`
|
||||
Name string `json:"name"`
|
||||
Checksum []byte `json:"checksum"`
|
||||
}
|
||||
|
||||
func (e Exercice) GetFiles() ([]EFile, error) {
|
||||
if rows, err := DBQuery("SELECT id_file, path, name, sha1 FROM exercice_files WHERE id_exercice = ?", e.id); err != nil {
|
||||
if rows, err := DBQuery("SELECT id_file, path, name, sha1 FROM exercice_files WHERE id_exercice = ?", e.Id); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
defer rows.Close()
|
||||
|
|
@ -24,8 +24,8 @@ func (e Exercice) GetFiles() ([]EFile, error) {
|
|||
var files = make([]EFile, 0)
|
||||
for rows.Next() {
|
||||
var f EFile
|
||||
f.id_exercice = e.id
|
||||
if err := rows.Scan(&f.id, &f.Path, &f.Name, &f.Checksum); err != nil {
|
||||
f.IdExercice = e.Id
|
||||
if err := rows.Scan(&f.Id, &f.Path, &f.Name, &f.Checksum); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
files = append(files, f)
|
||||
|
|
@ -55,17 +55,17 @@ func (e Exercice) ImportFile(filePath string) (EFile, error) {
|
|||
}
|
||||
|
||||
func (e Exercice) AddFile(path string, name string, checksum []byte) (EFile, error) {
|
||||
if res, err := DBExec("INSERT INTO exercice_files (id_exercice, path, name, sha1) VALUES (?, ?, ?, ?)", e.id, path, name, checksum); err != nil {
|
||||
if res, err := DBExec("INSERT INTO exercice_files (id_exercice, path, name, sha1) VALUES (?, ?, ?, ?)", e.Id, path, name, checksum); err != nil {
|
||||
return EFile{}, err
|
||||
} else if fid, err := res.LastInsertId(); err != nil {
|
||||
return EFile{}, err
|
||||
} else {
|
||||
return EFile{fid, path, e.id, name, checksum}, nil
|
||||
return EFile{fid, path, e.Id, name, checksum}, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (f EFile) Update() (int64, error) {
|
||||
if res, err := DBExec("UPDATE exercice_files SET id_exercice = ?, path = ?, name = ?, sha1 = ? WHERE id_file = ?", f.id_exercice, f.Path, f.Name, f.Checksum, f.id); err != nil {
|
||||
if res, err := DBExec("UPDATE exercice_files SET id_exercice = ?, path = ?, name = ?, sha1 = ? WHERE id_file = ?", f.IdExercice, f.Path, f.Name, f.Checksum, f.Id); err != nil {
|
||||
return 0, err
|
||||
} else if nb, err := res.RowsAffected(); err != nil {
|
||||
return 0, err
|
||||
|
|
@ -75,7 +75,7 @@ func (f EFile) Update() (int64, error) {
|
|||
}
|
||||
|
||||
func (f EFile) Delete() (int64, error) {
|
||||
if res, err := DBExec("DELETE FROM exercice_files WHERE id_file = ?", f.id); err != nil {
|
||||
if res, err := DBExec("DELETE FROM exercice_files WHERE id_file = ?", f.Id); err != nil {
|
||||
return 0, err
|
||||
} else if nb, err := res.RowsAffected(); err != nil {
|
||||
return 0, err
|
||||
|
|
|
|||
Reference in a new issue