diff --git a/product-services/.air.toml b/product-services/.air.toml new file mode 100644 index 0000000..8a9be78 --- /dev/null +++ b/product-services/.air.toml @@ -0,0 +1,44 @@ +root = "." +testdata_dir = "testdata" +tmp_dir = "tmp" + +[build] + args_bin = [] + bin = "cmd/api/tmp/api.exe" + cmd = "go build -o ./cmd/api/tmp/api.exe ./cmd/api/main.go" + delay = 0 + exclude_dir = ["assets", "tmp", "vendor", "testdata"] + exclude_file = [] + exclude_regex = ["_test.go"] + exclude_unchanged = false + follow_symlink = false + full_bin = "" + include_dir = [] + include_ext = ["go", "tpl", "tmpl", "html"] + include_file = [] + kill_delay = "0s" + log = "build-errors.log" + poll = false + poll_interval = 0 + rerun = false + rerun_delay = 500 + send_interrupt = false + stop_on_error = false + +[color] + app = "" + build = "yellow" + main = "magenta" + runner = "green" + watcher = "cyan" + +[log] + main_only = false + time = false + +[misc] + clean_on_exit = false + +[screen] + clear_on_rebuild = false + keep_scroll = true diff --git a/product-services/.env b/product-services/.env index b11d71c..22b9361 100644 --- a/product-services/.env +++ b/product-services/.env @@ -4,6 +4,6 @@ DB_HOST=localhost DB_USER=admin -DB_NAME=footex +DB_NAME=microsample DB_PORT=5432 DB_PASSWORD=admin \ No newline at end of file diff --git a/product-services/cmd/api/main.go b/product-services/cmd/api/main.go index 3d82bbc..9e57244 100644 --- a/product-services/cmd/api/main.go +++ b/product-services/cmd/api/main.go @@ -9,7 +9,7 @@ import ( func main() { - cfg, confErr := config.LoadCOnfig() + cfg, confErr := config.LoadConfig() if confErr != nil { log.Fatal("cannot load config: ", confErr) diff --git a/product-services/cmd/api/tmp/api.exe b/product-services/cmd/api/tmp/api.exe new file mode 100755 index 0000000..9e66271 Binary files /dev/null and b/product-services/cmd/api/tmp/api.exe differ diff --git a/product-services/pkg/api/routes/product.go b/product-services/pkg/api/routes/product.go index 917a382..7bc1825 100644 --- a/product-services/pkg/api/routes/product.go +++ b/product-services/pkg/api/routes/product.go @@ -9,4 +9,19 @@ import ( func ProductRoute(api *gin.RouterGroup, ProductHandler handlerinterfaces.ProductHandler) { + product := api.Group("/product") + { + // Product Basic + product.POST("/add", ProductHandler.AddProduct) // Product Adding + product.PATCH("/:id", ProductHandler.UpdateProduct) // Product Update + product.DELETE("/:id", ProductHandler.DeteleProduct) // Product Delete + product.GET("/id", ProductHandler.GetProductById) // Product GetById + + // Listing + product.GET("/all", ProductHandler.ListFullProducts) // Full Products Listing + product.GET("/category/:name") // Products Listing By category4 + product.GET("/brand/:name") // Producr Listign By name + product.GET("/subcategory/:name") // Product Listign By sub-category + } + } diff --git a/product-services/pkg/api/server.go b/product-services/pkg/api/server.go index d7c7012..d23eee6 100644 --- a/product-services/pkg/api/server.go +++ b/product-services/pkg/api/server.go @@ -21,7 +21,7 @@ func NewServerHTTP(ProductHandler handlerinterfaces.ProductHandler) *ServerHTTP // For Swagger // Engine.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerfiles.Handler)) - routes.ProductRoute(Engine.Group("/admin"), + routes.ProductRoute(Engine.Group("/product"), ProductHandler, ) return &ServerHTTP{engine: Engine} diff --git a/product-services/pkg/config/config.go b/product-services/pkg/config/config.go index 60a4f91..4b92683 100644 --- a/product-services/pkg/config/config.go +++ b/product-services/pkg/config/config.go @@ -1,8 +1,6 @@ package config import ( - "os" - "github.com/go-playground/validator" "github.com/spf13/viper" ) @@ -19,28 +17,20 @@ var envs = []string{ "DB_HOST", "DB_NAME", "DB_USER", "DB_PORT", "DB_PASSWORD", // Database } -var config Config // for create instance - -func LoadCOnfig() (Config, error) { - - v := viper.New() +var config Config // create instence of config - // Get the current working directory - wd, err := os.Getwd() - if err != nil { - return config, err - } +// func to get env variable and store it on struct Config and retuen it with error as nil or error +func LoadConfig() (Config, error) { - //Viper setup - v.AddConfigPath(wd) - v.SetConfigFile(".env") - v.ReadInConfig() // for read config + // vipen setup + viper.AddConfigPath("./") // add config path + viper.SetConfigFile(".env") //setup file name to viper + viper.ReadInConfig() // read .env file - v.SetEnvPrefix("product-services") - v.AutomaticEnv() + // range through the envNames and take each envName and bind that env variable to viper for _, env := range envs { - if err := v.BindEnv(env); err != nil { + if err := viper.BindEnv(env); err != nil { return config, err // error handling } } @@ -58,7 +48,6 @@ func LoadCOnfig() (Config, error) { } //successfully loaded the env values into struct config - return config, nil } diff --git a/product-services/pkg/models/product.go b/product-services/pkg/models/product.go index 5393556..c769beb 100644 --- a/product-services/pkg/models/product.go +++ b/product-services/pkg/models/product.go @@ -5,6 +5,5 @@ type Product struct { ProductName string Discription string Price float64 - Quantity int Category string } diff --git a/product-services/tmp/build-errors.log b/product-services/tmp/build-errors.log new file mode 100644 index 0000000..c38c619 --- /dev/null +++ b/product-services/tmp/build-errors.log @@ -0,0 +1 @@ +exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1 \ No newline at end of file