func HandleCrudRead(modules *modules.Modules) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		meta := getRequestMetaData(r)
		ctx, cancel := context.WithTimeout(r.Context(), 5*time.Second)
		defer cancel()
		auth, err := modules.Auth(meta.projectID)
		if err != nil {
			w.Header().Set("Content-Type", "application/json")
			w.WriteHeader(http.StatusBadRequest)
			_ = json.NewEncoder(w).Encode(map[string]string{"error": err.Error()})
			return
		}
		crud, err := modules.DB(meta.projectID)
		if err != nil {
			w.Header().Set("Content-Type", "application/json")
			w.WriteHeader(http.StatusBadRequest)
			_ = json.NewEncoder(w).Encode(map[string]string{"error": err.Error()})
			return
		}
		req := model.ReadRequest{}
		_ = json.NewDecoder(r.Body).Decode(&req)
		defer utils.CloseTheCloser(r.Body)
		if req.Options == nil {
			req.Options = new(model.ReadOptions)
		}
		dbType, _ := crud.GetDBType(meta.dbType)
		returnWhere := model.ReturnWhereStub{Col: meta.col, PrefixColName: len(req.Options.Join) > 0, ReturnWhere: dbType != string(model.Mongo), Where: map[string]interface{}{}}
		actions, reqParams, err := auth.IsReadOpAuthorised(ctx, meta.projectID, meta.dbType, meta.col, meta.token, &req, returnWhere)
		if err != nil {
			_ = helpers.Response.SendErrorResponse(ctx, w, http.StatusForbidden, err)
			return
		}
		if len(returnWhere.Where) > 0 {
			req.MatchWhere = append(req.MatchWhere, returnWhere.Where)
		}
		if req.PostProcess == nil {
			req.PostProcess = map[string]*model.PostProcess{}
		}
		req.PostProcess[meta.col] = actions
		if err := auth.RunAuthForJoins(ctx, meta.projectID, dbType, meta.dbType, meta.token, &req, req.Options.Join); err != nil {
			_ = helpers.Response.SendErrorResponse(ctx, w, http.StatusForbidden, err)
			return
		}
		reqParams = utils.ExtractRequestParams(r, reqParams, req)
		result, _, err := crud.Read(ctx, meta.dbType, meta.col, &req, reqParams)
		if err != nil {
			_ = helpers.Response.SendErrorResponse(ctx, w, http.StatusInternalServerError, err)
			return
		}
		_ = authHelpers.PostProcessMethod(ctx, auth.GetAESKey(), actions, result)
		_ = helpers.Response.SendResponse(ctx, w, http.StatusOK, map[string]interface{}{"result": result})
	}
}
HandleCrudRead creates the read operation endpoint
package handlers
import (
	"context"
	"encoding/json"
	"net/http"
	"strings"
	"time"
	"github.com/gorilla/mux"
	"github.com/spaceuptech/helpers"
	"github.com/spaceuptech/space-cloud/gateway/model"
	"github.com/spaceuptech/space-cloud/gateway/modules"
	authHelpers "github.com/spaceuptech/space-cloud/gateway/modules/auth/helpers"
	"github.com/spaceuptech/space-cloud/gateway/utils"
)
type requestMetaData struct {
	projectID, dbType, col, token string
}
func HandleCrudPreparedQuery(modules *modules.Modules) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		ctx, cancel := context.WithTimeout(r.Context(), 30*time.Second)
		defer cancel()
		vars := mux.Vars(r)
		dbAlias := vars["dbAlias"]
		project := vars["project"]
		id := vars["id"]
		token := utils.GetTokenFromHeader(r)
		auth, err := modules.Auth(project)
		if err != nil {
			_ = helpers.Response.SendErrorResponse(ctx, w, http.StatusInternalServerError, err)
			return
		}
		crud, err := modules.DB(project)
		if err != nil {
			_ = helpers.Response.SendErrorResponse(ctx, w, http.StatusInternalServerError, err)
			return
		}
		req := model.PreparedQueryRequest{}
		_ = json.NewDecoder(r.Body).Decode(&req)
		defer utils.CloseTheCloser(r.Body)
		actions, reqParams, err := auth.IsPreparedQueryAuthorised(ctx, project, dbAlias, id, token, &req)
		if err != nil {
			_ = helpers.Response.SendErrorResponse(ctx, w, http.StatusForbidden, err)
			return
		}
		reqParams = utils.ExtractRequestParams(r, reqParams, req)
		result, _, err := crud.ExecPreparedQuery(ctx, dbAlias, id, &req, reqParams)
		if err != nil {
			_ = helpers.Response.SendErrorResponse(ctx, w, http.StatusInternalServerError, err)
			return
		}
		_ = authHelpers.PostProcessMethod(ctx, auth.GetAESKey(), actions, result)
		_ = helpers.Response.SendResponse(ctx, w, http.StatusOK, map[string]interface{}{"result": result})
	}
}
func HandleCrudCreate(modules *modules.Modules) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		meta := getRequestMetaData(r)
		ctx, cancel := context.WithTimeout(r.Context(), time.Duration(utils.DefaultContextTime)*time.Second)
		defer cancel()
		auth, err := modules.Auth(meta.projectID)
		if err != nil {
			w.Header().Set("Content-Type", "application/json")
			w.WriteHeader(http.StatusBadRequest)
			_ = json.NewEncoder(w).Encode(map[string]string{"error": err.Error()})
			return
		}
		crud, err := modules.DB(meta.projectID)
		if err != nil {
			w.Header().Set("Content-Type", "application/json")
			w.WriteHeader(http.StatusBadRequest)
			_ = json.NewEncoder(w).Encode(map[string]string{"error": err.Error()})
			return
		}
		req := model.CreateRequest{}
		_ = json.NewDecoder(r.Body).Decode(&req)
		defer utils.CloseTheCloser(r.Body)
		reqParams, err := auth.IsCreateOpAuthorised(ctx, meta.projectID, meta.dbType, meta.col, meta.token, &req)
		if err != nil {
			_ = helpers.Response.SendErrorResponse(ctx, w, http.StatusForbidden, err)
			return
		}
		reqParams = utils.ExtractRequestParams(r, reqParams, req)
		err = crud.Create(ctx, meta.dbType, meta.col, &req, reqParams)
		if err != nil {
			_ = helpers.Response.SendErrorResponse(ctx, w, http.StatusInternalServerError, err)
			return
		}
		_ = helpers.Response.SendOkayResponse(ctx, http.StatusOK, w)
	}
}