Skip to content

Commit

Permalink
feat: cleanup code
Browse files Browse the repository at this point in the history
  • Loading branch information
carddev81 committed Sep 23, 2024
1 parent fa7641b commit f1ec771
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 33 deletions.
31 changes: 0 additions & 31 deletions backend/src/handlers/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,6 @@ func (srv *Server) applyAdminMiddleware(h HttpFunc) http.Handler {
srv.handleError(h)))))
}

// func (srv *Server) applyAdminTestingMiddleware(h func(http.ResponseWriter, *http.Request)) http.HandlerFunc {
// return http.HandlerFunc(srv.authMiddleware(srv.adminMiddleware(h)))
// }

func corsMiddleware(next http.Handler) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
origin := r.Header.Get("Origin")
Expand Down Expand Up @@ -326,33 +322,6 @@ func (srv *Server) isTesting(r *http.Request) bool {
return r.Context().Value(TestingClaimsKey) != nil
}

// func (srv *Server) testAsAdmin(h http.Handler) http.Handler {
// return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// testClaims := &Claims{
// UserID: 1,
// PasswordReset: false,
// Role: models.Admin,
// FacilityID: 1,
// }
// ctx := context.WithValue(r.Context(), ClaimsKey, testClaims)
// test_ctx := context.WithValue(ctx, TestingClaimsKey, true)
// h.ServeHTTP(w, r.WithContext(test_ctx))
// })
// }
//
// func (srv *Server) testAsUser(h http.Handler) http.Handler {
// return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// testClaims := &Claims{
// UserID: 4,
// Role: models.Student,
// PasswordReset: false,
// FacilityID: 1,
// }
// ctx := context.WithValue(r.Context(), ClaimsKey, testClaims)
// h.ServeHTTP(w, r.WithContext(ctx))
// })
// }

func (srv *Server) getPaginationInfo(r *http.Request) (int, int) {
page := r.URL.Query().Get("page")
perPage := r.URL.Query().Get("per_page")
Expand Down
3 changes: 1 addition & 2 deletions backend/src/handlers/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ func TestMain(m *testing.M) {
}

func (srv *Server) applyAdminTestingMiddleware(h http.Handler) http.Handler {
return srv.adminMiddleware(h) //without ory kratos
//return http.HandlerFunc(srv.authMiddleware(srv.adminMiddleware(h)))//with kratos...
return srv.adminMiddleware(h)
}

func executeRequest(t *testing.T, req *http.Request, handler http.Handler, test httpTest) *httptest.ResponseRecorder {
Expand Down

0 comments on commit f1ec771

Please sign in to comment.