forked from krasnopv/das
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entry.go
119 lines (103 loc) · 3.66 KB
/
entry.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
package controller
import (
"encoding/json"
"github.com/ProximaB/das/businesslogic"
"github.com/ProximaB/das/controller/util"
"github.com/ProximaB/das/viewmodel"
"net/http"
)
type EntryServer struct {
Service businesslogic.CompetitionRegistrationService
}
// SearchCompetitionEntryHandler handles the request
// GET /api/v1.0/competition/entries
// Public view for competitive event entry
func (server EntryServer) SearchCompetitionEntryHandler(w http.ResponseWriter, r *http.Request) {
form := new(viewmodel.SearchEntryForm)
if parseErr := util.ParseRequestData(r, form); parseErr != nil {
util.RespondJsonResult(w, http.StatusBadRequest, util.HTTP400InvalidRequestData, parseErr.Error())
return
}
criteria := businesslogic.SearchEntryCriteria{
CompetitionID: form.CompetitionID,
EventID: form.EventID,
FederationID: form.FederationID,
DivisionID: form.DivisionID,
ProficiencyID: form.ProficiencyID,
StyleID: form.StyleID,
AthleteID: form.AthleteID,
PartnershipID: form.PartnershipID,
}
entries, err := server.Service.SearchCompetitionEntries(criteria) // TODO: the underlying query may need optimization
if err != nil {
util.RespondJsonResult(w, http.StatusInternalServerError, err.Error(), nil)
return
}
data := viewmodel.CompetitionEntriesToViewModel(entries)
output, _ := json.Marshal(data)
w.Write(output)
}
// GET /api/v1.0/event/entries
// Parameters:
// {
// "eventId": 0.
// }
func (server EntryServer) SearchEventEntryHandler(w http.ResponseWriter, r *http.Request) {
form := new(viewmodel.SearchEntryForm)
if parseErr := util.ParseRequestData(r, form); parseErr != nil {
util.RespondJsonResult(w, http.StatusBadRequest, util.HTTP400InvalidRequestData, parseErr.Error())
return
}
criteria := businesslogic.SearchEntryCriteria{
CompetitionID: form.CompetitionID,
EventID: form.EventID,
FederationID: form.FederationID,
DivisionID: form.DivisionID,
ProficiencyID: form.ProficiencyID,
StyleID: form.StyleID,
AthleteID: form.AthleteID,
PartnershipID: form.PartnershipID,
}
entries, err := server.Service.SearchEventEntries(criteria) // TODO: the underlying query may need optimization
if err != nil {
util.RespondJsonResult(w, http.StatusInternalServerError, err.Error(), nil)
return
}
data := make([]viewmodel.EventEntryListViewModel, 0)
for _, each := range entries {
views := viewmodel.EventEntriesToViewModel(each)
data = append(data, views)
}
output, _ := json.Marshal(data)
w.Write(output)
}
// GET /api/v1.0/athlete/entries
func (server EntryServer) SearchAthleteEntryHandler(w http.ResponseWriter, r *http.Request) {
}
// SearchPartnershipEntryHandler handles the request
// GET /api/v1.0/partnership/entries
func (server EntryServer) SearchPartnershipEntryHandler(w http.ResponseWriter, r *http.Request) {
form := new(viewmodel.SearchEntryForm)
if parseErr := util.ParseRequestData(r, form); parseErr != nil {
util.RespondJsonResult(w, http.StatusBadRequest, util.HTTP400InvalidRequestData, parseErr.Error())
return
}
criteria := businesslogic.SearchEntryCriteria{
CompetitionID: form.CompetitionID,
EventID: form.EventID,
FederationID: form.FederationID,
DivisionID: form.DivisionID,
ProficiencyID: form.ProficiencyID,
StyleID: form.StyleID,
AthleteID: form.AthleteID,
PartnershipID: form.PartnershipID,
}
entries, err := server.Service.SearchPartnershipEventEntries(criteria) // TODO: the underlying query may need optimization
if err != nil {
util.RespondJsonResult(w, http.StatusInternalServerError, err.Error(), nil)
return
}
data := viewmodel.CoupleEventEntryToViewModel(entries)
output, _ := json.Marshal(data)
w.Write(output)
}