mirror of
https://github.com/Floriansylvain/RenewCMS.git
synced 2026-08-19 19:53:21 +02:00
refac: renamed 'post' -> 'article'
This commit is contained in:
@@ -0,0 +1,140 @@
|
||||
package gateways
|
||||
|
||||
import (
|
||||
entity "GoCMS/adapters/secondary/gateways/models"
|
||||
domain "GoCMS/domain/article"
|
||||
"GoCMS/domain/gateways"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type ArticleRepository struct {
|
||||
db *gorm.DB
|
||||
}
|
||||
|
||||
func NewArticleRepository(db *gorm.DB) *ArticleRepository {
|
||||
return &ArticleRepository{db}
|
||||
}
|
||||
|
||||
func mapArticleToDomain(article entity.Article) domain.Article {
|
||||
return domain.FromDb(article.ID, article.Title, article.Body, article.Images, article.IsOnline, article.CreatedAt, article.UpdatedAt)
|
||||
}
|
||||
|
||||
func (a *ArticleRepository) Get(id uint32) (domain.Article, error) {
|
||||
var article entity.Article
|
||||
err := a.db.Model(&entity.Article{}).Preload("Images").First(&article, id).Error
|
||||
if err != nil {
|
||||
return domain.Article{}, err
|
||||
}
|
||||
|
||||
return mapArticleToDomain(article), nil
|
||||
}
|
||||
|
||||
func (a *ArticleRepository) GetByName(name string) (domain.Article, error) {
|
||||
var article entity.Article
|
||||
err := a.db.Model(&entity.Article{}).Where("title = ?", name).First(&article).Error
|
||||
if err != nil {
|
||||
return domain.Article{}, err
|
||||
}
|
||||
|
||||
return mapArticleToDomain(article), nil
|
||||
}
|
||||
|
||||
func (a *ArticleRepository) Create(article domain.Article) (domain.Article, error) {
|
||||
creationResult := a.db.Create(&entity.Article{
|
||||
Title: article.Title,
|
||||
Body: article.Body,
|
||||
})
|
||||
if creationResult.Error != nil {
|
||||
return domain.Article{}, creationResult.Error
|
||||
}
|
||||
|
||||
var createdArticle entity.Article
|
||||
creationResult.Scan(&createdArticle)
|
||||
|
||||
return mapArticleToDomain(createdArticle), nil
|
||||
}
|
||||
|
||||
func (a *ArticleRepository) GetAll() []domain.Article {
|
||||
var articles []entity.Article
|
||||
err := a.db.Model(&entity.Article{}).Find(&articles).Error
|
||||
if err != nil {
|
||||
return []domain.Article{}
|
||||
}
|
||||
|
||||
var domainArticles = make([]domain.Article, 0)
|
||||
for _, article := range articles {
|
||||
domainArticles = append(domainArticles, mapArticleToDomain(article))
|
||||
}
|
||||
|
||||
return domainArticles
|
||||
}
|
||||
|
||||
func (a *ArticleRepository) UpdateBody(id uint32, body string) (domain.Article, error) {
|
||||
var localArticle entity.Article
|
||||
err := a.db.Model(&entity.Article{}).First(&localArticle, id).Error
|
||||
if err != nil {
|
||||
return domain.Article{}, err
|
||||
}
|
||||
|
||||
localArticle.Body = body
|
||||
err = a.db.Save(&localArticle).Error
|
||||
if err != nil {
|
||||
return domain.Article{}, err
|
||||
}
|
||||
|
||||
newArticle := domain.FromDb(
|
||||
localArticle.ID,
|
||||
localArticle.Title,
|
||||
localArticle.Body,
|
||||
localArticle.Images,
|
||||
localArticle.IsOnline,
|
||||
localArticle.CreatedAt,
|
||||
localArticle.UpdatedAt,
|
||||
)
|
||||
|
||||
return newArticle, nil
|
||||
}
|
||||
|
||||
func (a *ArticleRepository) UpdateIsOnline(id uint32, isOnline bool) (domain.Article, error) {
|
||||
var localArticle entity.Article
|
||||
err := a.db.Model(&entity.Article{}).First(&localArticle, id).Error
|
||||
if err != nil {
|
||||
return domain.Article{}, err
|
||||
}
|
||||
|
||||
localArticle.IsOnline = isOnline
|
||||
err = a.db.Save(&localArticle).Error
|
||||
if err != nil {
|
||||
return domain.Article{}, err
|
||||
}
|
||||
|
||||
return mapArticleToDomain(localArticle), nil
|
||||
}
|
||||
|
||||
func (a *ArticleRepository) Delete(id uint32) error {
|
||||
return a.db.Delete(&entity.Article{}, id).Error
|
||||
}
|
||||
|
||||
func (a *ArticleRepository) AddImage(articleId uint32, imageId uint32) error {
|
||||
var localArticle entity.Article
|
||||
err := a.db.Model(&entity.Article{}).First(&localArticle, articleId).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var localImage entity.Image
|
||||
err = a.db.Model(&entity.Image{}).First(&localImage, imageId).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = a.db.Model(&localArticle).Association("Images").Append(&localImage)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
var _ gateways.IArticleRepository = &ArticleRepository{}
|
||||
@@ -30,7 +30,7 @@ func mapImageToDomain(image entity.Image) domain.Image {
|
||||
return domain.FromDB(
|
||||
image.ID,
|
||||
image.Path,
|
||||
image.PostID,
|
||||
image.ArticleID,
|
||||
image.CreatedAt,
|
||||
image.UpdatedAt,
|
||||
)
|
||||
|
||||
+4
-3
@@ -1,16 +1,17 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type Post struct {
|
||||
type Article struct {
|
||||
gorm.Model
|
||||
ID uint32 `gorm:"primary_key;auto_increment;not_null"`
|
||||
Title string
|
||||
Body string
|
||||
Images []*Image `gorm:"many2many:post_images;"`
|
||||
Images []*Image `gorm:"many2many:article_images;"`
|
||||
IsOnline bool `gorm:"not_null;default:false"`
|
||||
CreatedAt time.Time `gorm:"autoCreateTime"`
|
||||
UpdatedAt time.Time `gorm:"autoUpdateTime"`
|
||||
@@ -1,15 +1,16 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type Image struct {
|
||||
gorm.Model
|
||||
ID uint32 `gorm:"primary_key;auto_increment;not_null"`
|
||||
Path string
|
||||
PostID uint32
|
||||
ArticleID uint32
|
||||
CreatedAt time.Time `gorm:"autoCreateTime"`
|
||||
UpdatedAt time.Time `gorm:"autoUpdateTime"`
|
||||
}
|
||||
|
||||
@@ -1,139 +0,0 @@
|
||||
package gateways
|
||||
|
||||
import (
|
||||
entity "GoCMS/adapters/secondary/gateways/models"
|
||||
"GoCMS/domain/gateways"
|
||||
domain "GoCMS/domain/post"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type PostRepository struct {
|
||||
db *gorm.DB
|
||||
}
|
||||
|
||||
func NewPostRepository(db *gorm.DB) *PostRepository {
|
||||
return &PostRepository{db}
|
||||
}
|
||||
|
||||
func mapPostToDomain(post entity.Post) domain.Post {
|
||||
return domain.FromDb(post.ID, post.Title, post.Body, post.Images, post.IsOnline, post.CreatedAt, post.UpdatedAt)
|
||||
}
|
||||
|
||||
func (a *PostRepository) Get(id uint32) (domain.Post, error) {
|
||||
var post entity.Post
|
||||
err := a.db.Model(&entity.Post{}).Preload("Images").First(&post, id).Error
|
||||
if err != nil {
|
||||
return domain.Post{}, err
|
||||
}
|
||||
|
||||
return mapPostToDomain(post), nil
|
||||
}
|
||||
|
||||
func (a *PostRepository) GetByName(name string) (domain.Post, error) {
|
||||
var post entity.Post
|
||||
err := a.db.Model(&entity.Post{}).Where("title = ?", name).First(&post).Error
|
||||
if err != nil {
|
||||
return domain.Post{}, err
|
||||
}
|
||||
|
||||
return mapPostToDomain(post), nil
|
||||
}
|
||||
|
||||
func (a *PostRepository) Create(post domain.Post) (domain.Post, error) {
|
||||
creationResult := a.db.Create(&entity.Post{
|
||||
Title: post.Title,
|
||||
Body: post.Body,
|
||||
})
|
||||
if creationResult.Error != nil {
|
||||
return domain.Post{}, creationResult.Error
|
||||
}
|
||||
|
||||
var createdPost entity.Post
|
||||
creationResult.Scan(&createdPost)
|
||||
|
||||
return mapPostToDomain(createdPost), nil
|
||||
}
|
||||
|
||||
func (a *PostRepository) GetAll() []domain.Post {
|
||||
var posts []entity.Post
|
||||
err := a.db.Model(&entity.Post{}).Find(&posts).Error
|
||||
if err != nil {
|
||||
return []domain.Post{}
|
||||
}
|
||||
|
||||
var domainPosts = make([]domain.Post, 0)
|
||||
for _, post := range posts {
|
||||
domainPosts = append(domainPosts, mapPostToDomain(post))
|
||||
}
|
||||
|
||||
return domainPosts
|
||||
}
|
||||
|
||||
func (a *PostRepository) UpdateBody(id uint32, body string) (domain.Post, error) {
|
||||
var localPost entity.Post
|
||||
err := a.db.Model(&entity.Post{}).First(&localPost, id).Error
|
||||
if err != nil {
|
||||
return domain.Post{}, err
|
||||
}
|
||||
|
||||
localPost.Body = body
|
||||
err = a.db.Save(&localPost).Error
|
||||
if err != nil {
|
||||
return domain.Post{}, err
|
||||
}
|
||||
|
||||
newPost := domain.FromDb(
|
||||
localPost.ID,
|
||||
localPost.Title,
|
||||
localPost.Body,
|
||||
localPost.Images,
|
||||
localPost.IsOnline,
|
||||
localPost.CreatedAt,
|
||||
localPost.UpdatedAt,
|
||||
)
|
||||
|
||||
return newPost, nil
|
||||
}
|
||||
|
||||
func (a *PostRepository) UpdateIsOnline(id uint32, isOnline bool) (domain.Post, error) {
|
||||
var localPost entity.Post
|
||||
err := a.db.Model(&entity.Post{}).First(&localPost, id).Error
|
||||
if err != nil {
|
||||
return domain.Post{}, err
|
||||
}
|
||||
|
||||
localPost.IsOnline = isOnline
|
||||
err = a.db.Save(&localPost).Error
|
||||
if err != nil {
|
||||
return domain.Post{}, err
|
||||
}
|
||||
|
||||
return mapPostToDomain(localPost), nil
|
||||
}
|
||||
|
||||
func (a *PostRepository) Delete(id uint32) error {
|
||||
return a.db.Delete(&entity.Post{}, id).Error
|
||||
}
|
||||
|
||||
func (a *PostRepository) AddImage(postId uint32, imageId uint32) error {
|
||||
var localPost entity.Post
|
||||
err := a.db.Model(&entity.Post{}).First(&localPost, postId).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var localImage entity.Image
|
||||
err = a.db.Model(&entity.Image{}).First(&localImage, imageId).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = a.db.Model(&localPost).Association("Images").Append(&localImage)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
var _ gateways.IPostRepository = &PostRepository{}
|
||||
+14
-14
@@ -1,7 +1,7 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>GoCMS | Create post</title>
|
||||
<title>GoCMS | Create article</title>
|
||||
{{.Head}}
|
||||
<style>
|
||||
form {
|
||||
@@ -12,27 +12,27 @@
|
||||
<body class="text-dark">
|
||||
{{.Navbar}}
|
||||
<div class="container mt-3 text-black-50">
|
||||
<h1>Post - creation</h1>
|
||||
<p>Create a new post</p>
|
||||
<form action="create" method="post" class="d-flex align-items-center flex-column gap-3" id="createPostForm">
|
||||
<h1>Article - creation</h1>
|
||||
<p>Create a new article</p>
|
||||
<form action="create" method="post" class="d-flex align-items-center flex-column gap-3" id="createArticleForm">
|
||||
<div class="form-floating w-100">
|
||||
<input type="text" class="form-control {{ if .PageError.IsError }} is-invalid {{ end }}" id="name"
|
||||
name="name" placeholder="Chose the post name" value="{{ .Name }}">
|
||||
name="name" placeholder="Chose the article name" value="{{ .Name }}">
|
||||
<label for="name">Name</label>
|
||||
<div class="invalid-feedback">{{ .PageError.Message }}</div>
|
||||
</div>
|
||||
<button id="createPostButton" class="btn btn-primary w-100" disabled type="submit">
|
||||
<span class="createPostFormButtonLoading visually-hidden spinner-border spinner-border-sm"
|
||||
<button id="createArticleButton" class="btn btn-primary w-100" disabled type="submit">
|
||||
<span class="createArticleFormButtonLoading visually-hidden spinner-border spinner-border-sm"
|
||||
role="status"></span>
|
||||
<span class="createPostFormButtonDefault">Create</span>
|
||||
<span class="createArticleFormButtonDefault">Create</span>
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const button = document.querySelector("#createPostButton")
|
||||
const button = document.querySelector("#createArticleButton")
|
||||
const inputs = document.querySelectorAll('input')
|
||||
const form = document.querySelector("#createPostForm")
|
||||
const form = document.querySelector("#createArticleForm")
|
||||
|
||||
function formFieldsEmpty() {
|
||||
return Array.from(inputs).some((input) => input.value === "")
|
||||
@@ -44,11 +44,11 @@
|
||||
|
||||
function setButtonLoading() {
|
||||
button.classList.add("disabled")
|
||||
button.querySelector(".createPostFormButtonDefault").classList.add("visually-hidden")
|
||||
button.querySelector(".createPostFormButtonLoading").classList.remove("visually-hidden")
|
||||
button.querySelector(".createArticleFormButtonDefault").classList.add("visually-hidden")
|
||||
button.querySelector(".createArticleFormButtonLoading").classList.remove("visually-hidden")
|
||||
}
|
||||
|
||||
function onCreatePostFormSubmit(event) {
|
||||
function onCreateArticleFormSubmit(event) {
|
||||
setButtonLoading()
|
||||
event.target.submit()
|
||||
}
|
||||
@@ -57,7 +57,7 @@
|
||||
if (event.target.tagName === "INPUT") setButtonDisabled()
|
||||
}
|
||||
|
||||
form.addEventListener('submit', onCreatePostFormSubmit)
|
||||
form.addEventListener('submit', onCreateArticleFormSubmit)
|
||||
window.addEventListener('input', onInput)
|
||||
setButtonDisabled()
|
||||
</script>
|
||||
+6
-6
@@ -1,7 +1,7 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>GoCMS | Post edition</title>
|
||||
<title>GoCMS | Article edition</title>
|
||||
{{.Head}}
|
||||
</head>
|
||||
<body class="text-dark vh-100 d-flex flex-column">
|
||||
@@ -9,8 +9,8 @@
|
||||
<form class="container mt-3 text-black-50 d-flex flex-column h-100" action="edit" method="post">
|
||||
<div class="d-flex align-items-center justify-content-between">
|
||||
<div>
|
||||
<h1>Post - edition</h1>
|
||||
<label for="postBody">Edition</label>
|
||||
<h1>Article - edition</h1>
|
||||
<label for="articleBody">Edition</label>
|
||||
</div>
|
||||
{{ if .Alert.Message }}
|
||||
<div class="alert {{ if .Alert.IsError }} alert-danger {{ else }} alert-success {{ end }} alert-dismissible"
|
||||
@@ -30,14 +30,14 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="text-black-50 d-flex align-items-center justify-content-center h-100 py-3">
|
||||
<textarea id="postBody" name="postBody">{{.Post.Body}}</textarea>
|
||||
<textarea id="articleBody" name="articleBody">{{.Article.Body}}</textarea>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<script src="/static/tinymce/js/tinymce/tinymce.min.js"></script>
|
||||
<script>
|
||||
tinymce.init({
|
||||
selector: '#postBody',
|
||||
selector: '#articleBody',
|
||||
promotion: false,
|
||||
plugins: 'image lists visualblocks',
|
||||
toolbar: 'undo redo | formatselect | bold italic underline strikethrough | alignleft aligncenter alignright alignjustify | bullist numlist | outdent indent | removeformat | image',
|
||||
@@ -52,7 +52,7 @@
|
||||
images_upload_handler: (blobInfo, progress) => new Promise((resolve, reject) => {
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.withCredentials = false;
|
||||
xhr.open('POST', "/post/{{.Post.ID}}/image/create");
|
||||
xhr.open('POST', "/article/{{.Article.ID}}/image/create");
|
||||
|
||||
xhr.upload.onprogress = (e) => {
|
||||
progress(e.loaded / e.total * 100);
|
||||
+20
-20
@@ -1,7 +1,7 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>GoCMS | Posts</title>
|
||||
<title>GoCMS | Articles</title>
|
||||
{{.Head}}
|
||||
|
||||
<style>
|
||||
@@ -15,8 +15,8 @@
|
||||
<body class="text-dark">
|
||||
{{.Navbar}}
|
||||
<div class="container mt-3 text-black-50">
|
||||
<h1>Posts</h1>
|
||||
<p>List of your posts</p>
|
||||
<h1>Articles</h1>
|
||||
<p>List of your articles</p>
|
||||
<table class="table table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
@@ -30,59 +30,59 @@
|
||||
<tbody>
|
||||
<tr>
|
||||
<td colspan="5" class="text-center">
|
||||
<form action="post/create" method="get">
|
||||
<button class="btn btn-sm btn-link w-100 h-100" type="submit">Create a new post...</button>
|
||||
<form action="article/create" method="get">
|
||||
<button class="btn btn-sm btn-link w-100 h-100" type="submit">Create a new article...</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
{{ range $post := .Posts }}
|
||||
{{ range $article := .Articles }}
|
||||
<tr>
|
||||
<td>{{ $post.Title }}</td>
|
||||
<td class="date">{{ $post.CreatedAt }}</td>
|
||||
<td class="date">{{ $post.UpdatedAt }}</td>
|
||||
<td>{{ if $post.IsOnline }}🟢 Online{{ else }}🟠 Offline{{ end }}</td>
|
||||
<td>{{ $article.Title }}</td>
|
||||
<td class="date">{{ $article.CreatedAt }}</td>
|
||||
<td class="date">{{ $article.UpdatedAt }}</td>
|
||||
<td>{{ if $article.IsOnline }}🟢 Online{{ else }}🟠 Offline{{ end }}</td>
|
||||
<td>
|
||||
<a href="/post/{{ $post.ID }}/edit" class="btn btn-outline-primary btn-sm">
|
||||
<a href="/article/{{ $article.ID }}/edit" class="btn btn-outline-primary btn-sm">
|
||||
<svg width="12px" height="12px" fill="currentColor">
|
||||
<use xlink:href="/static/bootstrap-icons.svg#pen"/>
|
||||
</svg>
|
||||
</a>
|
||||
{{ if $post.IsOnline }}
|
||||
<a href="/post/{{ $post.ID }}/unpublish" class="btn btn-outline-info btn-sm">
|
||||
{{ if $article.IsOnline }}
|
||||
<a href="/article/{{ $article.ID }}/unpublish" class="btn btn-outline-info btn-sm">
|
||||
<svg width="12px" height="12px" fill="currentColor">
|
||||
<use xlink:href="/static/bootstrap-icons.svg#eye-slash"/>
|
||||
</svg>
|
||||
</a>
|
||||
{{ else }}
|
||||
<a href="/post/{{ $post.ID }}/publish" class="btn btn-outline-info btn-sm">
|
||||
<a href="/article/{{ $article.ID }}/publish" class="btn btn-outline-info btn-sm">
|
||||
<svg width="12px" height="12px" fill="currentColor">
|
||||
<use xlink:href="/static/bootstrap-icons.svg#eye"/>
|
||||
</svg>
|
||||
</a>
|
||||
{{ end }}
|
||||
<a href="/post/{{ $post.Title }}/delete" class="btn btn-outline-danger btn-sm" data-bs-toggle="modal"
|
||||
data-bs-target="#{{ $post.ID }}">
|
||||
<a href="/article/{{ $article.Title }}/delete" class="btn btn-outline-danger btn-sm" data-bs-toggle="modal"
|
||||
data-bs-target="#{{ $article.ID }}">
|
||||
<svg width=" 12px" height="12px" fill="currentColor">
|
||||
<use xlink:href="/static/bootstrap-icons.svg#trash"/>
|
||||
</svg>
|
||||
</a>
|
||||
<div class="modal fade" id="{{ $post.ID }}" tabindex="-1" aria-labelledby="{{ $post.ID }}Label"
|
||||
<div class="modal fade" id="{{ $article.ID }}" tabindex="-1" aria-labelledby="{{ $article.ID }}Label"
|
||||
aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h1 class="modal-title fs-5" id="{{ $post.ID }}Label">Delete post</h1>
|
||||
<h1 class="modal-title fs-5" id="{{ $article.ID }}Label">Delete post</h1>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal"
|
||||
aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<p>You are about to delete the post <b>« {{ $post.Title }} »</b>, this is definitive,
|
||||
<p>You are about to delete the post <b>« {{ $article.Title }} »</b>, this is definitive,
|
||||
are you sure?</p>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-outline-secondary" data-bs-dismiss="modal">Cancel
|
||||
</button>
|
||||
<a href="/post/{{$post.ID}}/delete" class="btn btn-danger">Delete</a>
|
||||
<a href="/article/{{$article.ID}}/delete" class="btn btn-danger">Delete</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -16,7 +16,7 @@
|
||||
<a class="nav-link" href="/home">Home</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="/post">Posts</a>
|
||||
<a class="nav-link" href="/article">Articles</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="/integration">Integration</a>
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
<div class="container mt-3 text-black-50">
|
||||
<h1>Home</h1>
|
||||
<p>Welcome on GoCMS !</p>
|
||||
<a href="/post">
|
||||
<button class="btn btn-outline-primary">Posts »</button>
|
||||
<a href="/article">
|
||||
<button class="btn btn-outline-primary">Articles »</button>
|
||||
</a>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
@@ -12,19 +12,19 @@
|
||||
<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>
|
||||
<p>This documentation explains how to integrate our headless CMS API to retrieve article data via the <code>/article</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
|
||||
<h2>/v1/article</h2>
|
||||
<p>The <code>{{ .Host }}/v1/article</code> route returns a list of articles in JSON format. Each article has the
|
||||
following
|
||||
structure:</p>
|
||||
<pre>
|
||||
<code>[
|
||||
{
|
||||
"id": 12,
|
||||
"title": "This is a post!",
|
||||
"title": "This is a article!",
|
||||
"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",
|
||||
@@ -34,21 +34,21 @@
|
||||
</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
|
||||
<h2>/v1/article/{id}</h2>
|
||||
<p>The <code>{{ .Host }}/v1/article/{id}</code> route returns a single article in JSON format. The article has the
|
||||
following
|
||||
structure:</p>
|
||||
<pre>
|
||||
<code>{
|
||||
"id": 12,
|
||||
"title": "ravioli sans le ra et le i",
|
||||
"title": "ravioli",
|
||||
"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,
|
||||
"article_id": 0,
|
||||
"created_at": "2024-06-13T15:31:09.728359+02:00",
|
||||
"updated_at": "2024-06-13T15:31:09.728359+02:00"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user