🐛 Bug fixes thought postId is alias
This commit is contained in:
parent
4b8bc3e09b
commit
d75131cab4
@ -14,7 +14,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func getPost(c *fiber.Ctx) error {
|
func getPost(c *fiber.Ctx) error {
|
||||||
alias := c.Params("postId")
|
alias := c.Params("post")
|
||||||
|
|
||||||
item, err := services.GetPostWithAlias(alias)
|
item, err := services.GetPostWithAlias(alias)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -226,11 +226,10 @@ func reactPost(c *fiber.Ctx) error {
|
|||||||
AccountID: user.ID,
|
AccountID: user.ID,
|
||||||
}
|
}
|
||||||
|
|
||||||
alias := c.Params("postId")
|
alias := c.Params("post")
|
||||||
|
|
||||||
var res models.Post
|
var res models.Post
|
||||||
|
if err := database.C.Where("alias = ?", alias).Select("id").First(&res).Error; err != nil {
|
||||||
if err := database.C.Where("id = ?", alias).Select("id").First(&res).Error; err != nil {
|
|
||||||
return fiber.NewError(fiber.StatusBadRequest, fmt.Sprintf("unable to find post to react: %v", err))
|
return fiber.NewError(fiber.StatusBadRequest, fmt.Sprintf("unable to find post to react: %v", err))
|
||||||
} else {
|
} else {
|
||||||
reaction.PostID = &res.ID
|
reaction.PostID = &res.ID
|
||||||
|
@ -14,7 +14,7 @@ func listReplies(c *fiber.Ctx) error {
|
|||||||
|
|
||||||
tx := database.C
|
tx := database.C
|
||||||
var post models.Post
|
var post models.Post
|
||||||
if err := database.C.Where("alias = ?", c.Params("postId")).First(&post).Error; err != nil {
|
if err := database.C.Where("alias = ?", c.Params("post")).First(&post).Error; err != nil {
|
||||||
return fiber.NewError(fiber.StatusBadRequest, fmt.Sprintf("unable to find post: %v", err))
|
return fiber.NewError(fiber.StatusBadRequest, fmt.Sprintf("unable to find post: %v", err))
|
||||||
} else {
|
} else {
|
||||||
tx = services.FilterPostReply(tx, post.ID)
|
tx = services.FilterPostReply(tx, post.ID)
|
||||||
|
@ -68,13 +68,13 @@ func NewServer() {
|
|||||||
posts := api.Group("/posts").Name("Posts API")
|
posts := api.Group("/posts").Name("Posts API")
|
||||||
{
|
{
|
||||||
posts.Get("/", listPost)
|
posts.Get("/", listPost)
|
||||||
posts.Get("/:postId", getPost)
|
posts.Get("/:post", getPost)
|
||||||
posts.Post("/", authMiddleware, createPost)
|
posts.Post("/", authMiddleware, createPost)
|
||||||
posts.Post("/:postId/react", authMiddleware, reactPost)
|
posts.Post("/:post/react", authMiddleware, reactPost)
|
||||||
posts.Put("/:postId", authMiddleware, editPost)
|
posts.Put("/:postId", authMiddleware, editPost)
|
||||||
posts.Delete("/:postId", authMiddleware, deletePost)
|
posts.Delete("/:postId", authMiddleware, deletePost)
|
||||||
|
|
||||||
posts.Get("/:postId/replies", listReplies)
|
posts.Get("/:post/replies", listReplies)
|
||||||
}
|
}
|
||||||
|
|
||||||
api.Get("/categories", listCategories)
|
api.Get("/categories", listCategories)
|
||||||
|
Loading…
Reference in New Issue
Block a user