t

commit a0dd9f91475b845eb6932535205dac02e152da6c

Author: Pedro Lucas Porcellis <pedrolucasporcellis@gmail.com>

List notes

 commands/list.go | 55 +++++++++++++++++++++++++++++++++++++++++++++++++
 main.go | 29 ++++++++++++-------------
 models/models.go | 10 +++++++-


diff --git a/commands/list.go b/commands/list.go
new file mode 100644
index 0000000000000000000000000000000000000000..e7349b08354999abd7a8c22b109f21920620e2eb
--- /dev/null
+++ b/commands/list.go
@@ -0,0 +1,55 @@
+package commands
+
+import (
+	"fmt"
+	"git.sr.ht/~porcellis/t/config"
+	"git.sr.ht/~porcellis/t/models"
+	"io/ioutil"
+	"path"
+	"sort"
+)
+
+func List(config config.TConfig) error {
+	var (
+		err error
+	)
+
+	notes, err := BuildList(config)
+
+	if err != nil {
+		return err
+	}
+
+	fmt.Println("\n \t Your notes")
+
+	for index, note := range notes {
+		if index > 0 {
+			fmt.Printf("|#%-6d|\t%6s\t|%6s|\n", index, note.Title(), note.UpdatedAt())
+		}
+	}
+
+	return err
+}
+
+func BuildList(config config.TConfig) ([]models.Note, error) {
+	var (
+		err   error
+		notes []models.Note
+	)
+
+	fmt.Println("Listing some stuff")
+
+	files, err := ioutil.ReadDir(config.BasePath)
+
+	sort.Slice(files, func(index, aux int) bool {
+		return files[index].ModTime().After(files[aux].ModTime())
+	})
+
+	for _, entry := range files {
+		note := models.Note{Name: entry.Name(), Path: path.Join(config.BasePath, entry.Name()), ModTime: entry.ModTime()}
+
+		notes = append(notes, note)
+	}
+
+	return notes, err
+}




diff --git a/main.go b/main.go
index 254c7738b7d28260d724a27b7f5bf3bb7a0b09dd..d4794144cd9c3ad952e0e4c9ad3fe9a4602d7423 100644
--- a/main.go
+++ b/main.go
@@ -1,26 +1,25 @@
 package main
 
 import (
-  "fmt"
-  "git.sr.ht/~porcellis/t/models"
-  "git.sr.ht/~porcellis/t/config"
+	"fmt"
+	"git.sr.ht/~porcellis/t/commands"
+	"git.sr.ht/~porcellis/t/config"
 )
 
 func main() {
-  var (
-    n models.Note
-    c *config.TConfig
-  )
+	var (
+		c *config.TConfig
+	)
 
-  c, err := config.Initialize()
-  
-  if err != nil {
-    panic(err)
-  }
+	c, err := config.Initialize()
 
-  fmt.Println(c)
+	if err != nil {
+		panic(err)
+	}
 
-  n = models.Note{"Test", "~/notes/test.md"}
+	err = commands.List(*c)
 
-  fmt.Println(n)
+	if err != nil {
+		fmt.Println(err)
+	}
 }




diff --git a/models/models.go b/models/models.go
index 52125a93dfd63cab8bba30be7a28732a8bd7621c..37586beebb6884bc2ba6c6e6bf49cbd0bc073912 100644
--- a/models/models.go
+++ b/models/models.go
@@ -2,13 +2,19 @@ package models
 
 import (
 	"strings"
+	"time"
 )
 
 type Note struct {
-	Name string
-	Path string
+	Name    string
+	Path    string
+	ModTime time.Time
 }
 
 func (note *Note) Title() string {
 	return strings.Split(note.Name, ".")[0]
 }
+
+func (note *Note) UpdatedAt() string {
+	return note.ModTime.Format("Mon, Jan _2 15:04:05 2006")
+}