From b67a1cccd5a255d0fe93ba82d8b15e69d63f9e97 Mon Sep 17 00:00:00 2001 From: Chris Sexton Date: Fri, 8 Nov 2019 00:26:02 -0500 Subject: [PATCH] fix search, new, delete --- entry/entry.go | 17 ++++++---- frontend/src/App.vue | 15 +++++++++ frontend/src/components/Search.vue | 21 ++++++++----- frontend/src/components/TagList.vue | 2 +- frontend/src/store/index.js | 48 ++++++++++++++++++++++------- frontend/src/views/Console.vue | 2 +- web/entry.go | 1 + web/routes.go | 20 ++++++------ 8 files changed, 90 insertions(+), 36 deletions(-) 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 @@