File tree 2 files changed +27
-0
lines changed
2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -17,3 +17,26 @@ func GetRecords(c echo.Context) error {
17
17
18
18
return c .JSON (http .StatusOK , records )
19
19
}
20
+
21
+ func AddRecord (c echo.Context ) error {
22
+ record := new (model.Record )
23
+ if err := c .Bind (record ); err != nil {
24
+ return err
25
+ }
26
+
27
+ if record .Mode == "" {
28
+ return & echo.HTTPError {
29
+ Code : http .StatusBadRequest ,
30
+ Message : "invalid point or mode field" ,
31
+ }
32
+ }
33
+
34
+ uid := userIDFromToken (c )
35
+ if user := model .FindUser (& model.User {ID : uid }); user .ID == 0 {
36
+ return echo .ErrNotFound
37
+ }
38
+
39
+ record .UID = uid
40
+ model .CreateRecord (record )
41
+ return c .JSON (http .StatusCreated , record )
42
+ }
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package main
2
2
3
3
import (
4
4
"io"
5
+ "mime"
5
6
"text/template"
6
7
7
8
"github.com/labstack/echo"
@@ -14,6 +15,9 @@ type Template struct {
14
15
}
15
16
16
17
func newRouter () * echo.Echo {
18
+ // for windows probrem: return incorrect MIME Type "text/plain"
19
+ mime .AddExtensionType (".js" , "application/javascript" )
20
+
17
21
e := echo .New ()
18
22
e .Use (middleware .Logger ())
19
23
e .Use (middleware .Recover ())
You can’t perform that action at this time.
0 commit comments