diff options
Diffstat (limited to '')
-rw-r--r-- | endpoint_auth.go | 10 | ||||
-rw-r--r-- | endpoint_export_choices.go | 25 | ||||
-rw-r--r-- | endpoint_export_students.go | 16 |
3 files changed, 23 insertions, 28 deletions
diff --git a/endpoint_auth.go b/endpoint_auth.go index 4a9c770..0ff3316 100644 --- a/endpoint_auth.go +++ b/endpoint_auth.go @@ -157,12 +157,12 @@ func handleAuth(w http.ResponseWriter, req *http.Request) (string, int, error) { accessToken, err := getAccessToken(req.Context(), authorizationCode) if err != nil { - return "", http.StatusInternalServerError, err + return "", -1, err } department, err := getDepartment(req.Context(), *(accessToken.Content)) if err != nil { - return "", http.StatusInternalServerError, err + return "", -1, err } switch { @@ -176,7 +176,7 @@ func handleAuth(w http.ResponseWriter, req *http.Request) (string, int, error) { cookieValue, err := randomString(tokenLength) if err != nil { - return "", http.StatusInternalServerError, err + return "", -1, err } now := time.Now() @@ -218,10 +218,10 @@ func handleAuth(w http.ResponseWriter, req *http.Request) (string, int, error) { claims.Oid, ) if err != nil { - return "", http.StatusInternalServerError, wrapError(errUnexpectedDBError, err) + return "", -1, wrapError(errUnexpectedDBError, err) } } else { - return "", http.StatusInternalServerError, wrapError(errUnexpectedDBError, err) + return "", -1, wrapError(errUnexpectedDBError, err) } } diff --git a/endpoint_export_choices.go b/endpoint_export_choices.go index 80734b2..0705a3a 100644 --- a/endpoint_export_choices.go +++ b/endpoint_export_choices.go @@ -22,7 +22,6 @@ package main import ( "encoding/csv" - "fmt" "net/http" "strings" ) @@ -30,11 +29,7 @@ import ( func handleExportChoices(w http.ResponseWriter, req *http.Request) (string, int, error) { _, _, department, err := getUserInfoFromRequest(req) if err != nil { - wstr( - w, - http.StatusInternalServerError, - fmt.Sprintf("Error: %v", err), - ) + return "", -1, err } if department != staffDepartment { return "", http.StatusForbidden, errStaffOnly @@ -49,14 +44,14 @@ func handleExportChoices(w http.ResponseWriter, req *http.Request) (string, int, rows, err := db.Query(req.Context(), "SELECT userid, courseid FROM choices") if err != nil { - return "", http.StatusInternalServerError, wrapError(errUnexpectedDBError, err) + return "", -1, wrapError(errUnexpectedDBError, err) } output := make([][]string, 0) for { if !rows.Next() { err := rows.Err() if err != nil { - return "", http.StatusInternalServerError, wrapError(errUnexpectedDBError, err) + return "", -1, wrapError(errUnexpectedDBError, err) } break } @@ -64,7 +59,7 @@ func handleExportChoices(w http.ResponseWriter, req *http.Request) (string, int, var currentCourseID int err := rows.Scan(¤tUserID, ¤tCourseID) if err != nil { - return "", http.StatusInternalServerError, wrapError(errUnexpectedDBError, err) + return "", -1, wrapError(errUnexpectedDBError, err) } currentUserCache, ok := userCacheMap[currentUserID] if ok { @@ -83,7 +78,7 @@ func handleExportChoices(w http.ResponseWriter, req *http.Request) (string, int, ¤tDepartment, ) if err != nil { - return "", http.StatusInternalServerError, wrapError(errUnexpectedDBError, err) + return "", -1, wrapError(errUnexpectedDBError, err) } before, _, found := strings.Cut(currentUserEmail, "@") if found { @@ -100,14 +95,14 @@ func handleExportChoices(w http.ResponseWriter, req *http.Request) (string, int, _course, ok := courses.Load(currentCourseID) if !ok { - return "", http.StatusInternalServerError, wrapAny(errNoSuchCourse, currentCourseID) + return "", -1, wrapAny(errNoSuchCourse, currentCourseID) } course, ok := _course.(*courseT) if !ok { panic("courses map has non-\"*courseT\" items") } if course == nil { - return "", http.StatusInternalServerError, wrapAny(errNoSuchCourse, currentCourseID) + return "", -1, wrapAny(errNoSuchCourse, currentCourseID) } output = append( output, @@ -136,15 +131,15 @@ func handleExportChoices(w http.ResponseWriter, req *http.Request) (string, int, "Course ID", }) if err != nil { - return "", http.StatusInternalServerError, wrapError(errHTTPWrite, err) + return "", -1, wrapError(errHTTPWrite, err) } err = csvWriter.WriteAll(output) if err != nil { - return "", http.StatusInternalServerError, wrapError(errHTTPWrite, err) + return "", -1, wrapError(errHTTPWrite, err) } csvWriter.Flush() if csvWriter.Error() != nil { - return "", http.StatusInternalServerError, wrapError(errHTTPWrite, err) + return "", -1, wrapError(errHTTPWrite, err) } return "", -1, nil } diff --git a/endpoint_export_students.go b/endpoint_export_students.go index 932f7fd..6b616ee 100644 --- a/endpoint_export_students.go +++ b/endpoint_export_students.go @@ -29,22 +29,22 @@ import ( func handleExportStudents(w http.ResponseWriter, req *http.Request) (string, int, error) { _, _, department, err := getUserInfoFromRequest(req) if err != nil { - return "", http.StatusInternalServerError, err + return "", -1, err } if department != staffDepartment { - return "", http.StatusInternalServerError, errStaffOnly + return "", -1, errStaffOnly } rows, err := db.Query(req.Context(), "SELECT name, email, department, confirmed FROM users") if err != nil { - return "", http.StatusInternalServerError, wrapError(errUnexpectedDBError, err) + return "", -1, wrapError(errUnexpectedDBError, err) } output := make([][]string, 0) for { if !rows.Next() { err := rows.Err() if err != nil { - return "", http.StatusInternalServerError, wrapError(errUnexpectedDBError, err) + return "", -1, wrapError(errUnexpectedDBError, err) } break } @@ -57,7 +57,7 @@ func handleExportStudents(w http.ResponseWriter, req *http.Request) (string, int ¤tConfirmed, ) if err != nil { - return "", http.StatusInternalServerError, wrapError(errUnexpectedDBError, err) + return "", -1, wrapError(errUnexpectedDBError, err) } if currentDepartment == staffDepartment { @@ -88,15 +88,15 @@ func handleExportStudents(w http.ResponseWriter, req *http.Request) (string, int "Course ID", }) if err != nil { - return "", http.StatusInternalServerError, errHTTPWrite + return "", -1, errHTTPWrite } err = csvWriter.WriteAll(output) if err != nil { - return "", http.StatusInternalServerError, errHTTPWrite + return "", -1, errHTTPWrite } csvWriter.Flush() if csvWriter.Error() != nil { - return "", http.StatusInternalServerError, errHTTPWrite + return "", -1, errHTTPWrite } return "", -1, nil |