/
helpers.go
45 lines (36 loc) · 1.01 KB
/
helpers.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 handlers
import (
"net/http"
"strings"
"github.com/baking-bad/bcdhub/internal/config"
"github.com/baking-bad/bcdhub/internal/models/types"
"github.com/gin-gonic/gin"
)
// ContractsHelpers -
func ContractsHelpers() gin.HandlerFunc {
return func(c *gin.Context) {
ctx := c.MustGet("context").(*config.Context)
var req getByNetwork
if err := c.ShouldBindUri(&req); handleError(c, ctx.Storage, err, http.StatusNotFound) {
return
}
var args findContract
if err := c.ShouldBindQuery(&args); handleError(c, ctx.Storage, err, http.StatusBadRequest) {
return
}
splitted := strings.Split(args.Tags, ",")
tags := types.NewTags(splitted)
contract, err := ctx.Contracts.FindOne(c.Request.Context(), tags)
if handleError(c, ctx.Storage, err, http.StatusNotFound) {
return
}
response, err := contractPostprocessing(ctx, contract)
if handleError(c, ctx.Storage, err, 0) {
return
}
c.SecureJSON(http.StatusOK, response)
}
}
func getStringPointer(s string) *string {
return &s
}