Skip to content

Commit

Permalink
feat: support get current user's email and reg_time (#690)
Browse files Browse the repository at this point in the history
  • Loading branch information
xrz-cloud authored Dec 8, 2024
1 parent 4051eed commit 40ab299
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 16 deletions.
1 change: 1 addition & 0 deletions internal/user/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type FullUser struct {
ID model.UserID
UserGroup GroupID
TimeOffset int8
Email string
}

type GroupID = uint8
Expand Down
1 change: 1 addition & 0 deletions internal/user/mysql_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
11 changes: 11 additions & 0 deletions openapi/v0.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
37 changes: 21 additions & 16 deletions web/handler/user/me.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package user

import (
"net/http"
"time"

"github.com/labstack/echo/v4"
"github.com/trim21/errgo"
Expand All @@ -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 {
Expand All @@ -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,
})
}

0 comments on commit 40ab299

Please sign in to comment.