From 75821110de7010fae3a34ea402a00ae152e040d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=9E=E3=83=AA=E3=82=A6=E3=82=B9?= Date: Fri, 16 Oct 2020 00:59:25 +0100 Subject: [PATCH] Implemented first shot of working import command --- z/import.go | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/z/import.go b/z/import.go index 9086e9c..9a3a030 100644 --- a/z/import.go +++ b/z/import.go @@ -32,7 +32,6 @@ func importTymeJson(user string, file string) ([]Entry, error) { continue } - entry, err := NewEntry("", "", "", tymeEntry.Project, tymeEntry.Task, user) if err != nil { fmt.Printf("%s %+v\n", CharError, err) @@ -67,7 +66,34 @@ var importCmd = &cobra.Command{ fmt.Printf("%s %+v\n", CharError, err) os.Exit(1) } - fmt.Printf("%+v", entries) + } + + sha1List, sha1Err := database.GetImportsSHA1List(user) + if sha1Err != nil { + fmt.Printf("%s %+v\n", CharError, sha1Err) + os.Exit(1) + } + + for _, entry := range entries { + if id, ok := sha1List[entry.SHA1]; ok { + fmt.Printf("%s %s was previously imported as %s; not importing again\n", CharInfo, entry.SHA1, id) + continue + } + + importedId, err := database.AddEntry(user, entry, false) + if err != nil { + fmt.Printf("%s %s could not be imported: %+v\n", CharError, entry.SHA1, err) + continue + } + + fmt.Printf("%s %s was imported as %s\n", CharInfo, entry.SHA1, importedId) + sha1List[entry.SHA1] = importedId + } + + err = database.UpdateImportsSHA1List(user, sha1List) + if err != nil { + fmt.Printf("%s %+v\n", CharError, err) + os.Exit(1) } return