-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth.go
More file actions
30 lines (24 loc) 路 788 Bytes
/
Copy pathauth.go
File metadata and controls
30 lines (24 loc) 路 788 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package bank
import (
"net/http"
"github.com/gofiber/fiber/v2"
"github.com/jnaraujo/tec502-inter-bank/bank/internal/interbank"
"github.com/jnaraujo/tec502-inter-bank/bank/internal/storage"
"github.com/jnaraujo/tec502-inter-bank/bank/internal/validate"
)
type authBodySchema struct {
IBK interbank.IBK `json:"acc_ibk" validate:"required"`
}
func AuthRoute(c *fiber.Ctx) error {
var body authBodySchema
if errs := validate.ParseAndValidate(c.Body(), &body); len(errs) > 0 {
return c.Status(http.StatusBadRequest).JSON(&fiber.Map{"errors": errs})
}
acc := storage.Accounts.FindAccountByIBK(body.IBK)
if acc == nil {
return c.Status(http.StatusUnauthorized).JSON(&fiber.Map{
"message": "Conta n茫o encontrada",
})
}
return c.Status(http.StatusCreated).JSON(acc)
}