mirror of
https://github.com/Floriansylvain/RenewCMS.git
synced 2026-08-19 11:43:22 +02:00
refac: separated api content into sub-packages & renamed usecases
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
package pages
|
||||
|
||||
import (
|
||||
"GoCMS/api"
|
||||
"html/template"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func GetPostsPage(w http.ResponseWriter, _ *http.Request) {
|
||||
posts := api.Container.ListPostsUseCase.ListPosts()
|
||||
|
||||
var formattedPosts []map[string]interface{}
|
||||
for _, post := range posts {
|
||||
formattedPosts = append(formattedPosts, map[string]interface{}{
|
||||
"ID": post.ID,
|
||||
"Title": post.Title,
|
||||
"IsOnline": post.IsOnline,
|
||||
"CreatedAt": post.CreatedAt.Format("2006-01-02 15:04:05"),
|
||||
"UpdatedAt": post.UpdatedAt.Format("2006-01-02 15:04:05"),
|
||||
})
|
||||
}
|
||||
|
||||
navbarTmpl, _ := api.Container.GetPageUseCase.GetPage("componentNavbar", nil)
|
||||
postsTmpl, _ := api.Container.GetPageUseCase.GetPage("posts", map[string]interface{}{
|
||||
"Navbar": template.HTML(navbarTmpl),
|
||||
"Head": headTmpl,
|
||||
"Posts": formattedPosts,
|
||||
})
|
||||
|
||||
_, _ = w.Write(postsTmpl)
|
||||
}
|
||||
Reference in New Issue
Block a user