018aecdb72566625b0d3f359497eb3c719d71e95.svn-base 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package endpoint
  2. import (
  3. "context"
  4. "github.com/go-kit/kit/endpoint"
  5. "github.com/longjoy/micro-go-course/section08/user/service"
  6. )
  7. type UserEndpoints struct {
  8. RegisterEndpoint endpoint.Endpoint
  9. LoginEndpoint endpoint.Endpoint
  10. }
  11. type LoginRequest struct {
  12. Email string
  13. Password string
  14. }
  15. type LoginResponse struct {
  16. UserInfo *service.UserInfoDTO `json:"user_info"`
  17. }
  18. func MakeLoginEndpoint(userService service.UserService) endpoint.Endpoint {
  19. return func(ctx context.Context, request interface{}) (response interface{}, err error) {
  20. req := request.(*LoginRequest)
  21. userInfo, err := userService.Login(ctx, req.Email, req.Password)
  22. return &LoginResponse{UserInfo:userInfo}, err
  23. }
  24. }
  25. type RegisterRequest struct {
  26. Username string
  27. Email string
  28. Password string
  29. }
  30. type RegisterResponse struct {
  31. UserInfo *service.UserInfoDTO `json:"user_info"`
  32. }
  33. func MakeRegisterEndpoint(userService service.UserService) endpoint.Endpoint {
  34. return func(ctx context.Context, request interface{}) (response interface{}, err error) {
  35. req := request.(*RegisterRequest)
  36. userInfo, err := userService.Register(ctx, &service.RegisterUserVO{
  37. Username:req.Username,
  38. Password:req.Password,
  39. Email:req.Email,
  40. })
  41. return &RegisterResponse{UserInfo:userInfo}, err
  42. }
  43. }