forked from ZJGSU-Open-Source/GoOnlineJudge
-
Notifications
You must be signed in to change notification settings - Fork 5
/
status.go
122 lines (106 loc) · 2.76 KB
/
status.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package controller
import (
"github.com/ZJGSU-ACM/GoOnlineJudge/class"
"github.com/ZJGSU-ACM/GoOnlineJudge/config"
"github.com/ZJGSU-ACM/GoOnlineJudge/model"
"github.com/ZJGSU-ACM/restweb"
"net/http"
"strconv"
)
type StatusController struct {
class.Controller
} //@Controller
//@URL: /status @method: GET
func (sc *StatusController) List() {
restweb.Logger.Debug("Status List")
searchUrl := ""
qry := make(map[string]string)
// Search
if v, ok := sc.Input["uid"]; ok {
searchUrl += "uid=" + v[0] + "&"
sc.Output["SearchUid"] = v[0]
qry["uid"] = v[0]
}
if v, ok := sc.Input["pid"]; ok {
searchUrl += "pid=" + v[0] + "&"
sc.Output["SearchPid"] = v[0]
qry["pid"] = v[0]
}
if v, ok := sc.Input["judge"]; ok {
searchUrl += "judge=" + v[0] + "&"
sc.Output["SearchJudge"+v[0]] = v[0]
qry["judge"] = v[0]
}
if v, ok := sc.Input["language"]; ok {
searchUrl += "language=" + v[0] + "&"
sc.Output["SearchLanguage"+v[0]] = v[0]
qry["language"] = v[0]
}
sc.Output["URL"] = "/status?" + searchUrl
// Page
qry["page"] = "1"
if v, ok := sc.Input["page"]; ok {
qry["page"] = v[0]
}
solutionModel := model.SolutionModel{}
qry["module"] = strconv.Itoa(config.ModuleP)
qry["action"] = "submit"
count, err := solutionModel.Count(qry)
if err != nil {
sc.Error(err.Error(), 400)
return
}
var pageCount = (count-1)/config.SolutionPerPage + 1
page, err := strconv.Atoi(qry["page"])
if err != nil {
sc.Error("args error", 400)
return
}
if page > pageCount {
sc.Error("args error", 400)
return
}
qry["offset"] = strconv.Itoa((page - 1) * config.SolutionPerPage)
qry["limit"] = strconv.Itoa(config.SolutionPerPage)
pageData := sc.GetPage(page, pageCount)
for k, v := range pageData {
sc.Output[k] = v
}
list, err := solutionModel.List(qry)
if err != nil {
sc.Error(err.Error(), 500)
return
}
sc.Output["Solution"] = list
sc.Output["Title"] = "Status List"
sc.Output["IsStatus"] = true
sc.Output["Privilege"] = sc.Privilege
sc.Output["Uid"] = sc.Uid
sc.RenderTemplate("view/layout.tpl", "view/status_list.tpl")
}
//@URL: /status/code @method: GET
func (sc *StatusController) Code() {
restweb.Logger.Debug("Status Code")
sid, err := strconv.Atoi(sc.Input.Get("sid"))
if err != nil {
http.Error(sc.W, "args error", 400)
return
}
solutionModel := model.SolutionModel{}
one, err := solutionModel.Detail(sid)
if err != nil {
http.Error(sc.W, err.Error(), 400)
return
}
if one.Error != "" {
one.Code = one.Code + "\n/*\n" + one.Error + "*/\n"
}
if one.Uid == sc.Uid || sc.Privilege > config.PrivilegePU || one.Share {
sc.Output["Solution"] = one
sc.Output["Title"] = "View Code"
sc.Output["IsCode"] = true
sc.RenderTemplate("view/layout.tpl", "view/status_code.tpl")
} else {
sc.Err400("Warning", "You can't see it!")
}
}