Files
webserv/internal/handler/user.go
Олег Бородин e18bc7beef initial import
2024-01-16 09:02:47 +02:00

51 lines
1.4 KiB
Go

package handler
import (
"webserv/pkg/auxtool/auxhttp"
"webserv/internal/logic"
"github.com/gin-gonic/gin"
)
// https://github.com/swaggo/swag
// CreateUser godoc
// @Summary Create user
// @Description Create user for service
// @Router /user/create [POST]
// @Param username formData string true "User name"
// @Param grants formData []string true "Grants list"
// @Accept x-www-form-urlencoded
// @Produce json
// @Success 200 {object} logic.CreateUserResult
// @Tags user
func (hand *Handler) CreateUser(gctx *gin.Context) {
var err error
req := &logic.CreateUserRequest{}
err = gctx.ShouldBind(req)
if err != nil {
hand.log.Error("CreateUser parse incoming parameters error:", err)
auxhttp.SendError(gctx, err)
return
}
ctx := gctx.Request.Context()
res, err := hand.lg.CreateUser(ctx, req)
auxhttp.SendResult(gctx, res)
}
func (hand *Handler) DeleteUser(gctx *gin.Context) {
var err error
req := &logic.DeleteUserRequest{}
err = gctx.ShouldBind(req)
if err != nil {
hand.log.Error("DeleteUser parse incoming parameters error:", err)
auxhttp.SendError(gctx, err)
return
}
ctx := gctx.Request.Context()
res, err := hand.lg.DeleteUser(ctx, req)
auxhttp.SendResult(gctx, res)
}