mirror of
https://github.com/Floriansylvain/RenewCMS.git
synced 2026-08-19 11:43:22 +02:00
feat: integration page #41
This commit is contained in:
@@ -18,6 +18,9 @@
|
|||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link" href="/post">Posts</a>
|
<a class="nav-link" href="/post">Posts</a>
|
||||||
</li>
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="/integration">Integration</a>
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<ul class="navbar-nav">
|
<ul class="navbar-nav">
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
|
|||||||
@@ -0,0 +1,64 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<title>GoCMS | Home</title>
|
||||||
|
{{.Head}}
|
||||||
|
</head>
|
||||||
|
<body class="text-dark">
|
||||||
|
{{.Navbar}}
|
||||||
|
<div class="container mt-3 text-black-50">
|
||||||
|
<h1>Implementation</h1>
|
||||||
|
<p>How to use headless API</p>
|
||||||
|
<div class="mt-5">
|
||||||
|
<section>
|
||||||
|
<h2>Introduction</h2>
|
||||||
|
<p>This documentation explains how to integrate our headless CMS API to retrieve post data via the <code>/post</code>
|
||||||
|
route.</p>
|
||||||
|
</section>
|
||||||
|
<section>
|
||||||
|
<h2>/v1/post</h2>
|
||||||
|
<p>The <code>{{ .Host }}/v1/post</code> route returns a list of posts in JSON format. Each post has the
|
||||||
|
following
|
||||||
|
structure:</p>
|
||||||
|
<pre>
|
||||||
|
<code>[
|
||||||
|
{
|
||||||
|
"id": 12,
|
||||||
|
"title": "This is a post!",
|
||||||
|
"body": "<p>?</p>\r\n<p><img src=\"../../static/uploadedImages/649691a8-4f2e-48ca-9abe-27a60621d2e4.png\"
|
||||||
|
alt=\"\" width=\"391\" height=\"465\"></p>",
|
||||||
|
"created_at": "2024-06-13T15:30:55.3563238+02:00",
|
||||||
|
"updated_at": "2024-06-13T15:31:17.5508931+02:00"
|
||||||
|
}
|
||||||
|
]</code>
|
||||||
|
</pre>
|
||||||
|
</section>
|
||||||
|
<section>
|
||||||
|
<h2>/v1/post/{id}</h2>
|
||||||
|
<p>The <code>{{ .Host }}/v1/post/{id}</code> route returns a single post in JSON format. The post has the
|
||||||
|
following
|
||||||
|
structure:</p>
|
||||||
|
<pre>
|
||||||
|
<code>{
|
||||||
|
"id": 12,
|
||||||
|
"title": "ravioli sans le ra et le i",
|
||||||
|
"body": "<\p>?<\/p>\r\n<\p><\img src=\"../../static/uploadedImages/649691a8-4f2e-48ca-9abe-27a60621d2e4.png\" alt=\"\"
|
||||||
|
width=\"391\" height=\"465\"><\/p>",
|
||||||
|
"images": [
|
||||||
|
{
|
||||||
|
"id": 17,
|
||||||
|
"path": "/static/uploadedImages/649691a8-4f2e-48ca-9abe-27a60621d2e4.png",
|
||||||
|
"post_id": 0,
|
||||||
|
"created_at": "2024-06-13T15:31:09.728359+02:00",
|
||||||
|
"updated_at": "2024-06-13T15:31:09.728359+02:00"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"created_at": "2024-06-13T15:30:55.3563238+02:00",
|
||||||
|
"updated_at": "2024-06-13T15:31:17.5508931+02:00"
|
||||||
|
}</code>
|
||||||
|
</pre>
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -58,6 +58,10 @@
|
|||||||
<div class="alert alert-success my-4" role="alert">
|
<div class="alert alert-success my-4" role="alert">
|
||||||
{{ .Success }}
|
{{ .Success }}
|
||||||
</div>
|
</div>
|
||||||
|
{{ else if .Failure }}
|
||||||
|
<div class="alert alert-danger my-4" role="alert">
|
||||||
|
{{ .Failure }}
|
||||||
|
</div>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -147,6 +147,8 @@ func NewPageRouter() http.Handler {
|
|||||||
r.Post("/post/create", PostPostCreatePage)
|
r.Post("/post/create", PostPostCreatePage)
|
||||||
|
|
||||||
r.Post("/post/{id}/image/create", postImage)
|
r.Post("/post/{id}/image/create", postImage)
|
||||||
|
|
||||||
|
r.Get("/integration", GetPageIntegration)
|
||||||
})
|
})
|
||||||
|
|
||||||
return r
|
return r
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package api
|
||||||
|
|
||||||
|
import (
|
||||||
|
"html/template"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetPageIntegration(w http.ResponseWriter, r *http.Request) {
|
||||||
|
navbarTmpl, _ := Container.GetPageUseCase.GetPage("componentNavbar", nil)
|
||||||
|
templ, _ := Container.GetPageUseCase.GetPage("integration", map[string]interface{}{
|
||||||
|
"Navbar": template.HTML(navbarTmpl),
|
||||||
|
"Head": headTmpl,
|
||||||
|
"Host": os.Getenv("HOST"),
|
||||||
|
})
|
||||||
|
_, _ = w.Write(templ)
|
||||||
|
}
|
||||||
@@ -32,11 +32,13 @@ func GetLoginPageHandler(loginPage *LoginPage) http.HandlerFunc {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
success, _ := url.QueryUnescape(r.URL.Query().Get("success"))
|
success, _ := url.QueryUnescape(r.URL.Query().Get("success"))
|
||||||
|
failure, _ := url.QueryUnescape(r.URL.Query().Get("failure"))
|
||||||
bs, _ := Container.GetPageUseCase.GetPage("login", map[string]interface{}{
|
bs, _ := Container.GetPageUseCase.GetPage("login", map[string]interface{}{
|
||||||
"PageError": loginPage.PageError,
|
"PageError": loginPage.PageError,
|
||||||
"Username": loginPage.Username,
|
"Username": loginPage.Username,
|
||||||
"Head": headTmpl,
|
"Head": headTmpl,
|
||||||
"Success": success,
|
"Success": success,
|
||||||
|
"Failure": failure,
|
||||||
})
|
})
|
||||||
_, _ = w.Write(bs)
|
_, _ = w.Write(bs)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,6 +30,9 @@ var EmptyRegisterPage = &RegisterPage{
|
|||||||
|
|
||||||
func GetRegisterPageHandler(registerPage *RegisterPage) http.HandlerFunc {
|
func GetRegisterPageHandler(registerPage *RegisterPage) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if !IsLoggedIn(r) && SomeUsersVerified() {
|
||||||
|
http.Redirect(w, r, "/login?failure=There is already a verified account, please login.", http.StatusSeeOther)
|
||||||
|
}
|
||||||
if (IsLoggedIn(r) && IsVerified(r)) || SomeUsersVerified() {
|
if (IsLoggedIn(r) && IsVerified(r)) || SomeUsersVerified() {
|
||||||
http.Redirect(w, r, "/home", http.StatusSeeOther)
|
http.Redirect(w, r, "/home", http.StatusSeeOther)
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user