Fixing up the go code, adding initial work for the stats pages, adding a function to pre-populate the database with some example polls for testing. Will be removed later
This commit is contained in:
@@ -22,6 +22,7 @@ type Member struct {
|
||||
}
|
||||
|
||||
const BATCH_SIZE = 100
|
||||
const CVS_FILE_FIELD = "members.csv"
|
||||
|
||||
func AdminMembersHandler(resWriter http.ResponseWriter, request *http.Request) {
|
||||
if request.Method != http.MethodPost {
|
||||
@@ -49,16 +50,16 @@ func AdminMembersHandler(resWriter http.ResponseWriter, request *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
file, _, err := request.FormFile("members.csv")
|
||||
file, _, err := request.FormFile(CVS_FILE_FIELD)
|
||||
if err != nil {
|
||||
common.SendError(resWriter, "Failed to read members.csv file", http.StatusBadRequest)
|
||||
common.SendError(resWriter, "Failed to read " + CVS_FILE_FIELD + " file", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
fileBytes, err := ioutil.ReadAll(file)
|
||||
if err != nil {
|
||||
common.SendError(resWriter, "Failed to read members.csv file", http.StatusInternalServerError)
|
||||
common.SendError(resWriter, "Failed to read " + CVS_FILE_FIELD + " file", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -68,7 +69,7 @@ func AdminMembersHandler(resWriter http.ResponseWriter, request *http.Request) {
|
||||
}
|
||||
|
||||
resWriter.WriteHeader(http.StatusOK)
|
||||
json.NewEncoder(resWriter).Encode(map[string]bool{"success": true})
|
||||
json.NewEncoder(resWriter).Encode(map[string]bool{common.SUCCESS: true})
|
||||
}
|
||||
|
||||
func AdminMembersView(resWriter http.ResponseWriter, request *http.Request) {
|
||||
@@ -92,7 +93,7 @@ func AdminMembersView(resWriter http.ResponseWriter, request *http.Request) {
|
||||
|
||||
resWriter.WriteHeader(http.StatusOK)
|
||||
json.NewEncoder(resWriter).Encode(map[string]interface{}{
|
||||
"success": true,
|
||||
common.SUCCESS: true,
|
||||
"members": members,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user