✨ Manually active boost api
This commit is contained in:
@ -78,6 +78,24 @@ func createBoost(c *fiber.Ctx) error {
|
||||
}
|
||||
}
|
||||
|
||||
func activateBoost(c *fiber.Ctx) error {
|
||||
user := c.Locals("nex_user").(*sec.UserInfo)
|
||||
boostId, _ := c.ParamsInt("boostId", 0)
|
||||
|
||||
boost, err := services.GetBoostByID(uint(boostId))
|
||||
if err != nil {
|
||||
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
||||
} else if boost.AccountID != user.ID {
|
||||
return fiber.NewError(fiber.StatusNotFound, "record not created by you")
|
||||
}
|
||||
|
||||
if err := services.ActivateBoost(boost); err != nil {
|
||||
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
||||
} else {
|
||||
return c.JSON(boost)
|
||||
}
|
||||
}
|
||||
|
||||
func updateBoost(c *fiber.Ctx) error {
|
||||
user := c.Locals("nex_user").(*sec.UserInfo)
|
||||
boostId, _ := c.ParamsInt("boostId", 0)
|
||||
|
@ -13,9 +13,10 @@ func MapAPIs(app *fiber.App, baseURL string) {
|
||||
boost := api.Group("/boosts").Name("Boosts API")
|
||||
{
|
||||
boost.Get("/", listBoostByUser)
|
||||
boost.Get("/:id", getBoost)
|
||||
boost.Get("/:boostId", getBoost)
|
||||
boost.Post("/", sec.ValidatorMiddleware, createBoost)
|
||||
boost.Put("/:id", sec.ValidatorMiddleware, updateBoost)
|
||||
boost.Post("/:boostId/activate", sec.ValidatorMiddleware, activateBoost)
|
||||
boost.Put("/:boostId", sec.ValidatorMiddleware, updateBoost)
|
||||
}
|
||||
|
||||
pools := api.Group("/pools").Name("Pools API")
|
||||
|
Reference in New Issue
Block a user