Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Current user #36

Merged
merged 14 commits into from
Jul 26, 2024
1 change: 1 addition & 0 deletions .github/workflows/example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:

env:
DATABASE_URL: ${{secrets.DATABASE_URL}}
COOKIESTORE: ${{secrets.COOKIESTORE}}
# FIREBASE_ADMIN_PASSPHRASE: ${{secrets.FIREBASE_ADMIN_PASSPHRASE}}

jobs:
Expand Down
70 changes: 29 additions & 41 deletions adminHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,7 @@ func AdminHandler(router *mux.Router) {
vars := mux.Vars(req)
googleID := vars["googleID"]

currentUser, err := GetCurrentUser(req)
if err != nil {
http.Error(res, err.Error(), http.StatusInternalServerError)
return
}

student, err := readStudent(currentUser, googleID)
student, err := readStudent(googleID, req)
if err != nil {
http.Error(res, err.Error(), http.StatusInternalServerError)
return
Expand All @@ -67,15 +61,9 @@ func AdminHandler(router *mux.Router) {
vars := mux.Vars(req)
googleID := vars["googleID"]

currentUser, err := GetCurrentUser(req)
if err != nil {
http.Error(res, err.Error(), http.StatusInternalServerError)
return
}

switch req.Method {
case http.MethodGet:
student, err := readStudent(currentUser, googleID)
student, err := readStudent(googleID, req)
if err != nil {
http.Error(res, err.Error(), http.StatusInternalServerError)
return
Expand All @@ -88,7 +76,7 @@ func AdminHandler(router *mux.Router) {
http.Error(res, err.Error(), http.StatusBadRequest)
return
}
if err := updateStudent(currentUser, googleID, updates); err != nil {
if err := updateStudent(googleID, updates, req); err != nil {
http.Error(res, err.Error(), http.StatusInternalServerError)
return
}
Expand Down Expand Up @@ -120,13 +108,13 @@ func AdminHandler(router *mux.Router) {
vars := mux.Vars(req)
googleID := vars["googleID"]

currentUser, err := GetCurrentUser(req)
if err != nil {
http.Error(res, "Unauthorized", http.StatusUnauthorized)
return
}
// currentUser, err := GetCurrentUser(req)
// if err != nil {
// http.Error(res, "Unauthorized", http.StatusUnauthorized)
// return
// }

parent, err := readParent(currentUser, googleID)
parent, err := readParent(googleID, req)
if err != nil {
http.Error(res, err.Error(), http.StatusInternalServerError)
return
Expand All @@ -144,15 +132,15 @@ func AdminHandler(router *mux.Router) {
vars := mux.Vars(req)
googleID := vars["googleID"]

currentUser, err := GetCurrentUser(req)
if err != nil {
http.Error(res, "Unauthorized", http.StatusUnauthorized)
return
}
// currentUser, err := GetCurrentUser(req)
// if err != nil {
// http.Error(res, "Unauthorized", http.StatusUnauthorized)
// return
// }

switch req.Method {
case http.MethodGet:
parent, err := readParent(currentUser, googleID)
parent, err := readParent(googleID, req)
if err != nil {
http.Error(res, err.Error(), http.StatusInternalServerError)
return
Expand All @@ -165,7 +153,7 @@ func AdminHandler(router *mux.Router) {
http.Error(res, err.Error(), http.StatusBadRequest)
return
}
if err := updateParent(currentUser, googleID, updates); err != nil {
if err := updateParent(googleID, updates, req); err != nil {
http.Error(res, err.Error(), http.StatusInternalServerError)
return
}
Expand Down Expand Up @@ -197,13 +185,13 @@ func AdminHandler(router *mux.Router) {
vars := mux.Vars(req)
googleID := vars["googleID"]

currentUser, err := GetCurrentUser(req)
if err != nil {
http.Error(res, "Unauthorized", http.StatusUnauthorized)
return
}
// currentUser, err := GetCurrentUser(req)
// if err != nil {
// http.Error(res, "Unauthorized", http.StatusUnauthorized)
// return
// }

instructor, err := readInstructor(currentUser, googleID)
instructor, err := readInstructor(googleID, req)
if err != nil {
http.Error(res, err.Error(), http.StatusInternalServerError)
return
Expand All @@ -221,15 +209,15 @@ func AdminHandler(router *mux.Router) {
vars := mux.Vars(req)
googleID := vars["googleID"]

currentUser, err := GetCurrentUser(req)
if err != nil {
http.Error(res, "Unauthorized", http.StatusUnauthorized)
return
}
// currentUser, err := GetCurrentUser(req)
// if err != nil {
// http.Error(res, "Unauthorized", http.StatusUnauthorized)
// return
// }

switch req.Method {
case http.MethodGet:
instructor, err := readInstructor(currentUser, googleID)
instructor, err := readInstructor(googleID, req)
if err != nil {
http.Error(res, err.Error(), http.StatusInternalServerError)
return
Expand All @@ -242,7 +230,7 @@ func AdminHandler(router *mux.Router) {
http.Error(res, err.Error(), http.StatusBadRequest)
return
}
if err := updateInstructor(currentUser, googleID, updates); err != nil {
if err := updateInstructor(googleID, updates, req); err != nil {
http.Error(res, err.Error(), http.StatusInternalServerError)
return
}
Expand Down
Loading
Loading