-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
81 lines (68 loc) · 2.49 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
package main
import (
"final-project/controllers"
"final-project/database"
"final-project/middleware"
"final-project/repositories"
"final-project/services"
"fmt"
"github.com/gin-gonic/gin"
)
func main() {
// Initialize DB
db, err := database.ConnectDB(database.GoDotEnvVariable("DB_DRIVER"))
if err != nil {
fmt.Println("error :", err.Error())
return
}
userRepo := repositories.NewUserRepo(db)
userService := services.NewUserService(userRepo)
userController := controllers.NewUserController(userService)
photoRepo := repositories.NewPhotoRepo(db)
photoService := services.NewPhotoService(photoRepo)
photoController := controllers.NewPhotoController(photoService)
commentRepo := repositories.NewCommentRepo(db)
commentService := services.NewCommentService(commentRepo)
commentController := controllers.NewCommentController(commentService, photoService)
socialMediaRepo := repositories.NewSocialMediaRepo(db)
socialMediaService := services.NewSocialMediaService(socialMediaRepo)
socialMediaController := controllers.NewSocialMediaController(socialMediaService)
route := gin.Default()
// User
userRoute := route.Group("/users")
{
userRoute.POST("/register", userController.Register)
userRoute.POST("/login", userController.Login)
userRoute.Use(middleware.Auth())
userRoute.PUT("/:userId", userController.UpdateUser)
userRoute.DELETE("/:userId", userController.DeleteUser)
}
// Photo
photoRoute := route.Group("/photos")
{
photoRoute.Use(middleware.Auth())
photoRoute.POST("", photoController.CreatePhoto)
photoRoute.GET("", photoController.GetPhotos)
photoRoute.PUT("/:photoId", photoController.UpdatePhoto)
photoRoute.DELETE("/:photoId", photoController.DeletePhoto)
}
// Comment
commentRoute := route.Group("/comments")
{
commentRoute.Use(middleware.Auth())
commentRoute.POST("", commentController.CreateComment)
commentRoute.GET("", commentController.GetComments)
commentRoute.PUT("/:commentId", commentController.UpdateComment)
commentRoute.DELETE("/:commentId", commentController.DeleteComment)
}
// Social Media
socialMediaRoute := route.Group("/socialmedias")
{
socialMediaRoute.Use(middleware.Auth())
socialMediaRoute.POST("", socialMediaController.CreateSocialMedia)
socialMediaRoute.GET("", socialMediaController.GetSocialMedias)
socialMediaRoute.PUT("/:socialMediaId", socialMediaController.UpdateSocialMedia)
socialMediaRoute.DELETE("/:socialMediaId", socialMediaController.DeleteSocialMedia)
}
route.Run(database.GoDotEnvVariable("APP_PORT"))
}