Add Middleware to routes and update Swagger to add that

This commit is contained in:
qowevisa 2024-08-03 08:43:41 +03:00
parent c959d9f173
commit 39cecc80d1
2 changed files with 9 additions and 5 deletions

View File

@ -6,6 +6,7 @@ import (
docs "git.qowevisa.me/Qowevisa/gonuts/docs"
"git.qowevisa.me/Qowevisa/gonuts/handlers"
"git.qowevisa.me/Qowevisa/gonuts/middleware"
"git.qowevisa.me/Qowevisa/gonuts/tokens"
"github.com/gin-gonic/gin"
)
@ -36,10 +37,10 @@ func main() {
userRoutes.POST("/register", handlers.UserRegister)
userRoutes.POST("/login", handlers.UserLogin)
}
cardsRoutes := api.Group("/card")
cardsRoutes := api.Group("/card", middleware.AuthMiddleware())
{
cardsRoutes.GET("/:id", handlers.CardGetId)
cardsRoutes.POST("/add", handlers.CardGetId)
cardsRoutes.POST("/add", handlers.CardAdd)
}
}

View File

@ -14,10 +14,12 @@ import (
// @Tags card
// @Accept json
// @Produce json
// @Param card param int true "id"
// @Param Authorization header string true "Bearer token"
// @Param card path int true "id"
// @Success 200 {object} types.DbCard
// @Failure 400 {object} types.ErrorResponse
// @Failure 500 {object} types.ErrorResponse
// @Security ApiKeyAuth
// @Router /card/:id [get]
func CardGetId(c *gin.Context) {
idStr := c.Param("id")
@ -53,11 +55,13 @@ func CardGetId(c *gin.Context) {
// @Tags card
// @Accept json
// @Produce json
// @Param Authorization header string true "Bearer token"
// @Param card body types.DbCard true "Card"
// @Success 200 {object} types.Message
// @Failure 400 {object} types.ErrorResponse
// @Failure 500 {object} types.ErrorResponse
// @Router /card/:id [get]
// @Security ApiKeyAuth
// @Router /card/add [post]
func CardAdd(c *gin.Context) {
var card types.DbCard
if err := c.ShouldBindJSON(&card); err != nil {
@ -85,4 +89,3 @@ func CardAdd(c *gin.Context) {
}
c.JSON(200, msg)
}