initial import
This commit is contained in:
25
internal/handler/handler.go
Normal file
25
internal/handler/handler.go
Normal 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
50
internal/handler/user.go
Normal 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)
|
||||
}
|
||||
Reference in New Issue
Block a user