-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathset-token.go
More file actions
33 lines (27 loc) 路 861 Bytes
/
Copy pathset-token.go
File metadata and controls
33 lines (27 loc) 路 861 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
31
32
33
package interbank
import (
"net/http"
"time"
"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/token"
"github.com/jnaraujo/tec502-inter-bank/bank/internal/validate"
)
type setTokenBodySchema struct {
To interbank.BankId `json:"to" validate:"required"`
Ts time.Time `json:"ts" validate:"required"`
}
func SetToken(c *fiber.Ctx) error {
var body setTokenBodySchema
if errs := validate.ParseAndValidate(c.Body(), &body); len(errs) > 0 {
return c.Status(http.StatusBadRequest).JSON(&fiber.Map{"errors": errs})
}
storage.Token.Set(token.Token{
Owner: body.To,
Ts: body.Ts,
})
return c.Status(http.StatusOK).JSON(fiber.Map{
"message": "Token setado com sucesso",
})
}