user.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package controller
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/gogf/gf/v2/frame/g"
  6. "gof_ppw_api/api"
  7. "gof_ppw_api/internal/service"
  8. )
  9. var User = &UserController{}
  10. type UserController struct {
  11. Controller
  12. }
  13. // Create 创建用户
  14. func (p *UserController) Create(ctx context.Context, req *api.UserCreateReq) (res *api.CommonRes, err error) {
  15. data := p.parseReq(req)
  16. err = service.User.Create(ctx, data)
  17. return
  18. }
  19. // Update 修改用户
  20. func (p *UserController) Update(ctx context.Context, req *api.UserUpdateReq) (res *api.CommonRes, err error) {
  21. data := p.parseReq(req)
  22. err = service.User.Update(ctx, data)
  23. return
  24. }
  25. // Delete 删除用户
  26. func (p *UserController) Delete(ctx context.Context, req *api.UserDeleteReq) (res *api.CommonRes, err error) {
  27. data := p.parseReq(req)
  28. err = service.User.Delete(ctx, data)
  29. return
  30. }
  31. // Login 用户登录
  32. func (p *UserController) Login(ctx context.Context, req *api.UserLoginReq) (res *api.CommonRes, err error) {
  33. data := p.parseReq(req)
  34. err = service.User.Login(ctx, data)
  35. return
  36. }
  37. // Logout 用户登出
  38. func (p *UserController) Logout(ctx context.Context, req *api.UserLogoutReq) (res *api.CommonRes, err error) {
  39. err = service.User.Logout(ctx)
  40. return
  41. }
  42. func (p *UserController) Test(ctx context.Context, req *api.UserTestReq) (res *api.CommonRes, err error) {
  43. sessData, _ := g.RequestFromCtx(ctx).Session.Get("user_id")
  44. fmt.Println(sessData.Val() == nil)
  45. res = &api.CommonRes{
  46. Data: sessData,
  47. }
  48. return
  49. }