-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
103 lines (75 loc) · 2.81 KB
/
main.go
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package main
import (
"fmt"
"log"
"os"
"service-user-investor/auth"
"service-user-investor/config"
"service-user-investor/core"
"service-user-investor/database"
"service-user-investor/handler"
"service-user-investor/middleware"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
"github.com/joho/godotenv"
)
func main() {
// env
err := godotenv.Load()
if err != nil {
log.Fatal("Error loading .env file")
}
// setup log if Production Mode
// config.InitLog()
// SETUP REPO
db := database.NewConnectionDB()
userInvestorRepository := core.NewRepository(db)
// SETUP SERVICE
userInvestorService := core.NewService(userInvestorRepository)
authService := auth.NewService()
// setup handler
userHandler := handler.NewUserHandler(userInvestorService, authService)
// END SETUP
// RUN SERVICE
router := gin.Default()
// setup cors
corsConfig := config.InitCors()
router.Use(cors.New(corsConfig))
// group api
api := router.Group("api/v1")
// admin request
api.GET("/admin/log_service_toAdmin/:admin_id", userHandler.GetLogtoAdmin)
api.GET("/admin/service_status/:admin_id", userHandler.ServiceHealth)
// make endpoint deactive user
api.POST("/admin/deactive_user/:admin_id", userHandler.DeactiveUser)
api.POST("/admin/active_user/:admin_id", userHandler.ActiveUser)
// make endpoint get all user by admin
// make endpoint update user by admin
// make update password by admin
// make delete user by admin
// make
// Rounting start for investor
// starting endpoint
//make service health for investor
api.GET("/service_start", userHandler.ServiceStart)
api.GET("/service_check", middleware.AuthMiddleware(authService, userInvestorService), userHandler.ServiceCheckDB)
api.POST("/register_investor", userHandler.RegisterUser)
api.POST("/login_investor", userHandler.Login)
api.POST("/email_check", userHandler.CheckEmailAvailability)
api.POST("/phone_check", userHandler.CheckPhoneAvailability)
//make get user by auth
api.GET("/get_user", middleware.AuthMiddleware(authService, userInvestorService), userHandler.GetUser)
//make update profile user by unix_id
api.PUT("/update_profile/:unix_id", middleware.AuthMiddleware(authService, userInvestorService), userHandler.UpdateUser)
//make update password user by unix_id
api.PUT("/update_password/:unix_id", middleware.AuthMiddleware(authService, userInvestorService), userHandler.UpdatePassword)
//make create image profile user by unix_id
//make update image profile user by unix_id
//make delete image profile user by unix_id
// make logout user by unix_id
api.POST("/logout_investor", middleware.AuthMiddleware(authService, userInvestorService), userHandler.LogoutUser)
// end Rounting
// make env SERVICE_HOST and SERVICE_PORT
url := fmt.Sprintf("%s:%s", os.Getenv("SERVICE_HOST"), os.Getenv("SERVICE_PORT"))
router.Run(url)
}