♻️ Brand new post list

This commit is contained in:
2024-03-02 20:01:59 +08:00
parent 178f80c707
commit 3ae72cd9e0
23 changed files with 314 additions and 65 deletions

View File

@ -12,13 +12,13 @@ import (
func getOwnPost(c *fiber.Ctx) error {
user := c.Locals("principal").(models.Account)
id := c.Params("postId")
id, _ := c.ParamsInt("postId", 0)
take := c.QueryInt("take", 0)
offset := c.QueryInt("offset", 0)
tx := database.C.Where(&models.Post{
Alias: id,
AuthorID: user.ID,
BaseModel: models.BaseModel{ID: uint(id)},
AuthorID: user.ID,
})
post, err := services.GetPost(tx)

View File

@ -13,12 +13,12 @@ import (
)
func getPost(c *fiber.Ctx) error {
id := c.Params("postId")
id, _ := c.ParamsInt("postId", 0)
take := c.QueryInt("take", 0)
offset := c.QueryInt("offset", 0)
tx := database.C.Where(&models.Post{
Alias: id,
BaseModel: models.BaseModel{ID: uint(id)},
}).Where("published_at <= ? OR published_at IS NULL", time.Now())
post, err := services.GetPost(tx)
@ -162,8 +162,6 @@ func createPost(c *fiber.Ctx) error {
post, err := services.NewPost(
user,
realm,
data.Alias,
data.Title,
data.Content,
data.Attachments,
data.Categories,
@ -207,8 +205,6 @@ func editPost(c *fiber.Ctx) error {
post, err := services.EditPost(
post,
data.Alias,
data.Title,
data.Content,
data.PublishedAt,
data.Categories,

View File

@ -5,7 +5,7 @@ import (
"strings"
"time"
"code.smartsheep.studio/hydrogen/identity/pkg/views"
"code.smartsheep.studio/hydrogen/interactive/pkg/views"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cache"
"github.com/gofiber/fiber/v2/middleware/cors"