diff --git a/internal/db/db_test.go b/internal/db/db_test.go index 075b131..607bbad 100644 --- a/internal/db/db_test.go +++ b/internal/db/db_test.go @@ -20,6 +20,6 @@ func TestInitDBConn(t *testing.T) { malformedConnUrl := "postgres://malformed" cfg = utils.NewPGConfig(&malformedConnUrl, nil) - conn, err = InitDBConn(lib.PSQL, cfg) + _, err = InitDBConn(lib.PSQL, cfg) assert.Error(t, err) } diff --git a/internal/handlers/defaultHandler.go b/internal/handlers/defaultHandler.go index 40994ef..8a3fd6a 100644 --- a/internal/handlers/defaultHandler.go +++ b/internal/handlers/defaultHandler.go @@ -37,9 +37,9 @@ func (h *DefaultHandler) healthCheck(w http.ResponseWriter, r *http.Request) { type APIInfoResult struct { Author string `json:"author"` - Year int `json:"yeaer"` Contact string `json:"contact"` Repo string `json:"repo"` + Year int `json:"yeaer"` } // Get info about the api diff --git a/internal/server.go b/internal/server.go index a97d666..810d7a5 100644 --- a/internal/server.go +++ b/internal/server.go @@ -17,14 +17,14 @@ import ( type Server struct { storage db.Storage - port int router *chi.Mux listenCh chan bool + port int } func NewServer(storage db.Storage, port int, listenCh chan bool) *Server { r := chi.NewRouter() - return &Server{storage, port, r, listenCh} + return &Server{storage, r, listenCh, port} } func (s *Server) Serve() error { diff --git a/lib/validator.go b/lib/validator.go index 3cfd808..91d6c3a 100644 --- a/lib/validator.go +++ b/lib/validator.go @@ -5,10 +5,10 @@ import ( ) type ErrorResponse struct { - Error bool `json:"error"` + Value interface{} `json:"value"` FailedField string `json:"failed_field"` Tag string `json:"tag"` - Value interface{} `json:"value"` + Error bool `json:"error"` } var validate *validator.Validate diff --git a/models/common.go b/models/common.go index d5681c1..4ac6ae8 100644 --- a/models/common.go +++ b/models/common.go @@ -5,6 +5,6 @@ type SuccessResp struct { } type ErrResp struct { - Code int `json:"code"` Message any `json:"message"` + Code int `json:"code"` } diff --git a/models/tables.go b/models/tables.go index 54b2ee8..a8f55b3 100644 --- a/models/tables.go +++ b/models/tables.go @@ -5,19 +5,19 @@ type ListTablesResp struct { } type TableInfoResp struct { + Key any `db:"key" json:"key"` + Default any `db:"default" json:"default"` Name string `db:"name" json:"name"` Type string `db:"type" json:"type"` Nullable string `db:"nullable" json:"nullable"` - Key any `db:"key" json:"key"` - Default any `db:"default" json:"default"` } type CreateTablePayload struct { - ColName string `json:"column_name" validate:"required,alphanum"` - Type string `json:"type" validate:"required,ascii"` Nullable interface{} `json:"nullable" validate:"omitempty,boolean"` Default interface{} `json:"default" validate:"omitempty,alphanum" ` Unique interface{} `json:"unique" validate:"omitempty,boolean"` + ColName string `json:"column_name" validate:"required,alphanum"` + Type string `json:"type" validate:"required,ascii"` } type CreateTableResp struct { diff --git a/utils/handlers.go b/utils/handlers.go deleted file mode 100644 index a0b3ba0..0000000 --- a/utils/handlers.go +++ /dev/null @@ -1,25 +0,0 @@ -package utils - -import ( - "net/http" - - "github.com/gofiber/fiber/v2" - "github.com/jmoiron/sqlx" - "github.com/valyala/fasthttp/fasthttpadaptor" -) - -type RouteHandlerFunc func(*fiber.Ctx, *sqlx.DB) error - -func RouteHandler(db *sqlx.DB, routeHandlerFunc RouteHandlerFunc) fiber.Handler { - fn := func(c *fiber.Ctx) error { - return routeHandlerFunc(c, db) - } - - return fn -} - -func GraphQLHandler(f func(http.ResponseWriter, *http.Request)) func(ctx *fiber.Ctx) { - return func(ctx *fiber.Ctx) { - fasthttpadaptor.NewFastHTTPHandler(http.HandlerFunc(f))(ctx.Context()) - } -} diff --git a/utils/handlers_test.go b/utils/handlers_test.go deleted file mode 100644 index 81e5545..0000000 --- a/utils/handlers_test.go +++ /dev/null @@ -1,38 +0,0 @@ -package utils - -import ( - "net/http" - "testing" - - "github.com/gofiber/fiber/v2" - "github.com/jmoiron/sqlx" - _ "github.com/mattn/go-sqlite3" - "github.com/stretchr/testify/assert" - "github.com/valyala/fasthttp" -) - -func TestRouteHandler(t *testing.T) { - - mockRouteHandlerFunc := func(*fiber.Ctx, *sqlx.DB) error { - return nil - } - - con, _ := sqlx.Open("sqlite3", ":memory:") - defer con.Close() - - err := RouteHandler(con, mockRouteHandlerFunc)(&fiber.Ctx{}) - - assert.Nil(t, err) - -} - -func TestGraphQLHandler(t *testing.T) { - app := fiber.New() - c := app.AcquireCtx(&fasthttp.RequestCtx{}) - - mockGraphQLHandlerFunc := func(http.ResponseWriter, *http.Request) {} - - handler := GraphQLHandler(mockGraphQLHandlerFunc) - - assert.NotPanics(t, func() { handler(c) }) -}