-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroutes.go
71 lines (58 loc) · 1.66 KB
/
routes.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
63
64
65
66
67
68
69
70
71
package main
import (
"fmt"
"html/template"
"net/http"
"github.com/labstack/echo/v4"
"github.com/pauleibye/urban-octo-bassoon/internal/usecase"
)
// func fromFormParams(id string, params url.Values) series {
// keys := make([]string, 0, len(params))
// for k := range params {
// keys = append(keys, k)
// }
// sort.Strings(keys)
// data := make([]int, 0, len(params))
// fmt.Printf("paultest data len: %v", len(data))
// for _, k := range keys {
// v, _ := strconv.Atoi(params.Get(k))
// data = append(data, v)
// }
// return NewSeries(id, data)
// }
type SeriesResponse struct {
Id string `json:"id"`
Render template.HTML `json:"render"`
}
type controller struct {
uc usecase.Usecase
}
func (c controller) Index(ctx echo.Context) error {
render, err := c.uc.GetChart(1)
if err != nil {
fmt.Println("paultest err: ", err)
return ctx.JSON(http.StatusInternalServerError, err)
}
return ctx.Render(http.StatusOK, "index.html", SeriesResponse{Id: "paulchart", Render: render})
}
// type putSeriesRequest struct {
// Series []int `form:"putSeries"`
// }
// func putSeries(c echo.Context) error {
// // var series map[string]string
// // err := c.Bind(&series)
// values, err := c.FormParams()
// if err != nil {
// return c.String(http.StatusBadRequest, "bad request")
// }
// fmt.Printf("paultest values: %v\n", values)
// // if len(series.Series) == 0 {
// // return c.String(http.StatusBadRequest, "bad request")
// // }
// id := c.Param("id")
// if id == "1" {
// series1 = fromFormParams(id, values)
// return c.Render(http.StatusOK, "index.html", series1)
// }
// return c.JSON(http.StatusNotFound, "series not found")
// }