style: chained function line breaks

This commit is contained in:
Reinaldy Rafli 2021-08-04 17:14:33 +07:00
parent e38f36c579
commit b6788b33c6
7 changed files with 102 additions and 46 deletions

View File

@ -24,12 +24,18 @@ func AddNewJoke(c *fiber.Ctx) error {
} }
if !valid { if !valid {
return c.Status(fiber.StatusBadRequest).JSON(models.Error{ return c.
Error: "URL provided is not a valid image", Status(fiber.StatusBadRequest).
}) JSON(models.Error{
Error: "URL provided is not a valid image",
})
} }
sql, args, err := handler.Psql.Insert("jokesbapak2").Columns("link", "creator").Values(body.Link, c.Locals("userID")).ToSql() sql, args, err := handler.Psql.
Insert("jokesbapak2").
Columns("link", "creator").
Values(body.Link, c.Locals("userID")).
ToSql()
if err != nil { if err != nil {
return err return err
} }
@ -51,7 +57,9 @@ func AddNewJoke(c *fiber.Ctx) error {
return err return err
} }
return c.Status(fiber.StatusCreated).JSON(models.ResponseJoke{ return c.
Link: body.Link, Status(fiber.StatusCreated).
}) JSON(models.ResponseJoke{
Link: body.Link,
})
} }

View File

@ -19,7 +19,11 @@ func DeleteJoke(c *fiber.Ctx) error {
} }
// Check if the joke exists // Check if the joke exists
sql, args, err := handler.Psql.Select("id").From("jokesbapak2").Where(squirrel.Eq{"id": id}).ToSql() sql, args, err := handler.Psql.
Select("id").
From("jokesbapak2").
Where(squirrel.Eq{"id": id}).
ToSql()
if err != nil { if err != nil {
return err return err
} }
@ -31,7 +35,10 @@ func DeleteJoke(c *fiber.Ctx) error {
} }
if jokeID == id { if jokeID == id {
sql, args, err = handler.Psql.Delete("jokesbapak2").Where(squirrel.Eq{"id": id}).ToSql() sql, args, err = handler.Psql.
Delete("jokesbapak2").
Where(squirrel.Eq{"id": id}).
ToSql()
if err != nil { if err != nil {
return err return err
} }
@ -52,11 +59,15 @@ func DeleteJoke(c *fiber.Ctx) error {
return err return err
} }
return c.Status(fiber.StatusOK).JSON(models.ResponseJoke{ return c.
Message: "specified joke id has been deleted", Status(fiber.StatusOK).
}) JSON(models.ResponseJoke{
Message: "specified joke id has been deleted",
})
} }
return c.Status(fiber.StatusNotAcceptable).JSON(models.Error{ return c.
Error: "specified joke id does not exists", Status(fiber.StatusNotAcceptable).
}) JSON(models.Error{
Error: "specified joke id does not exists",
})
} }

View File

@ -132,7 +132,9 @@ func JokeByID(c *fiber.Ctx) error {
} }
if link == "" { if link == "" {
return c.Status(fiber.StatusNotFound).Send([]byte("Requested ID was not found.")) return c.
Status(fiber.StatusNotFound).
Send([]byte("Requested ID was not found."))
} }
// Get image data // Get image data

View File

@ -26,14 +26,18 @@ func TotalJokes(c *fiber.Ctx) error {
if err != nil { if err != nil {
if err.Error() == "Entry not found" { if err.Error() == "Entry not found" {
return c.Status(fiber.StatusInternalServerError).JSON(models.Error{ return c.
Error: "no data found", Status(fiber.StatusInternalServerError).
}) JSON(models.Error{
Error: "no data found",
})
} }
return err return err
} }
return c.Status(fiber.StatusOK).JSON(models.ResponseJoke{ return c.
Message: strconv.Itoa(int(total[0])), Status(fiber.StatusOK).
}) JSON(models.ResponseJoke{
Message: strconv.Itoa(int(total[0])),
})
} }

View File

@ -14,7 +14,11 @@ import (
func UpdateJoke(c *fiber.Ctx) error { func UpdateJoke(c *fiber.Ctx) error {
id := c.Params("id") id := c.Params("id")
// Check if the joke exists // Check if the joke exists
sql, args, err := handler.Psql.Select("id").From("jokesbapak2").Where(squirrel.Eq{"id": id}).ToSql() sql, args, err := handler.Psql.
Select("id").
From("jokesbapak2").
Where(squirrel.Eq{"id": id}).
ToSql()
if err != nil { if err != nil {
return err return err
} }
@ -39,12 +43,18 @@ func UpdateJoke(c *fiber.Ctx) error {
} }
if !valid { if !valid {
return c.Status(fiber.StatusBadRequest).JSON(models.Error{ return c.
Error: "URL provided is not a valid image", Status(fiber.StatusBadRequest).
}) JSON(models.Error{
Error: "URL provided is not a valid image",
})
} }
sql, args, err = handler.Psql.Update("jokesbapak2").Set("link", body.Link).Set("creator", c.Locals("userID")).ToSql() sql, args, err = handler.Psql.
Update("jokesbapak2").
Set("link", body.Link).
Set("creator", c.Locals("userID")).
ToSql()
if err != nil { if err != nil {
return err return err
} }
@ -65,13 +75,17 @@ func UpdateJoke(c *fiber.Ctx) error {
return err return err
} }
return c.Status(fiber.StatusOK).JSON(models.ResponseJoke{ return c.
Message: "specified joke id has been updated", Status(fiber.StatusOK).
Link: body.Link, JSON(models.ResponseJoke{
}) Message: "specified joke id has been updated",
Link: body.Link,
})
} }
return c.Status(fiber.StatusNotAcceptable).JSON(models.Error{ return c.
Error: "specified joke id does not exists", Status(fiber.StatusNotAcceptable).
}) JSON(models.Error{
Error: "specified joke id does not exists",
})
} }

View File

@ -24,7 +24,11 @@ func RequireAuth() fiber.Handler {
} }
// Check if key exists // Check if key exists
sql, args, err := psql.Select("token").From("administrators").Where(squirrel.Eq{"key": auth.Key}).ToSql() sql, args, err := psql.
Select("token").
From("administrators").
Where(squirrel.Eq{"key": auth.Key}).
ToSql()
if err != nil { if err != nil {
return err return err
} }
@ -33,9 +37,11 @@ func RequireAuth() fiber.Handler {
err = db.QueryRow(context.Background(), sql, args...).Scan(&token) err = db.QueryRow(context.Background(), sql, args...).Scan(&token)
if err != nil { if err != nil {
if err.Error() == "no rows in result set" { if err.Error() == "no rows in result set" {
return c.Status(fiber.StatusForbidden).JSON(models.Error{ return c.
Error: "Invalid key", Status(fiber.StatusForbidden).
}) JSON(models.Error{
Error: "Invalid key",
})
} }
return err return err
} }
@ -51,7 +57,10 @@ func RequireAuth() fiber.Handler {
} }
if verify { if verify {
sql, args, err = psql.Update("administrators").Set("last_used", time.Now().UTC().Format(time.RFC3339)).ToSql() sql, args, err = psql.
Update("administrators").
Set("last_used", time.Now().UTC().Format(time.RFC3339)).
ToSql()
if err != nil { if err != nil {
return err return err
} }
@ -61,7 +70,11 @@ func RequireAuth() fiber.Handler {
return err return err
} }
sql, args, err = psql.Select("id").From("administrators").Where(squirrel.Eq{"key": auth.Key}).ToSql() sql, args, err = psql.
Select("id").
From("administrators").
Where(squirrel.Eq{"key": auth.Key}).
ToSql()
if err != nil { if err != nil {
return err return err
} }
@ -75,8 +88,10 @@ func RequireAuth() fiber.Handler {
return c.Next() return c.Next()
} }
return c.Status(fiber.StatusForbidden).JSON(models.Error{ return c.
Error: "Invalid key", Status(fiber.StatusForbidden).
}) JSON(models.Error{
Error: "Invalid key",
})
} }
} }

View File

@ -19,8 +19,10 @@ func OnlyIntegerAsID() fiber.Handler {
return c.Next() return c.Next()
} }
return c.Status(fiber.StatusBadRequest).JSON(models.Error{ return c.
Error: "only numbers are allowed as ID", Status(fiber.StatusBadRequest).
}) JSON(models.Error{
Error: "only numbers are allowed as ID",
})
} }
} }