From 24eefb743b760e3243eea846e9484a9a5f99fc21 Mon Sep 17 00:00:00 2001 From: Florian Sylvain Date: Thu, 16 May 2024 19:30:33 +0200 Subject: [PATCH] feat: post creation WIP --- .air.toml | 51 +++++++++++++++ .gitignore | 4 +- .../gateways/web/templates/postCreate.html | 65 +++++++++++++++++++ .../gateways/web/templates/posts.html | 42 +++++++++--- api/page.go | 2 + api/pagePostCreate.go | 29 +++++++++ 6 files changed, 182 insertions(+), 11 deletions(-) create mode 100644 .air.toml create mode 100644 adapters/secondary/gateways/web/templates/postCreate.html create mode 100644 api/pagePostCreate.go diff --git a/.air.toml b/.air.toml new file mode 100644 index 0000000..67b1383 --- /dev/null +++ b/.air.toml @@ -0,0 +1,51 @@ +root = "." +testdata_dir = "testdata" +tmp_dir = "tmp" + +[build] + args_bin = [] + bin = "tmp\\main.exe" + cmd = "go build -o ./tmp/main.exe ./main" + delay = 1000 + exclude_dir = ["assets", "tmp", "vendor", "testdata"] + exclude_file = [] + exclude_regex = ["_test.go"] + exclude_unchanged = false + follow_symlink = false + full_bin = "" + include_dir = [] + include_ext = ["go", "tpl", "tmpl", "html"] + include_file = [] + kill_delay = "0s" + log = "build-errors.log" + poll = false + poll_interval = 0 + post_cmd = [] + pre_cmd = [] + rerun = false + rerun_delay = 500 + send_interrupt = false + stop_on_error = false + +[color] + app = "" + build = "yellow" + main = "magenta" + runner = "green" + watcher = "cyan" + +[log] + main_only = false + time = false + +[misc] + clean_on_exit = false + +[proxy] + app_port = 0 + enabled = false + proxy_port = 0 + +[screen] + clear_on_rebuild = false + keep_scroll = true diff --git a/.gitignore b/.gitignore index 0653454..449aa10 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,6 @@ bin # Environment -.env \ No newline at end of file +.env + +tmp/ diff --git a/adapters/secondary/gateways/web/templates/postCreate.html b/adapters/secondary/gateways/web/templates/postCreate.html new file mode 100644 index 0000000..cbb213b --- /dev/null +++ b/adapters/secondary/gateways/web/templates/postCreate.html @@ -0,0 +1,65 @@ + + + + GoCMS | Create post + {{.Head}} + + + + +{{.Navbar}} +
+

Post - creation

+

Create a new post

+
+
+ + +
+ +
+
+ + + + + diff --git a/adapters/secondary/gateways/web/templates/posts.html b/adapters/secondary/gateways/web/templates/posts.html index 9603a2c..7b2e2c6 100644 --- a/adapters/secondary/gateways/web/templates/posts.html +++ b/adapters/secondary/gateways/web/templates/posts.html @@ -1,20 +1,42 @@ - GoCMS | Posts - {{.Head}} + GoCMS | Posts + {{.Head}} + + {{.Navbar}}
-

Posts

-

List of your posts

- - - - - -
+

Posts

+

List of your posts

+ + + + + + + + + + + + + + + + + + + + +
NameCreation DateEdition DateActions
+
+ +
+
1MarkOtto@mdo
diff --git a/api/page.go b/api/page.go index 0dfe53a..5ef3f5b 100644 --- a/api/page.go +++ b/api/page.go @@ -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 diff --git a/api/pagePostCreate.go b/api/pagePostCreate.go new file mode 100644 index 0000000..68051e8 --- /dev/null +++ b/api/pagePostCreate.go @@ -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) +}