func archiveNote(rq rsrq.ArchiveNoteRQ) error { db, dbErr := data.GetDataConnection() if dbErr != nil { log.Fatal(dbErr) } defer db.Close() archiveNoteUpdate := data.ARCHIVE_NOTE_UPDATE archiveNoteUpdate = strings.Replace(archiveNoteUpdate, "{ID}", rq.NoteId, 1) archiveNoteUpdate = strings.Replace(archiveNoteUpdate, "{USERID}", rq.UserToken, 1) return data.ExecStatement(db, archiveNoteUpdate) }
//TODO add this to Note Data Controller (DAO / Registry) func insertNewNote(user string, noteId string, parentId string) error { db, dbErr := data.GetDataConnection() if dbErr != nil { log.Fatal(dbErr) } defer db.Close() insertQuery := data.INSERT_NOTE insertQuery = strings.Replace(insertQuery, "{ID}", noteId, 1) insertQuery = strings.Replace(insertQuery, "{PARENTID}", parentId, 1) insertQuery = strings.Replace(insertQuery, "{NAME}", "New Note", 1) //todo constant for new note name insertQuery = strings.Replace(insertQuery, "{CONTENT}", "", 1) insertQuery = strings.Replace(insertQuery, "{STATUS}", strconv.Itoa(data.NEW), 1) insertQuery = strings.Replace(insertQuery, "{CREATED}", strconv.FormatInt(time.Now().UnixNano(), 10), 1) insertQuery = strings.Replace(insertQuery, "{MODIFIED}", strconv.FormatInt(time.Now().UnixNano(), 10), 1) insertQuery = strings.Replace(insertQuery, "{USERID}", user, 1) //TODO put in order return data.ExecStatement(db, insertQuery) }
func getNotes(rq rsrq.ListNotesRQ) ([]model.Note, error) { db, dbErr := data.GetDataConnection() if dbErr != nil { log.Fatal(dbErr) } defer db.Close() listQuery := data.SELECT_NOTES_BY_PARENT listQuery = strings.Replace(listQuery, "{PARENTID}", rq.ParentId, 1) listQuery = strings.Replace(listQuery, "{USERID}", rq.UserToken, 1) listQuery = strings.Replace(listQuery, "{STATUS}", strconv.Itoa(rq.Status), 1) rows, err := db.Query(listQuery) if err != nil { return nil, err } defer rows.Close() noteList := []model.Note{} for rows.Next() { var ( id string userid string name string parentid string content string status int created int64 modified int64 ) rows.Scan(&id, &userid, &parentid, &name, &content, &status, &created, &modified) note := model.Note{id, userid, name, content, status, created, modified, parentid} noteList = append(noteList, note) } rows.Close() return noteList, nil }