From 9f7a724a07b170e72760a9d9ea47e6ddae69f649 Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Thu, 19 Dec 2024 17:46:19 +0000 Subject: Can add meeting --- tjp.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tjp.go b/tjp.go index c044338..bd6c69c 100644 --- a/tjp.go +++ b/tjp.go @@ -41,6 +41,18 @@ func init() { } } +// addMODMeeting adds a MOD meeting to the database +func addMODMeeting(name string, date string, subject string) { + var meetingId int + query := fmt.Sprintf("INSERT INTO meetings (name, date, subject) VALUES ('%s', '%s', '%s') RETURNING id", name, date, subject) + err := db.QueryRow(query).Scan(&meetingId) + if err != nil { + log.Fatal(err) + } + fmt.Printf("MOD meeting added with ID: %d\n", meetingId) +} + +// addMODContact adds a MOD contact to the database func addMODContact(firstName, lastName string) { var contactId int query := `INSERT INTO contacts (first_name, last_name, contact_type) VALUES ($1, $2, 3) RETURNING id` @@ -51,6 +63,7 @@ func addMODContact(firstName, lastName string) { fmt.Printf("MOD contact added with ID: %d\n", contactId) } +// addSleepEntry adds a sleep entry to the database func addSleepEntry(entry string, journalType int) { _, err := db.Exec("INSERT INTO journal_entries (entry, type) VALUES ('%s', %d)", entry, journalType) if err != nil { @@ -58,6 +71,7 @@ func addSleepEntry(entry string, journalType int) { } } +// addJournalEntry adds a journal entry to the database 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 { @@ -177,8 +191,12 @@ func main() { entry := flag.String("entry", "", "Content of the journal entry") + dateOfEntry := flag.String("date", "", "Date of entry") + orientationFlag := flag.String("orientation", "horizontal", "Orientation of the journal entries (vertical or horizontal)") + addMODMeetingFlag := flag.Bool("add-meeting", false, "Add a MOD meeting") + addMODEntryFlag := flag.Bool("add-mod", false, "Add a MOD entry") addPersonalEntryFlag := flag.Bool("add-personal", false, "Add a Personal entry") addJobbylogEntryFlag := flag.Bool("add-jobby", false, "Add a Jobbylog entry") @@ -198,6 +216,14 @@ func main() { log.Fatal("Both firstName and lastName must be provided for adding a MOD contact") } addMODContact(*firstName, *lastName) + } else if *addMODMeetingFlag { + if *entry == "" { + log.Fatal("Meeting name must be provided with -entry flag") + } + if *dateOfEntry == "" { + log.Fatal("Meeting date must be provided with -date flag") + } + addMODMeeting(*entry, *dateOfEntry, "Meeting") } else if *addSleepEntryFlag { if *entry == "" { log.Fatal("Sleep entry content must be provided") -- cgit v1.2.3