user.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package api
  2. import (
  3. apiResp "Gwen/http/response/api"
  4. "Gwen/service"
  5. "fmt"
  6. "github.com/gin-gonic/gin"
  7. "net/http"
  8. )
  9. type User struct {
  10. }
  11. // currentUser 当前用户
  12. // @Tags 用户
  13. // @Summary 用户信息
  14. // @Description 用户信息
  15. // @Accept json
  16. // @Produce json
  17. // @Success 200 {object} apiResp.UserPayload
  18. // @Failure 500 {object} response.Response
  19. // @Router /currentUser [get]
  20. // @Security token
  21. func (u *User) currentUser(c *gin.Context) {
  22. user := service.AllService.UserService.CurUser(c)
  23. up := (&apiResp.UserPayload{}).FromUser(user)
  24. c.JSON(http.StatusOK, up)
  25. }
  26. // Info 用户信息
  27. // @Tags 用户
  28. // @Summary 用户信息
  29. // @Description 用户信息
  30. // @Accept json
  31. // @Produce json
  32. // @Success 200 {object} apiResp.UserPayload
  33. // @Failure 500 {object} response.Response
  34. // @Router /api [get]
  35. // @Security token
  36. func (u *User) Info(c *gin.Context) {
  37. user := service.AllService.UserService.CurUser(c)
  38. up := (&apiResp.UserPayload{}).FromUser(user)
  39. c.JSON(http.StatusOK, up)
  40. }
  41. // Personal
  42. // @Tags 用户
  43. // @Summary 个人信息
  44. // @Description 个人信息
  45. // @Accept json
  46. // @Produce json
  47. // @Param string body string false "string valid"
  48. // @Success 200 {object} response.Response
  49. // @Failure 500 {object} response.Response
  50. // @Router /ab/personal [post]
  51. // @Security BearerAuth
  52. func (u *User) Personal(c *gin.Context) {
  53. //打印全部body
  54. fmt.Println(c.Request.Body)
  55. /**
  56. guid = json['guid'] ?? '',
  57. name = json['name'] ?? '',
  58. owner = json['owner'] ?? '',
  59. note = json['note'] ?? '',
  60. rule = json['rule'] ?? 0;
  61. */
  62. //如果返回了guid,后面的请求会有变化
  63. c.JSON(http.StatusOK, gin.H{
  64. //"guid": "123456",
  65. //"name": "admindddd",
  66. //"rule": 1,
  67. })
  68. }