-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
97 lines (79 loc) · 2.42 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
package main
import (
"backend-go/handlers/categories"
"backend-go/handlers/events"
"backend-go/handlers/ml"
"backend-go/handlers/reviews"
"backend-go/handlers/users"
"backend-go/middlewares"
"backend-go/mongodb"
"backend-go/utils"
"net/http"
"os"
_ "cloud.google.com/go/datastore"
_ "backend-go/docs"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
swaggerFiles "github.com/swaggo/files"
ginSwagger "github.com/swaggo/gin-swagger"
)
func init() {
utils.LoadEnv()
utils.InitGCS()
mongodb.ConnectDB()
mongodb.InitCollections()
}
// @title Match-Event Backend API
// @version 1.0
// @description A matchmaking service API in Go using Gin framework.
// @license.name Apache 2.0
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html
// @BasePath /
func main() {
defer mongodb.Client.Disconnect(mongodb.Context)
router := gin.Default()
router.Use(cors.Default())
router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler)) // http://[HOST_URL]/swagger/index.html
router.GET("/", func(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"message": "API is up and running!",
})
})
auth := router.Group("/auth")
{
auth.POST("/register", users.Register)
auth.POST("/login", users.Login)
}
user := router.Group("/users")
{
user.GET("/", middlewares.RequireAuth, users.GetUserInfo)
user.PUT("/", middlewares.RequireAuth, users.UpdateUser)
user.GET("/:id", users.GetUserById)
}
event := router.Group("/events")
{
event.GET("/", events.GetEvents)
event.GET("/:id", events.GetEventById)
event.GET("/popular", ml.GetPopularEvents)
event.GET("/reco", middlewares.RequireAuth, ml.GetRecommendedEvents)
event.POST("/", events.CreateEvent)
event.PUT("/:id", events.UpdateEvent)
event.DELETE("/:id", events.DeleteEvent)
event.POST("/:id/join", middlewares.RequireAuth, events.JoinEvent)
event.POST("/:id/image", events.UploadEventImage)
}
review := router.Group("/reviews")
{
review.GET("/:event_id", reviews.GetReviews)
review.POST("/:event_id", middlewares.RequireAuth, reviews.CreateReview)
review.DELETE("/:id", middlewares.RequireAuth, reviews.DeleteReview)
}
category := router.Group("/categories")
{
category.GET("/", categories.GetCategories)
category.POST("/", categories.CreateCategory)
category.PUT("/:id", categories.UpdateCategory)
category.DELETE("/:id", categories.DeleteCategory)
}
router.Run(":" + os.Getenv("PORT"))
}