Skip to content

Commit

Permalink
Current user (#36)
Browse files Browse the repository at this point in the history
* Changed database CRUD to grab user info from session

* Changed adminHandler.go to grab user from session

* missed out on changing delete instructor

* test

* added tests to get current user + session

* typo in createAnnouncement

* Changed database to use getCurrrentUser function, tested successfully

* correcting errors made during resolving merge conflicts

* test

* TEST

* test again

* test again 2

* .
  • Loading branch information
APandamonium1 authored Jul 26, 2024
1 parent 3b25b64 commit fd2b5a7
Show file tree
Hide file tree
Showing 5 changed files with 353 additions and 243 deletions.
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

0 comments on commit fd2b5a7

Please sign in to comment.