fix nil userId on getTodo query

This commit is contained in:
gilex-dev 2023-11-17 23:49:50 +01:00
parent 4851da8d19
commit 93ef12d8a9
1 changed files with 4 additions and 3 deletions

View File

@ -51,13 +51,14 @@ func (db CustomDB) GetTodo(todo *model.Todo) (*model.Todo, error) {
return nil, errors.New("invalid todoId")
}
statement, err := db.connection.Prepare("SELECT text, IS_done FROM Todo WHERE todoId = ?")
statement, err := db.connection.Prepare("SELECT text, IS_done, FK_User_userId FROM Todo WHERE todoId = ?")
if err != nil {
return nil, err
}
todo.User = &model.User{} // TODO: check if this overrides something
result := statement.QueryRow(numTodoId)
if err := result.Scan(&todo.Text, &todo.Done); err != nil {
if err := result.Scan(&todo.Text, &todo.Done, &todo.User.ID); err != nil {
return nil, err
}
@ -138,7 +139,7 @@ func (db CustomDB) CreateTodo(newTodo model.NewTodo) (*model.Todo, error) {
if err != nil {
return nil, err
}
return &model.Todo{ID: strconv.FormatInt(insertId, 10), Text: newTodo.Text, Done: false}, nil
return &model.Todo{ID: strconv.FormatInt(insertId, 10), Text: newTodo.Text, Done: false, User: &model.User{ID: newTodo.UserID}}, nil
}
func (db CustomDB) UpdateTodo(todoId string, changes *model.UpdateTodo) (*model.Todo, error) {