forked from nifz/online-store
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
85 lines (67 loc) · 2.81 KB
/
main.go
File metadata and controls
85 lines (67 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package main
import (
"log"
"online-store/configs"
"online-store/controllers"
"online-store/repositories"
"online-store/routes"
"online-store/services"
"os"
"github.com/gin-gonic/gin"
"github.com/joho/godotenv"
_ "online-store/docs"
swaggerFiles "github.com/swaggo/files"
ginSwagger "github.com/swaggo/gin-swagger"
)
// @title Online Store Challenge API
// @version 1.0
// @description Software Engineer Challenge PT. Synapsis Sinergi Digital.
// @termsOfService http://swagger.io/terms/
// @contact.name Mochammad Hanif
// @contact.url http://www.github.com/nifz
// @contact.email ochammadhanif@gmail.com
// @license.name Apache 2.0
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html
// @host online-store-hanif.up.railway.app
// @BasePath /
// @securityDefinitions.apikey BearerAuth
// @in header
// @name Authorization
// @externalDocs.description OpenAPI
// @externalDocs.url https://swagger.io/resources/open-api/
func main() {
_ = godotenv.Load()
port := os.Getenv("PORT")
dbUsername := os.Getenv("DATABASE_USERNAME")
dbPassword := os.Getenv("DATABASE_PASSWORD")
dbHost := os.Getenv("DATABASE_HOST")
dbPort := os.Getenv("DATABASE_PORT")
dbName := os.Getenv("DATABASE_NAME")
db, err := configs.GetDatabase(dbUsername, dbPassword, dbHost, dbPort, dbName)
if err != nil {
log.Fatal(err.Error())
}
userRepository := repositories.NewUserRepository(db)
userService := services.NewUserService(userRepository)
userController := controllers.NewUserController(userService)
categoryRepository := repositories.NewCategoryRepositories(db)
categoryService := services.NewCategoryServices(categoryRepository)
categoryController := controllers.NewCategoryController(categoryService)
productRepository := repositories.NewProductRepositories(db)
productService := services.NewProductServices(productRepository, categoryRepository)
productController := controllers.NewProductController(productService)
cartRepository := repositories.NewCartRepository(db)
cartService := services.NewCartService(cartRepository, productRepository, userRepository, categoryRepository)
cartController := controllers.NewCartController(cartService)
transactionRepository := repositories.NewTransactionRepository(db)
transactionService := services.NewTransactionService(transactionRepository, productRepository, userRepository, categoryRepository)
transactionController := controllers.NewTransactionController(transactionService)
router := gin.Default()
routes.UserRoute(router, userController)
routes.CategoryRoutes(router, categoryController)
routes.ProductRoutes(router, productController)
routes.CartRoute(router, cartController)
routes.TransactionRoute(router, transactionController)
router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
router.Run(":" + port)
}