Initialize repository

This commit is contained in:
eikendev 2020-07-26 00:28:38 +02:00
commit 1d758fcfd0
No known key found for this signature in database
GPG key ID: A1BDB1B28C8EF694
28 changed files with 1107 additions and 0 deletions

45
router/router.go Normal file
View file

@ -0,0 +1,45 @@
package router
import (
"log"
"github.com/eikendev/pushbits/api"
"github.com/eikendev/pushbits/authentication"
"github.com/eikendev/pushbits/database"
"github.com/eikendev/pushbits/dispatcher"
"github.com/gin-contrib/location"
"github.com/gin-gonic/gin"
)
// Create a Gin engine and setup all routes.
func Create(db *database.Database, dp *dispatcher.Dispatcher) *gin.Engine {
log.Println("Setting up HTTP routes.")
auth := authentication.Authenticator{DB: db}
applicationHandler := api.ApplicationHandler{DB: db, Dispatcher: dp}
notificationHandler := api.NotificationHandler{DB: db, Dispatcher: dp}
userHandler := api.UserHandler{DB: db}
r := gin.Default()
r.Use(location.Default())
applicationGroup := r.Group("/application")
applicationGroup.Use(auth.RequireUser())
{
applicationGroup.POST("", applicationHandler.CreateApplication)
//applicationGroup.DELETE("/:id", applicationHandler.DeleteApplication)
}
r.POST("/message", auth.RequireApplicationToken(), notificationHandler.CreateNotification)
userGroup := r.Group("/user")
userGroup.Use(auth.RequireAdmin())
{
userGroup.POST("", userHandler.CreateUser)
//userGroup.DELETE("/:id", userHandler.DeleteUser)
}
return r
}