woj-server/internal/api/user/handler.go

39 lines
936 B
Go

package user
import (
"git.0x7f.app/WOJ/woj-server/internal/misc/log"
"git.0x7f.app/WOJ/woj-server/internal/service/user"
"git.0x7f.app/WOJ/woj-server/internal/web/jwt"
"github.com/gin-gonic/gin"
"github.com/samber/do"
"go.uber.org/zap"
)
var _ Handler = (*handler)(nil)
type Handler interface {
Create(c *gin.Context)
Login(c *gin.Context)
Logout(c *gin.Context)
Profile(c *gin.Context)
}
type handler struct {
log *zap.Logger
jwtService jwt.Service
userService user.Service
}
func RouteRegister(rg *gin.RouterGroup, i *do.Injector) {
app := &handler{
log: do.MustInvoke[log.Service](i).GetLogger("api.user"),
jwtService: do.MustInvoke[jwt.Service](i),
userService: do.MustInvoke[user.Service](i),
}
rg.POST("/create", app.Create)
rg.POST("/login", app.Login)
rg.POST("/logout", app.jwtService.Handler(true), app.Logout)
rg.POST("/profile", app.jwtService.Handler(true), app.Profile)
}