Added authorization
This commit is contained in:
parent
c3c3d65d32
commit
b96dd39795
50 changed files with 685 additions and 410 deletions
|
|
@ -2,27 +2,41 @@ package interfaces
|
|||
|
||||
import (
|
||||
"58team_blog/internal/application/services"
|
||||
"58team_blog/internal/infrastructure"
|
||||
"58team_blog/internal/interfaces/api/controllers"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func BindPostAdmin(service *services.PostService, group *gin.RouterGroup) {
|
||||
post := controllers.CreatePostController(service)
|
||||
func BindPostAdmin(service *services.PostService, userService *services.UserService, group *gin.RouterGroup) {
|
||||
post := controllers.CreatePostController(service, userService)
|
||||
|
||||
g := group.Group("/post")
|
||||
g.GET("/", post.GetAll)
|
||||
g.GET("/offset/:offset", post.GetAllWithOffset)
|
||||
g.GET("/:id", post.GetById)
|
||||
g.Use(infrastructure.AuthRequired)
|
||||
|
||||
g.POST("/", post.Post)
|
||||
g.PUT("/:id", post.Put)
|
||||
g.DELETE("/:id", post.Delete)
|
||||
}
|
||||
|
||||
func BindUser(service *services.UserService, group *gin.RouterGroup) {
|
||||
user := controllers.CreateUserController(service)
|
||||
func BindPost(service *services.PostService, userService *services.UserService, group *gin.RouterGroup) {
|
||||
post := controllers.CreatePostController(service, userService)
|
||||
g := group.Group("/post")
|
||||
|
||||
g.GET("/", post.GetAll)
|
||||
g.GET("/offset/:offset", post.GetAllWithOffset)
|
||||
g.GET("/:id", post.GetById)
|
||||
}
|
||||
|
||||
func BindUser(adminName string, adminPass string, service *services.UserService, group *gin.RouterGroup) {
|
||||
user := controllers.CreateUserController(service, adminName, adminPass)
|
||||
|
||||
group.POST("/login", user.Login)
|
||||
group.GET("/logout", user.Logout)
|
||||
|
||||
g := group.Group("/user/")
|
||||
g.Use(infrastructure.AuthRequired)
|
||||
|
||||
g.POST("/", user.Post)
|
||||
g.GET("/", user.GetAll)
|
||||
g.GET("/:id", user.FindById)
|
||||
|
|
@ -30,3 +44,12 @@ func BindUser(service *services.UserService, group *gin.RouterGroup) {
|
|||
g.PUT("/:id", user.Put)
|
||||
g.DELETE("/:id", user.Delete)
|
||||
}
|
||||
|
||||
func BindImages(images_path string, service *services.ImagesService, group *gin.RouterGroup) {
|
||||
images := controllers.CreateImagesController(images_path, service)
|
||||
|
||||
g := group.Group("/images/")
|
||||
g.POST("/", images.PostImage)
|
||||
g.GET("/:path", images.GetImage)
|
||||
g.DELETE("/:path", images.DeleteImage)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue