-
Notifications
You must be signed in to change notification settings - Fork 0
/
upload.go
89 lines (76 loc) · 1.96 KB
/
upload.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package otrscouting
import (
json2 "encoding/json"
"fmt"
"github.com/gin-gonic/gin"
"strconv"
)
type UploadData struct {
PageTitle string
Uploaded bool
Unauthorized bool
}
type MatchUpload struct {
MatchId string `json:"match_id"`
Level string `json:"comp_level"`
EventId string `json:"event_id"`
Year int `json:"year"`
MatchData struct {
Red1 RobotTemplate `json:"red_1"`
Red2 RobotTemplate `json:"red_2"`
Red3 RobotTemplate `json:"red_3"`
Blue1 RobotTemplate `json:"blue_1"`
Blue2 RobotTemplate `json:"blue_2"`
Blue3 RobotTemplate `json:"blue_3"`
} `json:"match_data"`
}
func (m *MatchUpload) toMatchTemplate() MatchTemplate {
var mt = MatchTemplate{}
mt.MatchId = strconv.Itoa(m.Year) + "_" + m.EventId + "_" + string(m.Level[0]) + m.MatchId
mt.MatchNumber = m.MatchId
mt.Blue1 = m.MatchData.Blue1
mt.Blue2 = m.MatchData.Blue2
mt.Blue3 = m.MatchData.Blue3
mt.Red1 = m.MatchData.Red1
mt.Red2 = m.MatchData.Red2
mt.Red3 = m.MatchData.Red3
return mt
}
func (m MatchUpload) MatchCode() string {
return strconv.Itoa(m.Year) + "_" + m.EventId + "_" + m.MatchId
}
func GinDataTypeHandler(c *gin.Context) {
json := getMatch(c, "2018_onwat_q1")
c.JSON(200, json)
}
func GinUploadHandler(c *gin.Context) {
tmpl := GetPageTemplate("upload.html", c)
data := UploadData{
PageTitle: "Upload Event Info",
Uploaded: false,
Unauthorized: true,
}
if c.Request.Method == "GET" {
tmpl.Execute(c.Writer, data)
} else if c.Request.Method == "POST" {
data.Uploaded = true
// Extract JSON
pass := c.PostForm("pass")
if pass == "OTR3474" {
data.Unauthorized = false
}
if data.Unauthorized {
tmpl.Execute(c.Writer, data)
return
}
rawJson := c.PostForm("json")
var matches []MatchUpload
tmpl.Execute(c.Writer, data)
if err := json2.Unmarshal([]byte(rawJson), &matches); err != nil {
fmt.Fprint(c.Writer, err)
}
uploadMatchToDatastore(c, matches)
}
}
func GinManualUploadHandler(c *gin.Context) {
}