Skip to content

Commit

Permalink
refactor: 优化注册接口的请求参数设计
Browse files Browse the repository at this point in the history
  • Loading branch information
Penryn committed Dec 2, 2024
1 parent a148f50 commit 5cfc875
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
8 changes: 7 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,13 @@ linters-settings:
- name: max-public-structs # 最大公共结构体数目
severity: warning
disabled: true
- name: cognitive-complexity
- name: argument-limit # 函数参数限制
severity: warning
disabled: true
- name: function-length # 函数长度限制
severity: warning
disabled: true
- name: cognitive-complexity # 认知复杂度
severity: warning
disabled: false
arguments: [ 10 ]
Expand Down
19 changes: 16 additions & 3 deletions app/controllers/userController/reg.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ type createStudentUserWechatForm struct {
Password string `json:"password" binding:"required"`
Type uint `json:"type" binding:"required"` // 用户类型 1-本科生 2-研究生
IDCardNumber string `json:"idCardNumber" binding:"required"`
Email string `json:"email" binding:"required"`
Name string `json:"name" binding:"required"`
College string `json:"college" binding:"required"`
Class string `json:"class" binding:"required"`
Code string `json:"code" binding:"required"`
Email string `json:"email"`
}

// BindOrCreateStudentUserFromWechat 微信创建学生用户
Expand All @@ -42,6 +45,9 @@ func BindOrCreateStudentUserFromWechat(c *gin.Context) {
postForm.Type,
postForm.IDCardNumber,
postForm.Email,
postForm.Name,
postForm.College,
postForm.Class,
session.OpenID)
if err != nil {
var apiErr *apiException.Error
Expand All @@ -66,7 +72,10 @@ type createStudentUserForm struct {
Password string `json:"password" binding:"required"`
Type uint `json:"type" binding:"required"` // 用户类型 1-本科生 2-研究生
IDCardNumber string `json:"idCardNumber" binding:"required"`
Email string `json:"email" binding:"required"`
Name string `json:"name" binding:"required"`
College string `json:"college" binding:"required"`
Class string `json:"class" binding:"required"`
Email string `json:"email"`
}

// CreateStudentUser H5创建学生用户
Expand All @@ -84,7 +93,11 @@ func CreateStudentUser(c *gin.Context) {
postForm.Password,
postForm.IDCardNumber,
postForm.Email,
postForm.Type)
postForm.Name,
postForm.College,
postForm.Class,
postForm.Type,
)
if err != nil {
var apiErr *apiException.Error
if errors.As(err, &apiErr) {
Expand Down
13 changes: 11 additions & 2 deletions app/services/userService/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import (
)

// CreateStudentUser 创建学生用户
func CreateStudentUser(studentID, password, idCardNumber, email string, usertype uint) (*models.User, error) {
func CreateStudentUser(
studentID, password, idCardNumber, email, name, college, class string,
usertype uint,
) (*models.User, error) {
_, err := GetUserByStudentID(studentID)
if err == nil {
return nil, apiException.UserAlreadyExisted
Expand All @@ -24,6 +27,9 @@ func CreateStudentUser(studentID, password, idCardNumber, email string, usertype
}

user := &models.User{
Name: name,
College: college,
Class: class,
Type: usertype,
StudentID: studentID,
}
Expand All @@ -41,13 +47,16 @@ func CreateStudentUserWechat(
userType uint,
idCardNumber string,
email string,
name string,
college string,
class string,
wechatOpenID string,
) (*models.User, error) {
_, err := GetUserByWechatOpenID(wechatOpenID)
if err == nil {
return nil, apiException.OpenIDError
}
user, err := CreateStudentUser(studentID, password, idCardNumber, email, userType)
user, err := CreateStudentUser(studentID, password, idCardNumber, email, name, college, class, userType)
if err != nil && !errors.Is(err, apiException.ReactiveError) {
return nil, err
}
Expand Down

0 comments on commit 5cfc875

Please sign in to comment.