✨ 新增几大中心功能
This commit is contained in:
50
server/api/v1/app/invite_code.go
Normal file
50
server/api/v1/app/invite_code.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"git.echol.cn/loser/Go-Web-Template/server/model/common/response"
|
||||
appSvc "git.echol.cn/loser/Go-Web-Template/server/service/app"
|
||||
"git.echol.cn/loser/Go-Web-Template/server/utils"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type InviteCodeApi struct{}
|
||||
|
||||
type inviteCodeCurrentResponse struct {
|
||||
HasUnused bool `json:"hasUnused"`
|
||||
Record interface{} `json:"record,omitempty"`
|
||||
}
|
||||
|
||||
// GenerateInviteCode 玩家生成邀请码(返回明文)
|
||||
func (a *InviteCodeApi) GenerateInviteCode(c *gin.Context) {
|
||||
uid := utils.GetUserID(c)
|
||||
res, err := appSvc.AppInviteCodeServiceApp.Generate(uid)
|
||||
if err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
response.OkWithData(res, c)
|
||||
}
|
||||
|
||||
// CurrentInviteCode 获取当前未使用邀请码(不返回明文)
|
||||
func (a *InviteCodeApi) CurrentInviteCode(c *gin.Context) {
|
||||
uid := utils.GetUserID(c)
|
||||
rec, err := appSvc.AppInviteCodeServiceApp.GetCurrentUnused(uid)
|
||||
if err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
if rec == nil {
|
||||
response.OkWithData(inviteCodeCurrentResponse{HasUnused: false}, c)
|
||||
return
|
||||
}
|
||||
payload := map[string]interface{}{
|
||||
"id": rec.ID,
|
||||
"codeLast4": rec.CodeLast4,
|
||||
"status": rec.Status,
|
||||
"expiresAt": rec.ExpiresAt,
|
||||
"createdAt": rec.CreatedAt.Format(time.RFC3339),
|
||||
}
|
||||
response.OkWithData(inviteCodeCurrentResponse{HasUnused: true, Record: payload}, c)
|
||||
}
|
||||
Reference in New Issue
Block a user