-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ec4e825
commit a082e5f
Showing
9 changed files
with
134 additions
and
22 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
{ | ||
"swagger": "2.0", | ||
"info": { | ||
"description": "A RESTFull and GraphQL API to manage your MySQL DB", | ||
"description": "A RESTFull and GraphQL API to supercharge your database", | ||
"title": "MetaX", | ||
"contact": { | ||
"name": "Kareem Ebrahim", | ||
"email": "[email protected]" | ||
}, | ||
"version": "1.0" | ||
"version": "0.1.1" | ||
}, | ||
"host": "localhost:5522", | ||
"basePath": "/", | ||
|
@@ -331,6 +331,31 @@ | |
} | ||
}, | ||
"definitions": { | ||
"handlers.APIInfoResult": { | ||
"type": "object", | ||
"properties": { | ||
"author": { | ||
"type": "string" | ||
}, | ||
"contact": { | ||
"type": "string" | ||
}, | ||
"repo": { | ||
"type": "string" | ||
}, | ||
"year": { | ||
"type": "integer" | ||
} | ||
} | ||
}, | ||
"handlers.HealthCheckResult": { | ||
"type": "object", | ||
"properties": { | ||
"date": { | ||
"type": "string" | ||
} | ||
} | ||
}, | ||
"models.AddModifyColumnPayload": { | ||
"type": "object", | ||
"required": [ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,21 @@ | ||
basePath: / | ||
definitions: | ||
handlers.APIInfoResult: | ||
properties: | ||
author: | ||
type: string | ||
contact: | ||
type: string | ||
repo: | ||
type: string | ||
year: | ||
type: integer | ||
type: object | ||
handlers.HealthCheckResult: | ||
properties: | ||
date: | ||
type: string | ||
type: object | ||
models.AddModifyColumnPayload: | ||
properties: | ||
column_name: | ||
|
@@ -93,9 +109,9 @@ info: | |
contact: | ||
email: [email protected] | ||
name: Kareem Ebrahim | ||
description: A RESTFull and GraphQL API to manage your MySQL DB | ||
description: A RESTFull and GraphQL API to supercharge your database | ||
title: MetaX | ||
version: "1.0" | ||
version: 0.1.1 | ||
paths: | ||
/: | ||
get: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package db | ||
|
||
import "github.com/kareemmahlees/meta-x/models" | ||
|
||
// Interface that must be implemented by any | ||
// storage driver dealing with database logic | ||
type DatabaseExecuter interface { | ||
ListDBs() ([]*string, error) | ||
CreateDB(dbName string) error | ||
} | ||
|
||
// Interface that must be implemented by any | ||
// storage driver dealing with table logic | ||
type TableExecuter interface { | ||
GetTable(tableName string) ([]*models.TableInfoResp, error) | ||
ListTables() ([]*string, error) | ||
CreateTable(tableName string, data []models.CreateTablePayload) error | ||
DeleteTable(tableName string) error | ||
AddColumn(tableName string, data models.AddModifyColumnPayload) error | ||
UpdateColumn(tableName string, data models.AddModifyColumnPayload) error | ||
} | ||
|
||
type Storage interface { | ||
DatabaseExecuter | ||
TableExecuter | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,23 @@ | ||
package routes | ||
package handlers | ||
|
||
import ( | ||
"time" | ||
|
||
_ "github.com/kareemmahlees/meta-x/docs" | ||
|
||
"github.com/gofiber/fiber/v2" | ||
"github.com/kareemmahlees/meta-x/internal/db" | ||
) | ||
|
||
func RegisterDefaultRoutes(app *fiber.App) { | ||
app.Get("/health", healthCheck) | ||
app.Get("/", apiInfo) | ||
type defaultHandler struct { | ||
storage *db.Storage | ||
} | ||
|
||
func NewDefaultHandler(storage *db.Storage) *defaultHandler { | ||
return &defaultHandler{storage} | ||
} | ||
|
||
func (h *defaultHandler) RegisterRoutes(app *fiber.App) { | ||
app.Get("/health", h.healthCheck) | ||
app.Get("/", h.apiInfo) | ||
} | ||
|
||
type HealthCheckResult struct { | ||
|
@@ -24,7 +31,7 @@ type HealthCheckResult struct { | |
// @tags default | ||
// @router /health [get] | ||
// @success 200 {object} HealthCheckResult | ||
func healthCheck(c *fiber.Ctx) error { | ||
func (h *defaultHandler) healthCheck(c *fiber.Ctx) error { | ||
return c.JSON(fiber.Map{"date": time.Now()}) | ||
} | ||
|
||
|
@@ -42,11 +49,11 @@ type APIInfoResult struct { | |
// @tags default | ||
// @router / [get] | ||
// @success 200 {object} APIInfoResult | ||
func apiInfo(c *fiber.Ctx) error { | ||
func (h *defaultHandler) apiInfo(c *fiber.Ctx) error { | ||
return c.JSON(fiber.Map{ | ||
"author": "Kareem Ebrahim", | ||
"year": 2023, | ||
"contact": "[email protected]", | ||
"repo": "https://github.com/kareemmahlees/mysql-meta", | ||
"repo": "https://github.com/kareemmahlees/meta-x", | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package handlers | ||
|
||
import "github.com/gofiber/fiber/v2" | ||
|
||
type Handler interface { | ||
RegisterRoutes(app *fiber.App) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters