add getNote method

This commit is contained in:
agatha 2024-05-12 15:09:32 -04:00
parent c778ec988b
commit 0bcb6a53bf

14
main.go
View File

@ -116,8 +116,6 @@ func (ctx *AppContext) AddNote(note Note) {
} }
func main() { func main() {
// TODO: Clean up menu prompt
// TODO: Write getNote method
// TODO: Write option handlers (handleNewNote, handleNewReading) // TODO: Write option handlers (handleNewNote, handleNewReading)
var appCtx AppContext var appCtx AppContext
@ -149,11 +147,10 @@ func main() {
} }
case "2": case "2":
// Get a new Note from the user // Get a new Note from the user
noteText, err := getUserInput("Enter your note text: ") note, err := getNote()
if err != nil { if err != nil {
fmt.Printf("Error getting note: %s\n", err) fmt.Printf("Error getting note: %s\n", err)
} else { } else {
note := NewNote(noteText)
appCtx.AddNote(note) appCtx.AddNote(note)
} }
default: default:
@ -167,6 +164,14 @@ func main() {
} }
} }
func getNote() (Note, error) {
text, err := getUserInput("Enter note text")
if err != nil {
return Note{}, err
}
return NewNote(text), nil
}
func getReading() (Reading, error) { func getReading() (Reading, error) {
// Get glucose reading // Get glucose reading
glucose, err := getUserFloat("Enter glucose reading (mg/dL)") glucose, err := getUserFloat("Enter glucose reading (mg/dL)")
@ -208,7 +213,6 @@ func getReading() (Reading, error) {
fmt.Println("You are not in ketosis.") fmt.Println("You are not in ketosis.")
} }
//return NewReading(glucose, ketone), nil
return reading, nil return reading, nil
} }