auth-api/src/handlers/get.go

38 lines
1.1 KiB
Go
Raw Normal View History

2020-12-29 13:46:58 +01:00
package handlers
import (
"github.com/gofiber/fiber/v2"
)
2021-06-22 22:52:48 +02:00
// AccountGet godoc
2021-06-22 23:49:11 +02:00
// @Summary Get account by id
// @Description Requires Authorization-header with either role "admin" or with a matching account id.
// @Description Example: Authorization: bearer xxx
// @Description Where "xxx" is a valid JWT token
2021-06-22 22:52:48 +02:00
// @ID get-account-by-id
// @Accept json
// @Produce json
// @Param id path string true "Account ID"
// @Success 200 {object} db.Account
2021-06-22 23:49:11 +02:00
// @Failure 401 {object} []ResJSONError
// @Failure 403 {object} []ResJSONError
// @Failure 415 {object} []ResJSONError
// @Failure 500 {object} []ResJSONError
2021-06-22 22:52:48 +02:00
// @Router /account/{id} [get]
2021-01-02 11:56:24 +01:00
func (h Handlers) AccountGet(c *fiber.Ctx) error {
accountID := c.Params("accountID")
// logContext := log.WithFields(log.Fields{"accountID": accountID})
authErr := h.RequireAdminRoleOrAccountID(c, accountID)
if authErr != nil {
return c.Status(403).JSON([]ResJSONError{{Error: authErr.Error()}})
}
account, accountErr := h.Db.AccountGet(accountID, "", "")
if accountErr != nil {
return c.Status(500).JSON([]ResJSONError{{Error: accountErr.Error()}})
}
return c.JSON(account)
2020-12-29 13:46:58 +01:00
}