initial import

This commit is contained in:
Олег Бородин
2024-01-16 09:02:47 +02:00
commit e18bc7beef
61 changed files with 17123 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
package handler
import (
"webserv/pkg/logger"
"webserv/internal/logic"
)
type HandlerConfig struct {
Logic *logic.Logic
}
type Handler struct {
log *logger.Logger
lg *logic.Logic
}
func NewHandler(conf *HandlerConfig) (*Handler, error) {
var err error
hand := &Handler{
log: logger.NewLogger("handler"),
lg: conf.Logic,
}
return hand, err
}

50
internal/handler/user.go Normal file
View File

@@ -0,0 +1,50 @@
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)
}