This repository has been archived by the owner on Oct 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
transactions.go
62 lines (51 loc) · 1.77 KB
/
transactions.go
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package controller
import (
"github.com/kataras/iris/v12"
"github.com/kataras/iris/v12/context"
"github.com/kataras/iris/v12/core/router"
"net/http"
)
func (c *Controller) handleTransactions(p iris.Party) {
p.PartyFunc("/{bankAccountId:uint64}/transactions", func(p router.Party) {
p.Get("/", func(ctx *context.Context) {
bankAccountId := ctx.Params().GetUint64Default("bankAccountId", 0)
if bankAccountId == 0 {
c.returnError(ctx, http.StatusBadRequest, "must specify valid bank account Id")
return
}
// TODO Enforce a max limit for the number of transactions that can be requested.
limit := ctx.URLParamIntDefault("limit", 25)
offset := ctx.URLParamIntDefault("offset", 0)
repo := c.mustGetAuthenticatedRepository(ctx)
transactions, err := repo.GetTransactions(bankAccountId, limit, offset)
if err != nil {
c.wrapPgError(ctx, err, "failed to retrieve transactions")
return
}
ctx.JSON(map[string]interface{}{
"transactions": transactions,
})
})
p.Post("/", func(ctx *context.Context) {
bankAccountId := ctx.Params().GetUint64Default("bankAccountId", 0)
if bankAccountId == 0 {
c.returnError(ctx, http.StatusBadRequest, "must specify valid bank account Id")
return
}
})
p.Put("/{transactionId:uint64}", func(ctx *context.Context) {
bankAccountId := ctx.Params().GetUint64Default("bankAccountId", 0)
if bankAccountId == 0 {
c.returnError(ctx, http.StatusBadRequest, "must specify valid bank account Id")
return
}
})
p.Delete("/{transactionId:uint64}", func(ctx *context.Context) {
bankAccountId := ctx.Params().GetUint64Default("bankAccountId", 0)
if bankAccountId == 0 {
c.returnError(ctx, http.StatusBadRequest, "must specify valid bank account Id")
return
}
})
})
}