/
withdrawal.go
45 lines (38 loc) · 1.09 KB
/
withdrawal.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
package v1
import (
"net/http"
"time"
"github.com/freeusd/solebtc/Godeps/_workspace/src/github.com/gin-gonic/gin"
"github.com/freeusd/solebtc/errors"
"github.com/freeusd/solebtc/models"
)
// WithdrawalList returns user's withdrawal list as response
func WithdrawalList(
getWithdrawalsSince dependencyGetWithdrawalsSince,
getWithdrawalsUntil dependencyGetWithdrawalsUntil,
) gin.HandlerFunc {
return func(c *gin.Context) {
authToken := c.MustGet("auth_token").(models.AuthToken)
// parse pagination args
isSince, separator, limit, err := parsePagination(c)
if err != nil {
c.AbortWithStatus(http.StatusBadRequest)
return
}
// get result according to args
t := time.Unix(separator, 0)
result := []models.Withdrawal{}
var syserr *errors.Error
if isSince {
result, syserr = getWithdrawalsSince(authToken.UserID, t, limit)
} else {
result, syserr = getWithdrawalsUntil(authToken.UserID, t, limit)
}
// response with result or error
if syserr != nil {
c.AbortWithError(http.StatusInternalServerError, syserr)
return
}
c.JSON(http.StatusOK, result)
}
}