diff --git a/entry/entry.go b/entry/entry.go index ab640c3..18a46d1 100644 --- a/entry/entry.go +++ b/entry/entry.go @@ -52,13 +52,18 @@ func PrepareTable(tx *sqlx.Tx) error { return nil } -func New(db *db.Database) Entry { - return Entry{ +func New(db *db.Database) *Entry { + e := Entry{ db: db, ID: -1, Created: time.Now(), Updated: time.Now(), + Tags: []string{}, } + e.Title = e.GenerateTitle() + e.Slug = e.UniqueSlug() + e.Content = "= " + e.Title + return &e } func GetBySlug(db *db.Database, slug string) (Entry, error) { @@ -85,13 +90,13 @@ func Search(db *db.Database, query string) ([]*Entry, error) { entries := []*Entry{} log.Debug().Str("query", query).Msg("searching") if query != "" { - q := `select * from entries where content like ?` + q := `select * from entries where content like ? order by updated desc` err := db.Select(&entries, q, "%"+query+"%") if err != nil { return nil, err } } else { - q := `select * from entries` + q := `select * from entries order by updated desc` err := db.Select(&entries, q) if err != nil { return nil, err @@ -119,12 +124,12 @@ func RemoveBySlug(db *db.Database, slug string) error { tx.Rollback() return err } - q = `delete from entries where entry_id = ?` + q = `delete from entries where id = ?` if _, err := tx.Exec(q, e.ID); err != nil { tx.Rollback() return err } - return nil + return tx.Commit() } func (e *Entry) populateTags() error { diff --git a/frontend/src/App.vue b/frontend/src/App.vue index 0335ceb..d8074ae 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -7,6 +7,11 @@ Console About + + + + + + @@ -42,6 +47,16 @@ name: 'app', components: { Error + }, + methods: { + newFile: function() { + this.$store.dispatch('newFile') + .catch(err => console.log(err)) + .then(file => { + this.$store.dispatch('updateSearch') + this.$router.push({ name: 'console-slug', params: { slug: file.Slug }}) + }) + } } } diff --git a/frontend/src/components/Search.vue b/frontend/src/components/Search.vue index 22b0dda..286df71 100644 --- a/frontend/src/components/Search.vue +++ b/frontend/src/components/Search.vue @@ -1,11 +1,11 @@