Merge pull request #31 from yokowu/main

feat: 注册增加用户名字段, 补全记录返回提示词
This commit is contained in:
Yoko
2025-07-02 12:18:54 +08:00
committed by GitHub
5 changed files with 23 additions and 9 deletions

View File

@@ -2008,6 +2008,9 @@
},
"id": {
"type": "string"
},
"prompt": {
"type": "string"
}
}
},
@@ -2464,6 +2467,12 @@
},
"domain.RegisterReq": {
"type": "object",
"required": [
"code",
"email",
"password",
"username"
],
"properties": {
"code": {
"description": "邀请码",
@@ -2476,6 +2485,10 @@
"password": {
"description": "密码",
"type": "string"
},
"username": {
"description": "用户名",
"type": "string"
}
}
},

View File

@@ -87,6 +87,7 @@ func (c *CompletionRecord) From(e *db.Task) *CompletionRecord {
type CompletionInfo struct {
ID string `json:"id"`
Prompt string `json:"prompt"`
Content string `json:"content"`
CreatedAt int64 `json:"created_at"`
}
@@ -96,6 +97,7 @@ func (c *CompletionInfo) From(e *db.Task) *CompletionInfo {
return c
}
c.ID = e.TaskID
c.Prompt = e.Prompt
c.Content = e.Completion
c.CreatedAt = e.CreatedAt.Unix()
return c

View File

@@ -95,9 +95,10 @@ type ListReq struct {
}
type RegisterReq struct {
Email string `json:"email"` // 邮箱
Password string `json:"password"` // 密码
Code string `json:"code"` // 邀请
Username string `json:"username" validate:"required"` // 用户名
Email string `json:"email" validate:"required"` // 邮箱
Password string `json:"password" validate:"required"` //
Code string `json:"code" validate:"required"` // 邀请码
}
type ListLoginHistoryResp struct {

View File

@@ -74,6 +74,7 @@ func (r *UserRepo) CreateUser(ctx context.Context, user *db.User) (*db.User, err
SetEmail(user.Email).
SetPassword(user.Password).
SetStatus(user.Status).
SetPlatform(user.Platform).
Save(ctx)
}

View File

@@ -6,7 +6,6 @@ import (
"fmt"
"log/slog"
"net/url"
"strings"
"time"
"github.com/google/uuid"
@@ -136,14 +135,12 @@ func (u *UserUsecase) Register(ctx context.Context, req *domain.RegisterReq) (*d
if err != nil {
return nil, err
}
parts := strings.Split(req.Email, "@")
if len(parts) != 2 {
return nil, errcode.ErrEmailInvalid
}
user := &db.User{
Username: parts[0],
Username: req.Username,
Email: req.Email,
Password: string(hash),
Status: consts.UserStatusActive,
Platform: consts.UserPlatformEmail,
}
n, err := u.repo.CreateUser(ctx, user)
if err != nil {