-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
95 lines (75 loc) · 3.71 KB
/
main.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
package main
import (
"github.com/go-macaron/cache"
_ "github.com/go-macaron/cache/redis"
"github.com/go-macaron/binding"
_ "github.com/go-sql-driver/mysql"
"github.com/tahsinrahman/online-judge/db"
"github.com/tahsinrahman/online-judge/handlers"
"github.com/tahsinrahman/online-judge/middlewares"
"gopkg.in/macaron.v1"
)
func main() {
//starts database engine
db.StartEngine()
//macaron engine
m := macaron.Classic()
m.Use(macaron.Renderer()) //for html rendering
m.Use(cache.Cacher(cache.Options{
Adapter: "redis",
AdapterConfig: "addr=127.0.0.1:6379",
OccupyMode: false,
}))
m.Use(middlewares.CheckAuthentication) //check cookie
//FIXME
m.Get("/pd", handlers.PD)
m.Get("/wait", handlers.WaitingForApproval)
m.Get("/approve/:user", handlers.ApproveTeacher)
//middlewares for every route
m.SetDefaultCookieSecret("tahsin")
//handlers for user registration, login and logout TODO: secret key based cookie
m.Get("/", handlers.GetHome) //done
m.Get("/signup", handlers.GetSignUp) //done
m.Post("/signup", binding.Bind(handlers.Users{}), handlers.PostSignUp) //done
m.Get("/signin", handlers.GetSignIn) //done
m.Post("/signin", binding.Bind(handlers.Users{}), handlers.PostSignIn) //done
m.Get("/signout", handlers.GetSignOut) //done
// m.Get("/upload", handlers.GetUpload) //done
// m.Post("/upload", handlers.Upload) //done
//handlers for contests
m.Group("/contests", func() {
m.Get("/", handlers.GetAllContests) //done
m.Get("/new", middlewares.CheckAdmin, handlers.GetNewContest) //done
m.Post("/new", middlewares.CheckAdmin, binding.Bind(handlers.Contest{}), handlers.PostContest) //done
m.Group("/:cid", func() {
m.Get("/", handlers.GetDashboard) //done
m.Get("/auth", handlers.ContestAuth) //done
m.Get("/rank", handlers.GetRank)
m.Get("/submissions", handlers.GetAllSubmissions)
m.Get("/submissions/:id", handlers.GetSubmission)
m.Group("", func() {
m.Get("/update", handlers.GetUpdateContest) //done
m.Post("/update", binding.Bind(handlers.Contest{}), handlers.PutContest) //done
m.Get("/new", handlers.GetNewProblem) //done
m.Post("/new", binding.Bind(handlers.Problem{}), binding.MultipartForm(handlers.ProblemDataset{}), handlers.PostProblem) //TODO:db
}, middlewares.CheckManager)
m.Group("/:pid", func() {
m.Get("/", middlewares.CheckStartTime, middlewares.AddSubmissions, handlers.GetProblem)
//m.Delete("/", handlers.DeleteProblem)
//m.Post("/update", binding.Bind(handlers.Problem{}), binding.MultipartForm(handlers.ProblemDataset{}), handlers.PutPostProblem)
m.Get("/dload/:type/:id", middlewares.CheckManager, handlers.DownloadTest)
m.Get("/tests", middlewares.CheckManager, middlewares.AddTests, handlers.GetList)
m.Post("/tests", middlewares.CheckManager, binding.Bind(handlers.ProblemDataset{}), handlers.AddNewTest)
m.Post("/submit", middlewares.CheckStartTime, middlewares.CheckEndTime, binding.MultipartForm(handlers.Submission{}), handlers.SubmitProblem)
m.Group("/update", func() {
m.Get("/", handlers.UpdateProblem)
m.Post("/description", binding.Bind(handlers.Problem{}), handlers.UpdateProblemDescripton)
m.Delete("/:id", handlers.DeleteTest)
}, middlewares.CheckManager, middlewares.AddTests)
}, middlewares.CheckProblem) //need to add middleware to check if problem exists
}, middlewares.CheckContestExistance, middlewares.AddContestPermission)
})
handlers.Init()
//starting the server
m.Run()
}