Updating versions and changing log system
Some checks failed
continuous-integration/drone Build encountered an error
Some checks failed
continuous-integration/drone Build encountered an error
This commit is contained in:
@@ -44,3 +44,36 @@ func (h Handlers) AccountGet(c *fiber.Ctx) error {
|
||||
|
||||
return c.JSON(account)
|
||||
}
|
||||
|
||||
// AccountGet godoc
|
||||
// @Summary Get accounts
|
||||
// @Description Requires Authorization-header with role "admin".
|
||||
// @Description Example: Authorization: bearer xxx
|
||||
// @Description Where "xxx" is a valid JWT token
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {object} []db.Account
|
||||
// @Failure 401 {object} []ResJSONError
|
||||
// @Failure 403 {object} []ResJSONError
|
||||
// @Failure 415 {object} []ResJSONError
|
||||
// @Failure 500 {object} []ResJSONError
|
||||
// @Router /accounts [get]
|
||||
func (h Handlers) AccountsGet(c *fiber.Ctx) error {
|
||||
accountID := c.Params("accountID")
|
||||
|
||||
authErr := h.RequireAdminRole(c)
|
||||
if authErr != nil {
|
||||
return c.Status(403).JSON([]ResJSONError{{Error: authErr.Error()}})
|
||||
}
|
||||
|
||||
account, accountErr := h.Db.AccountGet(accountID, "", "")
|
||||
if accountErr != nil {
|
||||
if accountErr.Error() == "no rows in result set" {
|
||||
return c.Status(404).JSON([]ResJSONError{{Error: "No account found for given accountID"}})
|
||||
} else {
|
||||
return c.Status(500).JSON([]ResJSONError{{Error: accountErr.Error()}})
|
||||
}
|
||||
}
|
||||
|
||||
return c.JSON(account)
|
||||
}
|
||||
|
||||
@@ -25,13 +25,19 @@ import (
|
||||
func (h Handlers) AccountUpdateFields(c *fiber.Ctx) error {
|
||||
accountID := c.Params("accountID")
|
||||
|
||||
h.Log.Context = []interface{}{
|
||||
"accountID", accountID,
|
||||
}
|
||||
|
||||
_, uuidErr := uuid.Parse(accountID)
|
||||
if uuidErr != nil {
|
||||
h.Log.Debug("client supplied invalid uuid format")
|
||||
return c.Status(400).JSON([]ResJSONError{{Error: "Invalid uuid format"}})
|
||||
}
|
||||
|
||||
authErr := h.RequireAdminRole(c)
|
||||
if authErr != nil {
|
||||
h.Log.Debug("client does not have admin role")
|
||||
return c.Status(403).JSON([]ResJSONError{{Error: authErr.Error()}})
|
||||
}
|
||||
|
||||
|
||||
@@ -2,8 +2,8 @@ package handlers
|
||||
|
||||
import (
|
||||
"gitea.larvit.se/pwrpln/auth-api/src/db"
|
||||
"gitea.larvit.se/pwrpln/go_log"
|
||||
jwt "github.com/dgrijalva/jwt-go"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
// Claims is the JWT struct
|
||||
@@ -18,7 +18,7 @@ type Claims struct {
|
||||
type Handlers struct {
|
||||
Db db.Db
|
||||
JwtKey []byte
|
||||
Log *zap.SugaredLogger
|
||||
Log go_log.Log
|
||||
}
|
||||
|
||||
// ResJSONError is an error field that is used in JSON error responses
|
||||
|
||||
Reference in New Issue
Block a user