Compare commits

...

2 Commits

3 changed files with 10 additions and 5 deletions

View File

@ -55,6 +55,8 @@ func PrepareTable(tx *sqlx.Tx) error {
func NewFromMd(db *db.Database, body string) *Entry { func NewFromMd(db *db.Database, body string) *Entry {
e := New(db) e := New(db)
e.Content = body e.Content = body
e.Title = e.GenerateTitle()
e.Slug = e.UniqueSlug()
return e return e
} }

View File

@ -75,7 +75,7 @@
.then(res => { .then(res => {
this.$emit('markDirty', false) this.$emit('markDirty', false)
this.$store.dispatch('updateSearch') this.$store.dispatch('updateSearch')
if (res.data.Slug != this.$route.params.slug) if (res.data.Slug !== this.$route.params.slug)
this.$router.replace({params: { slug: res.data.Slug }}) this.$router.replace({params: { slug: res.data.Slug }})
}) })
.catch(() => { }) .catch(() => { })

View File

@ -17,13 +17,16 @@ func (web *Web) editEntry(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r) vars := mux.Vars(r)
slug := vars["slug"] slug := vars["slug"]
dec := json.NewDecoder(r.Body) dec := json.NewDecoder(r.Body)
newEntry := entry.New(web.db) req := struct {
err := dec.Decode(&newEntry) Content string
}{}
err := dec.Decode(&req)
if err != nil { if err != nil {
w.WriteHeader(500) w.WriteHeader(500)
fmt.Fprint(w, err) fmt.Fprint(w, err)
return return
} }
newEntry := entry.NewFromMd(web.db, req.Content)
oldEntry, err := entry.GetBySlug(web.db, slug) oldEntry, err := entry.GetBySlug(web.db, slug)
if err != nil { if err != nil {
@ -33,6 +36,8 @@ func (web *Web) editEntry(w http.ResponseWriter, r *http.Request) {
} }
oldEntry.Content = newEntry.Content oldEntry.Content = newEntry.Content
oldEntry.Title = newEntry.Title
oldEntry.Slug = newEntry.UniqueSlug()
oldEntry.Tags = newEntry.Tags oldEntry.Tags = newEntry.Tags
oldEntry.Updated = time.Now() oldEntry.Updated = time.Now()
@ -49,8 +54,6 @@ func (web *Web) editEntry(w http.ResponseWriter, r *http.Request) {
return return
} }
log.Debug().Interface("oldEntry", oldEntry).Msg("Got a PUT")
w.Header().Set("content-type", "application/json") w.Header().Set("content-type", "application/json")
fmt.Fprint(w, string(resp)) fmt.Fprint(w, string(resp))
} }