2024-07-14 10:29:36 +00:00
|
|
|
package routes
|
2024-07-14 09:44:49 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/gin-gonic/gin"
|
2024-07-14 14:29:59 +00:00
|
|
|
swaggerFiles "github.com/swaggo/files"
|
|
|
|
ginSwagger "github.com/swaggo/gin-swagger"
|
2024-07-14 15:58:23 +00:00
|
|
|
_ "leafdev.top/leaf/rag/docs"
|
2024-07-14 17:22:40 +00:00
|
|
|
"leafdev.top/leaf/rag/internal/handlers/controllers/library"
|
2024-07-14 15:58:23 +00:00
|
|
|
"leafdev.top/leaf/rag/internal/handlers/controllers/user"
|
|
|
|
"leafdev.top/leaf/rag/internal/middleware/http"
|
|
|
|
"leafdev.top/leaf/rag/internal/providers"
|
2024-07-14 09:44:49 +00:00
|
|
|
)
|
|
|
|
|
2024-07-14 17:22:40 +00:00
|
|
|
var userController = user.NewUserController()
|
|
|
|
var libraryController = library.NewLibraryController()
|
|
|
|
|
2024-07-14 14:14:27 +00:00
|
|
|
// @title Swagger Example API
|
|
|
|
// @version 1.0
|
|
|
|
// @description This is a sample server celler server.
|
|
|
|
// @termsOfService http://swagger.io/terms/
|
|
|
|
|
|
|
|
// @contact.name API Support
|
|
|
|
// @contact.url http://www.swagger.io/support
|
|
|
|
// @contact.email support@swagger.io
|
|
|
|
|
|
|
|
// @license.name Apache 2.0
|
|
|
|
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html
|
|
|
|
|
|
|
|
// @host localhost:8080
|
2024-07-14 17:22:40 +00:00
|
|
|
// @BasePath /api/v1
|
2024-07-14 14:14:27 +00:00
|
|
|
|
2024-07-14 14:29:59 +00:00
|
|
|
// @securityDefinitions.apikey ApiKeyAuth
|
|
|
|
//
|
2024-07-14 14:14:27 +00:00
|
|
|
// @in header
|
|
|
|
// @name Authorization
|
2024-07-14 14:29:59 +00:00
|
|
|
// @description Description for what is this security definition being used
|
|
|
|
// InitApiRoutes init api routes
|
2024-07-14 09:44:49 +00:00
|
|
|
func InitApiRoutes() {
|
2024-07-14 15:58:23 +00:00
|
|
|
var r = *providers.MustGet[gin.Engine]()
|
|
|
|
|
2024-07-14 17:22:40 +00:00
|
|
|
r.Use(http.MiddlewareJSONResponse)
|
|
|
|
|
|
|
|
// middleware group
|
|
|
|
authorizedApiV1 := r.Group("/api/v1")
|
|
|
|
authorizedApiV1.Use(http.RequireJWTIDToken)
|
|
|
|
{
|
|
|
|
authorizedApiV1.GET("/user", userController.CurrentUser)
|
2024-07-20 17:20:52 +00:00
|
|
|
//authorizedApiV1.GET("/library", libraryController.Library)
|
2024-07-14 17:22:40 +00:00
|
|
|
authorizedApiV1.POST("/library", libraryController.CreateLibrary)
|
|
|
|
}
|
2024-07-14 14:29:59 +00:00
|
|
|
|
|
|
|
}
|
2024-07-14 09:44:49 +00:00
|
|
|
|
2024-07-14 14:29:59 +00:00
|
|
|
// InitSwaggerRoutes init swagger routes
|
|
|
|
func InitSwaggerRoutes() {
|
2024-07-14 15:58:23 +00:00
|
|
|
var r = *providers.MustGet[gin.Engine]()
|
|
|
|
|
2024-07-14 14:29:59 +00:00
|
|
|
r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
|
2024-07-14 09:44:49 +00:00
|
|
|
}
|