update auth api with session

This commit is contained in:
steven
2021-12-10 13:41:17 +08:00
parent a08ad0ebab
commit 050c2ccbd5
15 changed files with 143 additions and 90 deletions

View File

@@ -10,7 +10,7 @@ import (
)
func handleGetMyQueries(w http.ResponseWriter, r *http.Request) {
userId, _ := GetUserIdInCookie(r)
userId, _ := GetUserIdInSession(r)
queries, err := store.GetQueriesByUserId(userId)
@@ -32,7 +32,7 @@ type QueryPut struct {
}
func handleCreateQuery(w http.ResponseWriter, r *http.Request) {
userId, _ := GetUserIdInCookie(r)
userId, _ := GetUserIdInSession(r)
queryPut := QueryPut{}
err := json.NewDecoder(r.Body).Decode(&queryPut)
@@ -103,6 +103,8 @@ func handleDeleteQuery(w http.ResponseWriter, r *http.Request) {
func RegisterQueryRoutes(r *mux.Router) {
queryRouter := r.PathPrefix("/api/query").Subrouter()
queryRouter.Use(AuthCheckerMiddleWare)
queryRouter.HandleFunc("/all", handleGetMyQueries).Methods("GET")
queryRouter.HandleFunc("/", handleCreateQuery).Methods("PUT")
queryRouter.HandleFunc("/{id}", handleUpdateQuery).Methods("PATCH")