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

37 lines
788 B
Go
Raw Normal View History

2022-09-08 22:00:25 +08:00
package user
import (
2022-10-13 16:32:44 +08:00
"github.com/WHUPRJ/woj-server/global"
2022-09-08 22:00:25 +08:00
"github.com/WHUPRJ/woj-server/internal/service/user"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
)
var _ Handler = (*handler)(nil)
type Handler interface {
Create(c *gin.Context)
2022-09-17 11:22:55 +08:00
Login(c *gin.Context)
2022-09-20 15:11:37 +08:00
Logout(c *gin.Context)
Profile(c *gin.Context)
2022-09-08 22:00:25 +08:00
}
type handler struct {
2022-09-17 11:22:55 +08:00
log *zap.Logger
userService user.Service
jwtService global.JwtService
2022-09-08 22:00:25 +08:00
}
func RouteRegister(g *global.Global, group *gin.RouterGroup) {
app := &handler{
2022-09-17 11:22:55 +08:00
log: g.Log,
2022-09-26 16:13:31 +08:00
userService: user.NewService(g),
2022-09-17 11:22:55 +08:00
jwtService: g.Jwt,
2022-09-08 22:00:25 +08:00
}
2022-09-17 11:22:55 +08:00
group.POST("/login", app.Login)
group.POST("/create", app.Create)
group.POST("/logout", app.jwtService.Handler(), app.Logout)
2022-09-20 15:11:37 +08:00
group.POST("/profile", app.jwtService.Handler(), app.Profile)
2022-09-08 22:00:25 +08:00
}