recommender/internal/router/api.go
2024-11-08 02:25:15 +08:00

49 lines
1.2 KiB
Go

package router
import (
"github.com/gin-gonic/gin"
"leafdev.top/Ecosystem/recommender/internal/handler/http"
)
// 两种方法都可以
//type Api struct {
// User *v1.UserController
//}
type Api struct {
h *http.Handlers
}
func NewApiRoute(
h *http.Handlers,
) *Api {
return &Api{
h,
}
}
func (a *Api) InitApiRouter(r *gin.RouterGroup) {
r.GET("/applications", a.h.ApplicationController.List)
r.POST("/applications", a.h.ApplicationController.Save)
r.GET("/application/:application_id/tokens", a.h.ApplicationController.ListToken)
r.POST("/application/:application_id/tokens", a.h.ApplicationController.SaveToken)
}
func (a *Api) InitNoAuthApiRouter(r *gin.RouterGroup) {
}
func (a *Api) InitApplicationApi(r *gin.RouterGroup) {
r.GET("/info", a.h.ApplicationApi.Info)
r.GET("/posts", a.h.ApplicationPostApi.List)
r.POST("/posts", a.h.ApplicationPostApi.Save)
r.DELETE("/post/:post_id", a.h.ApplicationPostApi.Delete)
r.GET("/post/:post_id", a.h.ApplicationPostApi.Get)
r.GET("/categories", a.h.ApplicationCategoryApi.List)
r.POST("/categories", a.h.ApplicationCategoryApi.Save)
r.GET("/categories/:category_id", a.h.ApplicationCategoryApi.Get)
r.DELETE("/categories/:category_id", a.h.ApplicationCategoryApi.Delete)
}