Skip to content

Commit 27b379d

Browse files
committed
update api and bug fix mime type for windows
1 parent ed006aa commit 27b379d

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

handler/api.go

+23
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,26 @@ func GetRecords(c echo.Context) error {
1717

1818
return c.JSON(http.StatusOK, records)
1919
}
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+
}

router.go

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"io"
5+
"mime"
56
"text/template"
67

78
"github.com/labstack/echo"
@@ -14,6 +15,9 @@ type Template struct {
1415
}
1516

1617
func newRouter() *echo.Echo {
18+
// for windows probrem: return incorrect MIME Type "text/plain"
19+
mime.AddExtensionType(".js", "application/javascript")
20+
1721
e := echo.New()
1822
e.Use(middleware.Logger())
1923
e.Use(middleware.Recover())

0 commit comments

Comments
 (0)