summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Lemon <y@yulqen.org>2024-12-19 09:10:50 +0000
committerMatthew Lemon <y@yulqen.org>2024-12-19 09:10:50 +0000
commite2a2551d7cc40cf669086a0c9453df18ab341fb1 (patch)
tree0c3d3f55afe1b091473364223e1a54e86d85498b
parent5bed4233afe9404d19916f6e66d9396e24a848fc (diff)
incrememental improvements
-rw-r--r--tjp.go49
1 files changed, 32 insertions, 17 deletions
diff --git a/tjp.go b/tjp.go
index b192189..60c38d4 100644
--- a/tjp.go
+++ b/tjp.go
@@ -18,6 +18,13 @@ const (
dbname = "journal"
)
+const (
+ JOURNAL_TYPE_MOD = iota + 1
+ JOURNAL_TYPE_PERSONAL
+ JOURNAL_TYPE_JOBBY
+ JOURNAL_TYPE_SLEEP
+)
+
var db *sql.DB
func init() {
@@ -51,34 +58,38 @@ func addSleepEntry(entry string) {
}
}
-func addPersonalEntry(entry string) {
- _, err := db.Exec("INSERT INTO journal_entries (entry, type) VALUES ($1, 2)", entry)
- if err != nil {
- log.Fatal(err)
- }
-}
-
-func addMODEntry(entry string) {
- _, err := db.Exec("INSERT INTO journal_entries (entry, type) VALUES ($1, 1)", entry)
+func addJournalEntry(entry string, journalType int) {
+ _, err := db.Exec(fmt.Sprintf("INSERT INTO journal_entries (entry, type) VALUES ('%s', %d)", entry, journalType))
if err != nil {
log.Fatal(err)
}
}
-func listPersonalEntries(orientation string) {
+// List journal entries, dependent on journalType
+func listjournalEntries(orientation string, journalType int) {
var rows *sql.Rows
var id sql.NullInt64
var dateAdded sql.NullTime
var entry sql.NullString
var comment sql.NullString
+ var header string
+ var err error
+
+ // if MOD journalType
+ if journalType == JOURNAL_TYPE_MOD {
+ rows, err = db.Query(fmt.Sprintf("SELECT id, date_added, entry, comment FROM journal_entries WHERE type = %d AND meeting_id IS NULL ORDER BY date_added ASC, id ASC", journalType))
+ header = "MOD entries:"
+ } else if journalType == JOURNAL_TYPE_PERSONAL {
+ rows, err = db.Query(fmt.Sprintf("SELECT id, date_added, entry, comment FROM journal_entries WHERE type = %d ORDER BY date_added ASC, id ASC", journalType))
+ header = "Personal entries:"
+ }
- rows, err := db.Query("SELECT id, date_added, entry, comment FROM journal_entries WHERE type = 2 ORDER BY date_added ASC, id ASC")
if err != nil {
log.Fatal(err)
}
defer rows.Close()
- fmt.Println("Personal Entries:")
+ fmt.Println(header)
var previousDateAdded sql.NullTime // Track the previous date only
previousDateAdded.Time = time.Time{} // Initialize to zero value
@@ -160,17 +171,19 @@ func main() {
firstName := flag.String("firstName", "", "First name of the contact")
lastName := flag.String("lastName", "", "Last name of the contact")
+ entry := flag.String("entry", "", "Content of the journal entry")
+
orientationFlag := flag.String("orientation", "horizontal", "Orientation of the journal entries (vertical or horizontal)")
addSleepEntryFlag := flag.Bool("addSleepEntry", false, "Add a sleep entry")
sleepEntry := flag.String("sleepEntry", "", "Content of the sleep entry")
addPersonalEntryFlag := flag.Bool("p", false, "Add a personal entry")
- entry := flag.String("entry", "", "Content of the journal entry")
- addMODEntryFlag := flag.Bool("addMODEntry", false, "Add a MOD entry")
+ addMODEntryFlag := flag.Bool("m", false, "Add a MOD entry")
listPersonalEntriesFlag := flag.Bool("l", false, "List all personal entries")
+ listMODEntriesFlag := flag.Bool("M", false, "List all MOD entries, not including those associated with a meeting")
// Parse flags
flag.Parse()
@@ -190,14 +203,16 @@ func main() {
if *entry == "" {
log.Fatal("Personal entry content must be provided - use the -entry flag")
}
- addPersonalEntry(*entry)
+ addJournalEntry(*entry, JOURNAL_TYPE_PERSONAL)
} else if *addMODEntryFlag {
if *entry == "" {
log.Fatal("MOD entry content must be provided - use the -entry flag")
}
- addMODEntry(*entry)
+ addJournalEntry(*entry, JOURNAL_TYPE_MOD)
} else if *listPersonalEntriesFlag {
- listPersonalEntries(*orientationFlag)
+ listjournalEntries(*orientationFlag, 2)
+ } else if *listMODEntriesFlag {
+ listjournalEntries(*orientationFlag, 1)
} else {
flag.Usage() // Print usage if no valid flags are provided
os.Exit(1)