summaryrefslogtreecommitdiff
path: root/src/http/posts.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/http/posts.go')
-rw-r--r--src/http/posts.go50
1 files changed, 17 insertions, 33 deletions
diff --git a/src/http/posts.go b/src/http/posts.go
index 09daac4..1950113 100644
--- a/src/http/posts.go
+++ b/src/http/posts.go
@@ -123,26 +123,14 @@ func (a *api) postToPostTplPayload(storedPost post.StoredPost) (postTplPayload,
return tplPayload, nil
}
-func (a *api) renderPostHandler() http.Handler {
+func (a *api) getPostHandler() http.Handler {
tpl := a.mustParseBasedTpl("post.html")
- renderPostsIndexHandler := a.renderPostsIndexHandler()
- renderEditPostHandler := a.renderEditPostHandler(false)
return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
id := strings.TrimSuffix(filepath.Base(r.URL.Path), ".html")
- if id == "/" {
- renderPostsIndexHandler.ServeHTTP(rw, r)
- return
- }
-
- if _, ok := r.URL.Query()["edit"]; ok {
- renderEditPostHandler.ServeHTTP(rw, r)
- return
- }
-
storedPost, err := a.params.PostStore.GetByID(id)
if errors.Is(err, post.ErrPostNotFound) {
@@ -171,19 +159,13 @@ func (a *api) renderPostHandler() http.Handler {
})
}
-func (a *api) renderPostsIndexHandler() http.Handler {
+func (a *api) managePostsHandler() http.Handler {
- renderEditPostHandler := a.renderEditPostHandler(false)
- tpl := a.mustParseBasedTpl("posts.html")
+ tpl := a.mustParseBasedTpl("posts-manage.html")
const pageCount = 20
return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
- if _, ok := r.URL.Query()["edit"]; ok {
- renderEditPostHandler.ServeHTTP(rw, r)
- return
- }
-
page, err := apiutil.StrToInt(r.FormValue("p"), 0)
if err != nil {
apiutil.BadRequest(
@@ -221,20 +203,26 @@ func (a *api) renderPostsIndexHandler() http.Handler {
})
}
-func (a *api) renderEditPostHandler(isDraft bool) http.Handler {
+func (a *api) editPostHandler(isDraft bool) http.Handler {
- tpl := a.mustParseBasedTpl("edit-post.html")
+ tpl := a.mustParseBasedTpl("post-edit.html")
return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
id := filepath.Base(r.URL.Path)
- var storedPost post.StoredPost
+ if id == "/" && !isDraft {
+ http.Error(rw, "Post id required", 400)
+ return
+ }
+
+ var (
+ storedPost post.StoredPost
+ err error
+ )
if id != "/" {
- var err error
-
if isDraft {
storedPost.Post, err = a.params.PostDraftStore.GetByID(id)
} else {
@@ -250,10 +238,6 @@ func (a *api) renderEditPostHandler(isDraft bool) http.Handler {
)
return
}
-
- } else if !isDraft {
- http.Error(rw, "Post ID required in URL", 400)
- return
}
tags, err := a.params.PostStore.GetTags()
@@ -348,7 +332,7 @@ func (a *api) postPostHandler() http.Handler {
return
}
- a.executeRedirectTpl(rw, r, a.postURL(p.ID, false))
+ a.executeRedirectTpl(rw, r, a.editPostURL(p.ID, false))
})
}
@@ -382,9 +366,9 @@ func (a *api) deletePostHandler(isDraft bool) http.Handler {
}
if isDraft {
- a.executeRedirectTpl(rw, r, a.draftsURL(false))
+ a.executeRedirectTpl(rw, r, a.manageDraftPostsURL(false))
} else {
- a.executeRedirectTpl(rw, r, a.postsURL(false))
+ a.executeRedirectTpl(rw, r, a.managePostsURL(false))
}
})
}