mirror of
https://github.com/Floriansylvain/RenewCMS.git
synced 2026-08-19 11:43:22 +02:00
feat: post creation WIP
This commit is contained in:
@@ -123,6 +123,8 @@ func NewPageRouter() http.Handler {
|
||||
r.Get("/home", GetHomePage)
|
||||
r.Get("/post", GetPostsPage)
|
||||
r.Get("/post/edit", GetPostEditPage)
|
||||
r.Get("/post/create", GetPostCreatePage)
|
||||
r.Post("/post/create", PostPostCreatePage)
|
||||
})
|
||||
|
||||
return r
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"html/template"
|
||||
"net/http"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
func PostPostCreatePage(w http.ResponseWriter, r *http.Request) {
|
||||
_ = r.ParseForm()
|
||||
|
||||
postName := r.FormValue("name")
|
||||
pattern := regexp.MustCompile("^[a-zA-Z0-9]{3,50}$")
|
||||
|
||||
isPostNameValid := pattern.MatchString(postName)
|
||||
if !isPostNameValid {
|
||||
r.Method = http.MethodGet
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
func GetPostCreatePage(w http.ResponseWriter, _ *http.Request) {
|
||||
navbarTmpl, _ := Container.GetPageUseCase.GetPage("componentNavbar", nil)
|
||||
postsTmpl, _ := Container.GetPageUseCase.GetPage("postCreate", map[string]interface{}{
|
||||
"Navbar": template.HTML(navbarTmpl),
|
||||
"Head": headTmpl,
|
||||
})
|
||||
_, _ = w.Write(postsTmpl)
|
||||
}
|
||||
Reference in New Issue
Block a user