From b6788b33c616d0d15ea4dc703cc9fd88e09ebe08 Mon Sep 17 00:00:00 2001 From: Reinaldy Rafli Date: Wed, 4 Aug 2021 17:14:33 +0700 Subject: [PATCH] style: chained function line breaks --- api/app/v1/handler/joke/joke_add.go | 22 ++++++++++----- api/app/v1/handler/joke/joke_delete.go | 27 ++++++++++++------ api/app/v1/handler/joke/joke_get.go | 4 ++- api/app/v1/handler/joke/joke_total.go | 16 +++++++---- api/app/v1/handler/joke/joke_update.go | 38 ++++++++++++++++++-------- api/app/v1/middleware/auth.go | 33 ++++++++++++++++------ api/app/v1/middleware/validation.go | 8 ++++-- 7 files changed, 102 insertions(+), 46 deletions(-) diff --git a/api/app/v1/handler/joke/joke_add.go b/api/app/v1/handler/joke/joke_add.go index c569357..30c0989 100644 --- a/api/app/v1/handler/joke/joke_add.go +++ b/api/app/v1/handler/joke/joke_add.go @@ -24,12 +24,18 @@ func AddNewJoke(c *fiber.Ctx) error { } if !valid { - return c.Status(fiber.StatusBadRequest).JSON(models.Error{ - Error: "URL provided is not a valid image", - }) + return c. + 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 { return err } @@ -51,7 +57,9 @@ func AddNewJoke(c *fiber.Ctx) error { return err } - return c.Status(fiber.StatusCreated).JSON(models.ResponseJoke{ - Link: body.Link, - }) + return c. + Status(fiber.StatusCreated). + JSON(models.ResponseJoke{ + Link: body.Link, + }) } diff --git a/api/app/v1/handler/joke/joke_delete.go b/api/app/v1/handler/joke/joke_delete.go index 4b8e63d..d3b7c69 100644 --- a/api/app/v1/handler/joke/joke_delete.go +++ b/api/app/v1/handler/joke/joke_delete.go @@ -19,7 +19,11 @@ func DeleteJoke(c *fiber.Ctx) error { } // 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 { return err } @@ -31,7 +35,10 @@ func DeleteJoke(c *fiber.Ctx) error { } 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 { return err } @@ -52,11 +59,15 @@ func DeleteJoke(c *fiber.Ctx) error { return err } - return c.Status(fiber.StatusOK).JSON(models.ResponseJoke{ - Message: "specified joke id has been deleted", - }) + return c. + Status(fiber.StatusOK). + JSON(models.ResponseJoke{ + Message: "specified joke id has been deleted", + }) } - return c.Status(fiber.StatusNotAcceptable).JSON(models.Error{ - Error: "specified joke id does not exists", - }) + return c. + Status(fiber.StatusNotAcceptable). + JSON(models.Error{ + Error: "specified joke id does not exists", + }) } diff --git a/api/app/v1/handler/joke/joke_get.go b/api/app/v1/handler/joke/joke_get.go index 47563ec..cab33a8 100644 --- a/api/app/v1/handler/joke/joke_get.go +++ b/api/app/v1/handler/joke/joke_get.go @@ -132,7 +132,9 @@ func JokeByID(c *fiber.Ctx) error { } 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 diff --git a/api/app/v1/handler/joke/joke_total.go b/api/app/v1/handler/joke/joke_total.go index c6bb933..6fc1874 100644 --- a/api/app/v1/handler/joke/joke_total.go +++ b/api/app/v1/handler/joke/joke_total.go @@ -26,14 +26,18 @@ func TotalJokes(c *fiber.Ctx) error { if err != nil { if err.Error() == "Entry not found" { - return c.Status(fiber.StatusInternalServerError).JSON(models.Error{ - Error: "no data found", - }) + return c. + Status(fiber.StatusInternalServerError). + JSON(models.Error{ + Error: "no data found", + }) } return err } - return c.Status(fiber.StatusOK).JSON(models.ResponseJoke{ - Message: strconv.Itoa(int(total[0])), - }) + return c. + Status(fiber.StatusOK). + JSON(models.ResponseJoke{ + Message: strconv.Itoa(int(total[0])), + }) } diff --git a/api/app/v1/handler/joke/joke_update.go b/api/app/v1/handler/joke/joke_update.go index 36bef5d..7a5ee83 100644 --- a/api/app/v1/handler/joke/joke_update.go +++ b/api/app/v1/handler/joke/joke_update.go @@ -14,7 +14,11 @@ import ( func UpdateJoke(c *fiber.Ctx) error { id := c.Params("id") // 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 { return err } @@ -39,12 +43,18 @@ func UpdateJoke(c *fiber.Ctx) error { } if !valid { - return c.Status(fiber.StatusBadRequest).JSON(models.Error{ - Error: "URL provided is not a valid image", - }) + return c. + 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 { return err } @@ -65,13 +75,17 @@ func UpdateJoke(c *fiber.Ctx) error { return err } - return c.Status(fiber.StatusOK).JSON(models.ResponseJoke{ - Message: "specified joke id has been updated", - Link: body.Link, - }) + return c. + Status(fiber.StatusOK). + JSON(models.ResponseJoke{ + Message: "specified joke id has been updated", + Link: body.Link, + }) } - return c.Status(fiber.StatusNotAcceptable).JSON(models.Error{ - Error: "specified joke id does not exists", - }) + return c. + Status(fiber.StatusNotAcceptable). + JSON(models.Error{ + Error: "specified joke id does not exists", + }) } diff --git a/api/app/v1/middleware/auth.go b/api/app/v1/middleware/auth.go index 1c1157b..7ef7768 100644 --- a/api/app/v1/middleware/auth.go +++ b/api/app/v1/middleware/auth.go @@ -24,7 +24,11 @@ func RequireAuth() fiber.Handler { } // 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 { return err } @@ -33,9 +37,11 @@ func RequireAuth() fiber.Handler { err = db.QueryRow(context.Background(), sql, args...).Scan(&token) if err != nil { if err.Error() == "no rows in result set" { - return c.Status(fiber.StatusForbidden).JSON(models.Error{ - Error: "Invalid key", - }) + return c. + Status(fiber.StatusForbidden). + JSON(models.Error{ + Error: "Invalid key", + }) } return err } @@ -51,7 +57,10 @@ func RequireAuth() fiber.Handler { } 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 { return err } @@ -61,7 +70,11 @@ func RequireAuth() fiber.Handler { 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 { return err } @@ -75,8 +88,10 @@ func RequireAuth() fiber.Handler { return c.Next() } - return c.Status(fiber.StatusForbidden).JSON(models.Error{ - Error: "Invalid key", - }) + return c. + Status(fiber.StatusForbidden). + JSON(models.Error{ + Error: "Invalid key", + }) } } diff --git a/api/app/v1/middleware/validation.go b/api/app/v1/middleware/validation.go index c1f913f..0156d81 100644 --- a/api/app/v1/middleware/validation.go +++ b/api/app/v1/middleware/validation.go @@ -19,8 +19,10 @@ func OnlyIntegerAsID() fiber.Handler { return c.Next() } - return c.Status(fiber.StatusBadRequest).JSON(models.Error{ - Error: "only numbers are allowed as ID", - }) + return c. + Status(fiber.StatusBadRequest). + JSON(models.Error{ + Error: "only numbers are allowed as ID", + }) } }