diff --git a/pkg/server/posts_api.go b/pkg/server/posts_api.go index 20153a1..9631c14 100644 --- a/pkg/server/posts_api.go +++ b/pkg/server/posts_api.go @@ -14,7 +14,7 @@ import ( ) func getPost(c *fiber.Ctx) error { - alias := c.Params("postId") + alias := c.Params("post") item, err := services.GetPostWithAlias(alias) if err != nil { @@ -226,11 +226,10 @@ func reactPost(c *fiber.Ctx) error { AccountID: user.ID, } - alias := c.Params("postId") + alias := c.Params("post") var res models.Post - - if err := database.C.Where("id = ?", alias).Select("id").First(&res).Error; err != nil { + if err := database.C.Where("alias = ?", alias).Select("id").First(&res).Error; err != nil { return fiber.NewError(fiber.StatusBadRequest, fmt.Sprintf("unable to find post to react: %v", err)) } else { reaction.PostID = &res.ID diff --git a/pkg/server/replies_api.go b/pkg/server/replies_api.go index fc20278..cc15724 100644 --- a/pkg/server/replies_api.go +++ b/pkg/server/replies_api.go @@ -14,7 +14,7 @@ func listReplies(c *fiber.Ctx) error { tx := database.C 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)) } else { tx = services.FilterPostReply(tx, post.ID) diff --git a/pkg/server/startup.go b/pkg/server/startup.go index 4dfe3df..e2c2825 100644 --- a/pkg/server/startup.go +++ b/pkg/server/startup.go @@ -68,13 +68,13 @@ func NewServer() { posts := api.Group("/posts").Name("Posts API") { posts.Get("/", listPost) - posts.Get("/:postId", getPost) + posts.Get("/:post", getPost) posts.Post("/", authMiddleware, createPost) - posts.Post("/:postId/react", authMiddleware, reactPost) + posts.Post("/:post/react", authMiddleware, reactPost) posts.Put("/:postId", authMiddleware, editPost) posts.Delete("/:postId", authMiddleware, deletePost) - posts.Get("/:postId/replies", listReplies) + posts.Get("/:post/replies", listReplies) } api.Get("/categories", listCategories)