Skip to content

Commit

Permalink
Handle submission page with a proper HTML response.
Browse files Browse the repository at this point in the history
  • Loading branch information
knadh committed Jun 19, 2022
1 parent 6fcc4e6 commit 8e0a60f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cmd/dictpress/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func initHTTPServer(app *App, ko *koanf.Koanf) *echo.Echo {
p.POST("/api/submissions/new", handleNewSubmission)
p.POST("/api/submissions/comments", handleNewComments)
p.GET("/submit", handleSubmissionPage)
p.POST("/submit", handleNewSubmission)
p.POST("/submit", handleSubmissionPage)
}

// Admin handlers and APIs.
Expand Down
17 changes: 17 additions & 0 deletions cmd/dictpress/site.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,23 @@ func handleSearchPage(c echo.Context) error {

// handleSubmissionPage renders the new entry submission page.
func handleSubmissionPage(c echo.Context) error {
if c.Request().Method == http.MethodPost {
if err := handleNewSubmission(c); err != nil {
e := err.(*echo.HTTPError)
return c.Render(e.Code, "message", pageTpl{
Title: "Error",
Heading: "Error",
Description: fmt.Sprintf("%s", e.Message),
})
}

return c.Render(http.StatusOK, "message", pageTpl{
Title: "Submitted",
Heading: "Submitted",
Description: "Your entry has been submitted for review.",
})
}

return c.Render(http.StatusOK, "submit-entry", pageTpl{
Title: "Submit a new entry",
})
Expand Down

0 comments on commit 8e0a60f

Please sign in to comment.