From 40ab2997c01246e32a64c55dc29448cf0ea7ee0a Mon Sep 17 00:00:00 2001 From: xrz <62951481+xrz-cloud@users.noreply.github.com> Date: Sun, 8 Dec 2024 22:05:17 +0800 Subject: [PATCH] feat: support get current user's email and reg_time (#690) --- internal/user/model.go | 1 + internal/user/mysql_repository.go | 1 + openapi/v0.yaml | 11 +++++++++ web/handler/user/me.go | 37 ++++++++++++++++++------------- 4 files changed, 34 insertions(+), 16 deletions(-) diff --git a/internal/user/model.go b/internal/user/model.go index 2ee5e2bbb..cb700cf6b 100644 --- a/internal/user/model.go +++ b/internal/user/model.go @@ -32,6 +32,7 @@ type FullUser struct { ID model.UserID UserGroup GroupID TimeOffset int8 + Email string } type GroupID = uint8 diff --git a/internal/user/mysql_repository.go b/internal/user/mysql_repository.go index c77fb0d3e..a85365a79 100644 --- a/internal/user/mysql_repository.go +++ b/internal/user/mysql_repository.go @@ -59,6 +59,7 @@ func (m mysqlRepo) GetFullUser(ctx context.Context, userID model.UserID) (FullUs ID: u.ID, RegistrationTime: time.Unix(u.Regdate, 0), TimeOffset: parseTimeOffset(u.Timeoffset), + Email: u.Email, }, nil } diff --git a/openapi/v0.yaml b/openapi/v0.yaml index 69addf9f0..87e18ee9a 100644 --- a/openapi/v0.yaml +++ b/openapi/v0.yaml @@ -1041,8 +1041,19 @@ paths: schema: allOf: - "$ref": "#/components/schemas/User" + - required: + - email + - reg_time - type: object properties: + email: + description: "用户绑定的邮箱地址" + type: string + format: email + reg_time: + description: "用户注册时间。比如 2017-12-03T08:51:16+08:00" + type: string + format: date-time time_offset: description: "用户设置的时区偏移,以小时为单位。比如 GMT+8(shanghai/beijing)为 8" type: integer diff --git a/web/handler/user/me.go b/web/handler/user/me.go index d2482c903..ca4fecc8e 100644 --- a/web/handler/user/me.go +++ b/web/handler/user/me.go @@ -16,6 +16,7 @@ package user import ( "net/http" + "time" "github.com/labstack/echo/v4" "github.com/trim21/errgo" @@ -26,14 +27,16 @@ import ( ) type CurrentUser struct { - Avatar res.Avatar `json:"avatar"` - Sign string `json:"sign"` - URL string `json:"url"` - Username string `json:"username"` - Nickname string `json:"nickname"` - ID model.UserID `json:"id"` - UserGroup uint8 `json:"user_group"` - TimeOffset int8 `json:"time_offset"` + Avatar res.Avatar `json:"avatar"` + Sign string `json:"sign"` + URL string `json:"url"` + Username string `json:"username"` + Nickname string `json:"nickname"` + ID model.UserID `json:"id"` + UserGroup uint8 `json:"user_group"` + RegistrationTime time.Time `json:"reg_time"` + Email string `json:"email"` + TimeOffset int8 `json:"time_offset"` } func (h User) GetCurrent(c echo.Context) error { @@ -48,13 +51,15 @@ func (h User) GetCurrent(c echo.Context) error { } return c.JSON(http.StatusOK, CurrentUser{ - ID: user.ID, - URL: "https://bgm.tv/user/" + user.UserName, - Username: user.UserName, - Nickname: user.NickName, - UserGroup: user.UserGroup, - Avatar: res.UserAvatar(user.Avatar), - Sign: user.Sign, - TimeOffset: user.TimeOffset, + ID: user.ID, + URL: "https://bgm.tv/user/" + user.UserName, + Username: user.UserName, + Nickname: user.NickName, + UserGroup: user.UserGroup, + Avatar: res.UserAvatar(user.Avatar), + Sign: user.Sign, + RegistrationTime: user.RegistrationTime, + Email: user.Email, + TimeOffset: user.TimeOffset, }) }