12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- package controller
- import (
- "context"
- "fmt"
- "github.com/gogf/gf/v2/frame/g"
- "gof_ppw_api/api"
- "gof_ppw_api/internal/service"
- )
- var User = &UserController{}
- type UserController struct {
- Controller
- }
- // Create 创建用户
- func (p *UserController) Create(ctx context.Context, req *api.UserCreateReq) (res *api.CommonRes, err error) {
- data := p.parseReq(req)
- err = service.User.Create(ctx, data)
- return
- }
- // Update 修改用户
- func (p *UserController) Update(ctx context.Context, req *api.UserUpdateReq) (res *api.CommonRes, err error) {
- data := p.parseReq(req)
- err = service.User.Update(ctx, data)
- return
- }
- // Delete 删除用户
- func (p *UserController) Delete(ctx context.Context, req *api.UserDeleteReq) (res *api.CommonRes, err error) {
- data := p.parseReq(req)
- err = service.User.Delete(ctx, data)
- return
- }
- // Login 用户登录
- func (p *UserController) Login(ctx context.Context, req *api.UserLoginReq) (res *api.CommonRes, err error) {
- data := p.parseReq(req)
- err = service.User.Login(ctx, data)
- return
- }
- // Logout 用户登出
- func (p *UserController) Logout(ctx context.Context, req *api.UserLogoutReq) (res *api.CommonRes, err error) {
- err = service.User.Logout(ctx)
- return
- }
- func (p *UserController) Test(ctx context.Context, req *api.UserTestReq) (res *api.CommonRes, err error) {
- sessData, _ := g.RequestFromCtx(ctx).Session.Get("user_id")
- fmt.Println(sessData.Val() == nil)
- res = &api.CommonRes{
- Data: sessData,
- }
- return
- }
|