正在显示
19 个修改的文件
包含
944 行增加
和
0 行删除
| 1 | +package command | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + "reflect" | ||
| 6 | + "strings" | ||
| 7 | + | ||
| 8 | + "github.com/beego/beego/v2/core/validation" | ||
| 9 | +) | ||
| 10 | + | ||
| 11 | +type CompanySignUpCommand struct { | ||
| 12 | + // 企业名称 | ||
| 13 | + CompanyName string `cname:"企业名称" json:"companyName" valid:"Required"` | ||
| 14 | + // 联系人 | ||
| 15 | + Contacts string `cname:"联系人" json:"contacts" valid:"Required"` | ||
| 16 | + // 手机号码 | ||
| 17 | + Phone string `cname:"手机号码" json:"phone" valid:"Required"` | ||
| 18 | + // 规模 | ||
| 19 | + Scale string `cname:"规模" json:"scale" valid:"Required"` | ||
| 20 | + // 所属行业 | ||
| 21 | + IndustryCategory string `cname:"所属行业" json:"industryCategory" valid:"Required"` | ||
| 22 | + // 密码 | ||
| 23 | + Password string `cname:"密码" json:"password" valid:"Required"` | ||
| 24 | +} | ||
| 25 | + | ||
| 26 | +func (companySignUpCommand *CompanySignUpCommand) Valid(validation *validation.Validation) { | ||
| 27 | + //validation.SetError("CustomValid", "未实现的自定义认证") | ||
| 28 | +} | ||
| 29 | + | ||
| 30 | +func (companySignUpCommand *CompanySignUpCommand) ValidateCommand() error { | ||
| 31 | + valid := validation.Validation{} | ||
| 32 | + b, err := valid.Valid(companySignUpCommand) | ||
| 33 | + if err != nil { | ||
| 34 | + return err | ||
| 35 | + } | ||
| 36 | + if !b { | ||
| 37 | + elem := reflect.TypeOf(companySignUpCommand).Elem() | ||
| 38 | + for _, validErr := range valid.Errors { | ||
| 39 | + field, isExist := elem.FieldByName(validErr.Field) | ||
| 40 | + if isExist { | ||
| 41 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
| 42 | + } else { | ||
| 43 | + return fmt.Errorf(validErr.Message) | ||
| 44 | + } | ||
| 45 | + } | ||
| 46 | + } | ||
| 47 | + return nil | ||
| 48 | +} |
| 1 | +package command | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + "reflect" | ||
| 6 | + "strings" | ||
| 7 | + | ||
| 8 | + "github.com/beego/beego/v2/core/validation" | ||
| 9 | +) | ||
| 10 | + | ||
| 11 | +type DestroyAccountCommand struct { | ||
| 12 | + // 用户Id 用户唯一标识 | ||
| 13 | + UserId int64 `cname:"用户Id 用户唯一标识" json:"userId,string" valid:"Required"` | ||
| 14 | +} | ||
| 15 | + | ||
| 16 | +func (destroyAccountCommand *DestroyAccountCommand) Valid(validation *validation.Validation) { | ||
| 17 | + validation.SetError("CustomValid", "未实现的自定义认证") | ||
| 18 | +} | ||
| 19 | + | ||
| 20 | +func (destroyAccountCommand *DestroyAccountCommand) ValidateCommand() error { | ||
| 21 | + valid := validation.Validation{} | ||
| 22 | + b, err := valid.Valid(destroyAccountCommand) | ||
| 23 | + if err != nil { | ||
| 24 | + return err | ||
| 25 | + } | ||
| 26 | + if !b { | ||
| 27 | + elem := reflect.TypeOf(destroyAccountCommand).Elem() | ||
| 28 | + for _, validErr := range valid.Errors { | ||
| 29 | + field, isExist := elem.FieldByName(validErr.Field) | ||
| 30 | + if isExist { | ||
| 31 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
| 32 | + } else { | ||
| 33 | + return fmt.Errorf(validErr.Message) | ||
| 34 | + } | ||
| 35 | + } | ||
| 36 | + } | ||
| 37 | + return nil | ||
| 38 | +} |
| 1 | +package command | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + "reflect" | ||
| 6 | + "strings" | ||
| 7 | + | ||
| 8 | + "github.com/beego/beego/v2/core/validation" | ||
| 9 | +) | ||
| 10 | + | ||
| 11 | +type PhoneAuthChangePasswordCommand struct { | ||
| 12 | + // 用户Id 用户唯一标识 | ||
| 13 | + UserId int64 `cname:"用户Id 用户唯一标识" json:"userId,string" valid:"Required"` | ||
| 14 | + // 旧密码 | ||
| 15 | + OldPassword string `cname:"旧密码" json:"oldPassword" valid:"Required"` | ||
| 16 | + // 新密码 | ||
| 17 | + NewPassword string `cname:"新密码" json:"newPassword" valid:"Required"` | ||
| 18 | +} | ||
| 19 | + | ||
| 20 | +func (phoneAuthChangePasswordCommand *PhoneAuthChangePasswordCommand) Valid(validation *validation.Validation) { | ||
| 21 | + validation.SetError("CustomValid", "未实现的自定义认证") | ||
| 22 | +} | ||
| 23 | + | ||
| 24 | +func (phoneAuthChangePasswordCommand *PhoneAuthChangePasswordCommand) ValidateCommand() error { | ||
| 25 | + valid := validation.Validation{} | ||
| 26 | + b, err := valid.Valid(phoneAuthChangePasswordCommand) | ||
| 27 | + if err != nil { | ||
| 28 | + return err | ||
| 29 | + } | ||
| 30 | + if !b { | ||
| 31 | + elem := reflect.TypeOf(phoneAuthChangePasswordCommand).Elem() | ||
| 32 | + for _, validErr := range valid.Errors { | ||
| 33 | + field, isExist := elem.FieldByName(validErr.Field) | ||
| 34 | + if isExist { | ||
| 35 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
| 36 | + } else { | ||
| 37 | + return fmt.Errorf(validErr.Message) | ||
| 38 | + } | ||
| 39 | + } | ||
| 40 | + } | ||
| 41 | + return nil | ||
| 42 | +} |
| 1 | +package command | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + "reflect" | ||
| 6 | + "strings" | ||
| 7 | + | ||
| 8 | + "github.com/beego/beego/v2/core/validation" | ||
| 9 | +) | ||
| 10 | + | ||
| 11 | +type PhoneAuthCheckCommand struct { | ||
| 12 | + // 手机号码 | ||
| 13 | + Phone string `cname:"手机号码" json:"phone" valid:"Required"` | ||
| 14 | + // 密码 | ||
| 15 | + Password string `cname:"密码" json:"password" valid:"Required"` | ||
| 16 | +} | ||
| 17 | + | ||
| 18 | +func (phoneAuthCheckCommand *PhoneAuthCheckCommand) Valid(validation *validation.Validation) { | ||
| 19 | + validation.SetError("CustomValid", "未实现的自定义认证") | ||
| 20 | +} | ||
| 21 | + | ||
| 22 | +func (phoneAuthCheckCommand *PhoneAuthCheckCommand) ValidateCommand() error { | ||
| 23 | + valid := validation.Validation{} | ||
| 24 | + b, err := valid.Valid(phoneAuthCheckCommand) | ||
| 25 | + if err != nil { | ||
| 26 | + return err | ||
| 27 | + } | ||
| 28 | + if !b { | ||
| 29 | + elem := reflect.TypeOf(phoneAuthCheckCommand).Elem() | ||
| 30 | + for _, validErr := range valid.Errors { | ||
| 31 | + field, isExist := elem.FieldByName(validErr.Field) | ||
| 32 | + if isExist { | ||
| 33 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
| 34 | + } else { | ||
| 35 | + return fmt.Errorf(validErr.Message) | ||
| 36 | + } | ||
| 37 | + } | ||
| 38 | + } | ||
| 39 | + return nil | ||
| 40 | +} |
| 1 | +package command | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + "reflect" | ||
| 6 | + "strings" | ||
| 7 | + | ||
| 8 | + "github.com/beego/beego/v2/core/validation" | ||
| 9 | +) | ||
| 10 | + | ||
| 11 | +type PhoneAuthResetPasswordCommand struct { | ||
| 12 | + // 手机号码 | ||
| 13 | + Phone string `cname:"手机号码" json:"phone" valid:"Required"` | ||
| 14 | + // 密码 | ||
| 15 | + Password string `cname:"密码" json:"password" valid:"Required"` | ||
| 16 | +} | ||
| 17 | + | ||
| 18 | +func (phoneAuthResetPasswordCommand *PhoneAuthResetPasswordCommand) Valid(validation *validation.Validation) { | ||
| 19 | + validation.SetError("CustomValid", "未实现的自定义认证") | ||
| 20 | +} | ||
| 21 | + | ||
| 22 | +func (phoneAuthResetPasswordCommand *PhoneAuthResetPasswordCommand) ValidateCommand() error { | ||
| 23 | + valid := validation.Validation{} | ||
| 24 | + b, err := valid.Valid(phoneAuthResetPasswordCommand) | ||
| 25 | + if err != nil { | ||
| 26 | + return err | ||
| 27 | + } | ||
| 28 | + if !b { | ||
| 29 | + elem := reflect.TypeOf(phoneAuthResetPasswordCommand).Elem() | ||
| 30 | + for _, validErr := range valid.Errors { | ||
| 31 | + field, isExist := elem.FieldByName(validErr.Field) | ||
| 32 | + if isExist { | ||
| 33 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
| 34 | + } else { | ||
| 35 | + return fmt.Errorf(validErr.Message) | ||
| 36 | + } | ||
| 37 | + } | ||
| 38 | + } | ||
| 39 | + return nil | ||
| 40 | +} |
| 1 | +package command | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + "reflect" | ||
| 6 | + "strings" | ||
| 7 | + | ||
| 8 | + "github.com/beego/beego/v2/core/validation" | ||
| 9 | +) | ||
| 10 | + | ||
| 11 | +type PhoneAuthResetPhoneCommand struct { | ||
| 12 | + // 用户Id 用户唯一标识 | ||
| 13 | + UserId int64 `cname:"用户Id 用户唯一标识" json:"userId,string" valid:"Required"` | ||
| 14 | + OldPhone int `cname:"" json:"oldPhone" valid:"Required"` | ||
| 15 | + NewPhone int `cname:"" json:"newPhone" valid:"Required"` | ||
| 16 | +} | ||
| 17 | + | ||
| 18 | +func (phoneAuthResetPhoneCommand *PhoneAuthResetPhoneCommand) Valid(validation *validation.Validation) { | ||
| 19 | + validation.SetError("CustomValid", "未实现的自定义认证") | ||
| 20 | +} | ||
| 21 | + | ||
| 22 | +func (phoneAuthResetPhoneCommand *PhoneAuthResetPhoneCommand) ValidateCommand() error { | ||
| 23 | + valid := validation.Validation{} | ||
| 24 | + b, err := valid.Valid(phoneAuthResetPhoneCommand) | ||
| 25 | + if err != nil { | ||
| 26 | + return err | ||
| 27 | + } | ||
| 28 | + if !b { | ||
| 29 | + elem := reflect.TypeOf(phoneAuthResetPhoneCommand).Elem() | ||
| 30 | + for _, validErr := range valid.Errors { | ||
| 31 | + field, isExist := elem.FieldByName(validErr.Field) | ||
| 32 | + if isExist { | ||
| 33 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
| 34 | + } else { | ||
| 35 | + return fmt.Errorf(validErr.Message) | ||
| 36 | + } | ||
| 37 | + } | ||
| 38 | + } | ||
| 39 | + return nil | ||
| 40 | +} |
pkg/application/auth/command/refreshim.go
0 → 100644
| 1 | +package command | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + "reflect" | ||
| 6 | + "strings" | ||
| 7 | + | ||
| 8 | + "github.com/beego/beego/v2/core/validation" | ||
| 9 | +) | ||
| 10 | + | ||
| 11 | +type RefreshIMCommand struct { | ||
| 12 | + // 手机号码 | ||
| 13 | + Phone string `cname:"手机号码" json:"phone" valid:"Required"` | ||
| 14 | +} | ||
| 15 | + | ||
| 16 | +func (refreshIMCommand *RefreshIMCommand) Valid(validation *validation.Validation) { | ||
| 17 | + validation.SetError("CustomValid", "未实现的自定义认证") | ||
| 18 | +} | ||
| 19 | + | ||
| 20 | +func (refreshIMCommand *RefreshIMCommand) ValidateCommand() error { | ||
| 21 | + valid := validation.Validation{} | ||
| 22 | + b, err := valid.Valid(refreshIMCommand) | ||
| 23 | + if err != nil { | ||
| 24 | + return err | ||
| 25 | + } | ||
| 26 | + if !b { | ||
| 27 | + elem := reflect.TypeOf(refreshIMCommand).Elem() | ||
| 28 | + for _, validErr := range valid.Errors { | ||
| 29 | + field, isExist := elem.FieldByName(validErr.Field) | ||
| 30 | + if isExist { | ||
| 31 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
| 32 | + } else { | ||
| 33 | + return fmt.Errorf(validErr.Message) | ||
| 34 | + } | ||
| 35 | + } | ||
| 36 | + } | ||
| 37 | + return nil | ||
| 38 | +} |
pkg/application/auth/query/user_info.go
0 → 100644
| 1 | +package query | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + "reflect" | ||
| 6 | + "strings" | ||
| 7 | + | ||
| 8 | + "github.com/beego/beego/v2/core/validation" | ||
| 9 | +) | ||
| 10 | + | ||
| 11 | +type UserInfoQuery struct { | ||
| 12 | +} | ||
| 13 | + | ||
| 14 | +func (userInfoQuery *UserInfoQuery) Valid(validation *validation.Validation) { | ||
| 15 | + //validation.SetError("CustomValid", "未实现的自定义认证") | ||
| 16 | +} | ||
| 17 | + | ||
| 18 | +func (userInfoQuery *UserInfoQuery) ValidateQuery() error { | ||
| 19 | + valid := validation.Validation{} | ||
| 20 | + b, err := valid.Valid(userInfoQuery) | ||
| 21 | + if err != nil { | ||
| 22 | + return err | ||
| 23 | + } | ||
| 24 | + if !b { | ||
| 25 | + elem := reflect.TypeOf(userInfoQuery).Elem() | ||
| 26 | + for _, validErr := range valid.Errors { | ||
| 27 | + field, isExist := elem.FieldByName(validErr.Field) | ||
| 28 | + if isExist { | ||
| 29 | + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1)) | ||
| 30 | + } else { | ||
| 31 | + return fmt.Errorf(validErr.Message) | ||
| 32 | + } | ||
| 33 | + } | ||
| 34 | + } | ||
| 35 | + return nil | ||
| 36 | +} |
pkg/application/auth/service/auth.go
0 → 100644
| 1 | +package service | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "github.com/linmadan/egglib-go/core/application" | ||
| 5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/auth/command" | ||
| 6 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/auth/query" | ||
| 7 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/factory" | ||
| 8 | +) | ||
| 9 | + | ||
| 10 | +// 认证服务 | ||
| 11 | +type AuthService struct { | ||
| 12 | +} | ||
| 13 | + | ||
| 14 | +// 企业注册 | ||
| 15 | +func (authService *AuthService) CompanySignUp(companySignUpCommand *command.CompanySignUpCommand) (interface{}, error) { | ||
| 16 | + if err := companySignUpCommand.ValidateCommand(); err != nil { | ||
| 17 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
| 18 | + } | ||
| 19 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
| 20 | + if err != nil { | ||
| 21 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 22 | + } | ||
| 23 | + if err := transactionContext.StartTransaction(); err != nil { | ||
| 24 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 25 | + } | ||
| 26 | + defer func() { | ||
| 27 | + transactionContext.RollbackTransaction() | ||
| 28 | + }() | ||
| 29 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
| 30 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 31 | + } | ||
| 32 | + return nil, nil | ||
| 33 | +} | ||
| 34 | + | ||
| 35 | +// 注销账号 (添加用户时重新激活) | ||
| 36 | +func (authService *AuthService) DestroyAccount(destroyAccountCommand *command.DestroyAccountCommand) (interface{}, error) { | ||
| 37 | + if err := destroyAccountCommand.ValidateCommand(); err != nil { | ||
| 38 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
| 39 | + } | ||
| 40 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
| 41 | + if err != nil { | ||
| 42 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 43 | + } | ||
| 44 | + if err := transactionContext.StartTransaction(); err != nil { | ||
| 45 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 46 | + } | ||
| 47 | + defer func() { | ||
| 48 | + transactionContext.RollbackTransaction() | ||
| 49 | + }() | ||
| 50 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
| 51 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 52 | + } | ||
| 53 | + return nil, nil | ||
| 54 | +} | ||
| 55 | + | ||
| 56 | +// 修改密码 | ||
| 57 | +func (authService *AuthService) PhoneAuthChangePassword(phoneAuthChangePasswordCommand *command.PhoneAuthChangePasswordCommand) (interface{}, error) { | ||
| 58 | + if err := phoneAuthChangePasswordCommand.ValidateCommand(); err != nil { | ||
| 59 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
| 60 | + } | ||
| 61 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
| 62 | + if err != nil { | ||
| 63 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 64 | + } | ||
| 65 | + if err := transactionContext.StartTransaction(); err != nil { | ||
| 66 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 67 | + } | ||
| 68 | + defer func() { | ||
| 69 | + transactionContext.RollbackTransaction() | ||
| 70 | + }() | ||
| 71 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
| 72 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 73 | + } | ||
| 74 | + return nil, nil | ||
| 75 | +} | ||
| 76 | + | ||
| 77 | +// 手机账号密码检查 | ||
| 78 | +func (authService *AuthService) PhoneAuthCheck(phoneAuthCheckCommand *command.PhoneAuthCheckCommand) (interface{}, error) { | ||
| 79 | + if err := phoneAuthCheckCommand.ValidateCommand(); err != nil { | ||
| 80 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
| 81 | + } | ||
| 82 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
| 83 | + if err != nil { | ||
| 84 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 85 | + } | ||
| 86 | + if err := transactionContext.StartTransaction(); err != nil { | ||
| 87 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 88 | + } | ||
| 89 | + defer func() { | ||
| 90 | + transactionContext.RollbackTransaction() | ||
| 91 | + }() | ||
| 92 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
| 93 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 94 | + } | ||
| 95 | + return nil, nil | ||
| 96 | +} | ||
| 97 | + | ||
| 98 | +// 重置密码(忘记密码) | ||
| 99 | +func (authService *AuthService) PhoneAuthResetPassword(phoneAuthResetPasswordCommand *command.PhoneAuthResetPasswordCommand) (interface{}, error) { | ||
| 100 | + if err := phoneAuthResetPasswordCommand.ValidateCommand(); err != nil { | ||
| 101 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
| 102 | + } | ||
| 103 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
| 104 | + if err != nil { | ||
| 105 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 106 | + } | ||
| 107 | + if err := transactionContext.StartTransaction(); err != nil { | ||
| 108 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 109 | + } | ||
| 110 | + defer func() { | ||
| 111 | + transactionContext.RollbackTransaction() | ||
| 112 | + }() | ||
| 113 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
| 114 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 115 | + } | ||
| 116 | + return nil, nil | ||
| 117 | +} | ||
| 118 | + | ||
| 119 | +// 重置手机号 | ||
| 120 | +func (authService *AuthService) PhoneAuthResetPhone(phoneAuthResetPhoneCommand *command.PhoneAuthResetPhoneCommand) (interface{}, error) { | ||
| 121 | + if err := phoneAuthResetPhoneCommand.ValidateCommand(); err != nil { | ||
| 122 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
| 123 | + } | ||
| 124 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
| 125 | + if err != nil { | ||
| 126 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 127 | + } | ||
| 128 | + if err := transactionContext.StartTransaction(); err != nil { | ||
| 129 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 130 | + } | ||
| 131 | + defer func() { | ||
| 132 | + transactionContext.RollbackTransaction() | ||
| 133 | + }() | ||
| 134 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
| 135 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 136 | + } | ||
| 137 | + return nil, nil | ||
| 138 | +} | ||
| 139 | + | ||
| 140 | +// 刷新IM信息 | ||
| 141 | +func (authService *AuthService) RefreshIM(refreshIMCommand *command.RefreshIMCommand) (interface{}, error) { | ||
| 142 | + if err := refreshIMCommand.ValidateCommand(); err != nil { | ||
| 143 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
| 144 | + } | ||
| 145 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
| 146 | + if err != nil { | ||
| 147 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 148 | + } | ||
| 149 | + if err := transactionContext.StartTransaction(); err != nil { | ||
| 150 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 151 | + } | ||
| 152 | + defer func() { | ||
| 153 | + transactionContext.RollbackTransaction() | ||
| 154 | + }() | ||
| 155 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
| 156 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 157 | + } | ||
| 158 | + return nil, nil | ||
| 159 | +} | ||
| 160 | + | ||
| 161 | +// 用户信息 (暂时没有使用) | ||
| 162 | +func (authService *AuthService) UserInfo(userInfoQuery *query.UserInfoQuery) (interface{}, error) { | ||
| 163 | + if err := userInfoQuery.ValidateQuery(); err != nil { | ||
| 164 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
| 165 | + } | ||
| 166 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
| 167 | + if err != nil { | ||
| 168 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 169 | + } | ||
| 170 | + if err := transactionContext.StartTransaction(); err != nil { | ||
| 171 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 172 | + } | ||
| 173 | + defer func() { | ||
| 174 | + transactionContext.RollbackTransaction() | ||
| 175 | + }() | ||
| 176 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
| 177 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 178 | + } | ||
| 179 | + return nil, nil | ||
| 180 | +} | ||
| 181 | + | ||
| 182 | +func NewAuthService(options map[string]interface{}) *AuthService { | ||
| 183 | + newAuthService := &AuthService{} | ||
| 184 | + return newAuthService | ||
| 185 | +} |
| 1 | +package controllers | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "github.com/linmadan/egglib-go/web/beego" | ||
| 5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/auth/command" | ||
| 6 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/auth/query" | ||
| 7 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/auth/service" | ||
| 8 | +) | ||
| 9 | + | ||
| 10 | +type AuthController struct { | ||
| 11 | + beego.BaseController | ||
| 12 | +} | ||
| 13 | + | ||
| 14 | +func (controller *AuthController) CompanySignUp() { | ||
| 15 | + authService := service.NewAuthService(nil) | ||
| 16 | + companySignUpCommand := &command.CompanySignUpCommand{} | ||
| 17 | + controller.Unmarshal(companySignUpCommand) | ||
| 18 | + data, err := authService.CompanySignUp(companySignUpCommand) | ||
| 19 | + controller.Response(data, err) | ||
| 20 | +} | ||
| 21 | + | ||
| 22 | +func (controller *AuthController) PhoneAuthCheck() { | ||
| 23 | + authService := service.NewAuthService(nil) | ||
| 24 | + phoneAuthCheckCommand := &command.PhoneAuthCheckCommand{} | ||
| 25 | + controller.Unmarshal(phoneAuthCheckCommand) | ||
| 26 | + data, err := authService.PhoneAuthCheck(phoneAuthCheckCommand) | ||
| 27 | + controller.Response(data, err) | ||
| 28 | +} | ||
| 29 | + | ||
| 30 | +func (controller *AuthController) PhoneAuthResetPassword() { | ||
| 31 | + authService := service.NewAuthService(nil) | ||
| 32 | + phoneAuthResetPasswordCommand := &command.PhoneAuthResetPasswordCommand{} | ||
| 33 | + controller.Unmarshal(phoneAuthResetPasswordCommand) | ||
| 34 | + data, err := authService.PhoneAuthResetPassword(phoneAuthResetPasswordCommand) | ||
| 35 | + controller.Response(data, err) | ||
| 36 | +} | ||
| 37 | + | ||
| 38 | +func (controller *AuthController) PhoneAuthChangePassword() { | ||
| 39 | + authService := service.NewAuthService(nil) | ||
| 40 | + phoneAuthChangePasswordCommand := &command.PhoneAuthChangePasswordCommand{} | ||
| 41 | + controller.Unmarshal(phoneAuthChangePasswordCommand) | ||
| 42 | + data, err := authService.PhoneAuthChangePassword(phoneAuthChangePasswordCommand) | ||
| 43 | + controller.Response(data, err) | ||
| 44 | +} | ||
| 45 | + | ||
| 46 | +func (controller *AuthController) PhoneAuthResetPhone() { | ||
| 47 | + authService := service.NewAuthService(nil) | ||
| 48 | + phoneAuthResetPhoneCommand := &command.PhoneAuthResetPhoneCommand{} | ||
| 49 | + controller.Unmarshal(phoneAuthResetPhoneCommand) | ||
| 50 | + data, err := authService.PhoneAuthResetPhone(phoneAuthResetPhoneCommand) | ||
| 51 | + controller.Response(data, err) | ||
| 52 | +} | ||
| 53 | + | ||
| 54 | +func (controller *AuthController) DestroyAccount() { | ||
| 55 | + authService := service.NewAuthService(nil) | ||
| 56 | + destroyAccountCommand := &command.DestroyAccountCommand{} | ||
| 57 | + controller.Unmarshal(destroyAccountCommand) | ||
| 58 | + data, err := authService.DestroyAccount(destroyAccountCommand) | ||
| 59 | + controller.Response(data, err) | ||
| 60 | +} | ||
| 61 | + | ||
| 62 | +func (controller *AuthController) UserInfo() { | ||
| 63 | + authService := service.NewAuthService(nil) | ||
| 64 | + userInfoQuery := &query.UserInfoQuery{} | ||
| 65 | + data, err := authService.UserInfo(userInfoQuery) | ||
| 66 | + controller.Response(data, err) | ||
| 67 | +} |
pkg/port/beego/routers/auth_router.go
0 → 100644
| 1 | +package routers | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "github.com/beego/beego/v2/server/web" | ||
| 5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/port/beego/controllers" | ||
| 6 | +) | ||
| 7 | + | ||
| 8 | +func init() { | ||
| 9 | + web.Router("/auth/company-sign-up", &controllers.AuthController{}, "Post:CompanySignUp") | ||
| 10 | + web.Router("/auth/check-password", &controllers.AuthController{}, "Post:PhoneAuthCheck") | ||
| 11 | + web.Router("/auth/reset-password", &controllers.AuthController{}, "Post:PhoneAuthResetPassword") | ||
| 12 | + web.Router("/auth/change-password", &controllers.AuthController{}, "Post:PhoneAuthChangePassword") | ||
| 13 | + web.Router("/auth/reset-phone", &controllers.AuthController{}, "Post:PhoneAuthResetPhone") | ||
| 14 | + web.Router("/auth/destroy-account", &controllers.AuthController{}, "Post:DestroyAccount") | ||
| 15 | + web.Router("/auth/userInfo", &controllers.AuthController{}, "Post:UserInfo") | ||
| 16 | +} |
| 1 | +package auth | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "net/http" | ||
| 5 | + "net/http/httptest" | ||
| 6 | + "testing" | ||
| 7 | + | ||
| 8 | + "github.com/beego/beego/v2/server/web" | ||
| 9 | + . "github.com/onsi/ginkgo" | ||
| 10 | + . "github.com/onsi/gomega" | ||
| 11 | + _ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/pg" | ||
| 12 | + _ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/port/beego" | ||
| 13 | +) | ||
| 14 | + | ||
| 15 | +func TestAuth(t *testing.T) { | ||
| 16 | + RegisterFailHandler(Fail) | ||
| 17 | + RunSpecs(t, "Beego Port Auth Correlations Test Case Suite") | ||
| 18 | +} | ||
| 19 | + | ||
| 20 | +var handler http.Handler | ||
| 21 | +var server *httptest.Server | ||
| 22 | + | ||
| 23 | +var _ = BeforeSuite(func() { | ||
| 24 | + handler = web.BeeApp.Handlers | ||
| 25 | + server = httptest.NewServer(handler) | ||
| 26 | +}) | ||
| 27 | + | ||
| 28 | +var _ = AfterSuite(func() { | ||
| 29 | + server.Close() | ||
| 30 | +}) |
| 1 | +package auth | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "github.com/go-pg/pg/v10" | ||
| 5 | + "net/http" | ||
| 6 | + | ||
| 7 | + "github.com/gavv/httpexpect" | ||
| 8 | + . "github.com/onsi/ginkgo" | ||
| 9 | + . "github.com/onsi/gomega" | ||
| 10 | + pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/pg" | ||
| 11 | +) | ||
| 12 | + | ||
| 13 | +var _ = Describe("企业注册", func() { | ||
| 14 | + var Id int64 | ||
| 15 | + BeforeEach(func() { | ||
| 16 | + _, err := pG.DB.QueryOne( | ||
| 17 | + pg.Scan(&Id), | ||
| 18 | + "INSERT INTO s () VALUES () RETURNING _id", | ||
| 19 | + ) | ||
| 20 | + Expect(err).NotTo(HaveOccurred()) | ||
| 21 | + }) | ||
| 22 | + Describe("企业注册", func() { | ||
| 23 | + Context("", func() { | ||
| 24 | + It("", func() { | ||
| 25 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
| 26 | + body := map[string]interface{}{ | ||
| 27 | + "companyName": "string", | ||
| 28 | + "contacts": "string", | ||
| 29 | + "phone": "string", | ||
| 30 | + "scale": "string", | ||
| 31 | + "industryCategory": "string", | ||
| 32 | + "password": "string", | ||
| 33 | + } | ||
| 34 | + httpExpect.POST("/auth/company-sign-up"). | ||
| 35 | + WithJSON(body). | ||
| 36 | + Expect(). | ||
| 37 | + Status(http.StatusOK). | ||
| 38 | + JSON(). | ||
| 39 | + Object(). | ||
| 40 | + ContainsKey("code").ValueEqual("code", 0). | ||
| 41 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
| 42 | + ContainsKey("data").Value("data").Object() | ||
| 43 | + }) | ||
| 44 | + }) | ||
| 45 | + }) | ||
| 46 | + AfterEach(func() { | ||
| 47 | + _, err := pG.DB.Exec("DELETE FROM s WHERE true") | ||
| 48 | + Expect(err).NotTo(HaveOccurred()) | ||
| 49 | + }) | ||
| 50 | +}) |
| 1 | +package auth | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "github.com/go-pg/pg/v10" | ||
| 5 | + "net/http" | ||
| 6 | + | ||
| 7 | + "github.com/gavv/httpexpect" | ||
| 8 | + . "github.com/onsi/ginkgo" | ||
| 9 | + . "github.com/onsi/gomega" | ||
| 10 | + pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/pg" | ||
| 11 | +) | ||
| 12 | + | ||
| 13 | +var _ = Describe("注销账号 (添加用户时重新激活)", func() { | ||
| 14 | + var Id int64 | ||
| 15 | + BeforeEach(func() { | ||
| 16 | + _, err := pG.DB.QueryOne( | ||
| 17 | + pg.Scan(&Id), | ||
| 18 | + "INSERT INTO s () VALUES () RETURNING _id", | ||
| 19 | + ) | ||
| 20 | + Expect(err).NotTo(HaveOccurred()) | ||
| 21 | + }) | ||
| 22 | + Describe("注销账号 (添加用户时重新激活)", func() { | ||
| 23 | + Context("", func() { | ||
| 24 | + It("", func() { | ||
| 25 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
| 26 | + body := map[string]interface{}{ | ||
| 27 | + "userId": "int64", | ||
| 28 | + } | ||
| 29 | + httpExpect.POST("/auth/destroy-account"). | ||
| 30 | + WithJSON(body). | ||
| 31 | + Expect(). | ||
| 32 | + Status(http.StatusOK). | ||
| 33 | + JSON(). | ||
| 34 | + Object(). | ||
| 35 | + ContainsKey("code").ValueEqual("code", 0). | ||
| 36 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
| 37 | + ContainsKey("data").Value("data").Object() | ||
| 38 | + }) | ||
| 39 | + }) | ||
| 40 | + }) | ||
| 41 | + AfterEach(func() { | ||
| 42 | + _, err := pG.DB.Exec("DELETE FROM s WHERE true") | ||
| 43 | + Expect(err).NotTo(HaveOccurred()) | ||
| 44 | + }) | ||
| 45 | +}) |
| 1 | +package auth | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "github.com/go-pg/pg/v10" | ||
| 5 | + "net/http" | ||
| 6 | + | ||
| 7 | + "github.com/gavv/httpexpect" | ||
| 8 | + . "github.com/onsi/ginkgo" | ||
| 9 | + . "github.com/onsi/gomega" | ||
| 10 | + pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/pg" | ||
| 11 | +) | ||
| 12 | + | ||
| 13 | +var _ = Describe("修改密码", func() { | ||
| 14 | + var Id int64 | ||
| 15 | + BeforeEach(func() { | ||
| 16 | + _, err := pG.DB.QueryOne( | ||
| 17 | + pg.Scan(&Id), | ||
| 18 | + "INSERT INTO s () VALUES () RETURNING _id", | ||
| 19 | + ) | ||
| 20 | + Expect(err).NotTo(HaveOccurred()) | ||
| 21 | + }) | ||
| 22 | + Describe("修改密码", func() { | ||
| 23 | + Context("", func() { | ||
| 24 | + It("", func() { | ||
| 25 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
| 26 | + body := map[string]interface{}{ | ||
| 27 | + "userId": "int64", | ||
| 28 | + "oldPassword": "string", | ||
| 29 | + "newPassword": "string", | ||
| 30 | + } | ||
| 31 | + httpExpect.POST("/auth/change-password"). | ||
| 32 | + WithJSON(body). | ||
| 33 | + Expect(). | ||
| 34 | + Status(http.StatusOK). | ||
| 35 | + JSON(). | ||
| 36 | + Object(). | ||
| 37 | + ContainsKey("code").ValueEqual("code", 0). | ||
| 38 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
| 39 | + ContainsKey("data").Value("data").Object() | ||
| 40 | + }) | ||
| 41 | + }) | ||
| 42 | + }) | ||
| 43 | + AfterEach(func() { | ||
| 44 | + _, err := pG.DB.Exec("DELETE FROM s WHERE true") | ||
| 45 | + Expect(err).NotTo(HaveOccurred()) | ||
| 46 | + }) | ||
| 47 | +}) |
| 1 | +package auth | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "github.com/go-pg/pg/v10" | ||
| 5 | + "net/http" | ||
| 6 | + | ||
| 7 | + "github.com/gavv/httpexpect" | ||
| 8 | + . "github.com/onsi/ginkgo" | ||
| 9 | + . "github.com/onsi/gomega" | ||
| 10 | + pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/pg" | ||
| 11 | +) | ||
| 12 | + | ||
| 13 | +var _ = Describe("手机账号密码检查", func() { | ||
| 14 | + var Id int64 | ||
| 15 | + BeforeEach(func() { | ||
| 16 | + _, err := pG.DB.QueryOne( | ||
| 17 | + pg.Scan(&Id), | ||
| 18 | + "INSERT INTO s () VALUES () RETURNING _id", | ||
| 19 | + ) | ||
| 20 | + Expect(err).NotTo(HaveOccurred()) | ||
| 21 | + }) | ||
| 22 | + Describe("手机账号密码检查", func() { | ||
| 23 | + Context("", func() { | ||
| 24 | + It("", func() { | ||
| 25 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
| 26 | + body := map[string]interface{}{ | ||
| 27 | + "phone": "string", | ||
| 28 | + "password": "string", | ||
| 29 | + } | ||
| 30 | + httpExpect.POST("/auth/check-password"). | ||
| 31 | + WithJSON(body). | ||
| 32 | + Expect(). | ||
| 33 | + Status(http.StatusOK). | ||
| 34 | + JSON(). | ||
| 35 | + Object(). | ||
| 36 | + ContainsKey("code").ValueEqual("code", 0). | ||
| 37 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
| 38 | + ContainsKey("data").Value("data").Object() | ||
| 39 | + }) | ||
| 40 | + }) | ||
| 41 | + }) | ||
| 42 | + AfterEach(func() { | ||
| 43 | + _, err := pG.DB.Exec("DELETE FROM s WHERE true") | ||
| 44 | + Expect(err).NotTo(HaveOccurred()) | ||
| 45 | + }) | ||
| 46 | +}) |
| 1 | +package auth | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "github.com/go-pg/pg/v10" | ||
| 5 | + "net/http" | ||
| 6 | + | ||
| 7 | + "github.com/gavv/httpexpect" | ||
| 8 | + . "github.com/onsi/ginkgo" | ||
| 9 | + . "github.com/onsi/gomega" | ||
| 10 | + pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/pg" | ||
| 11 | +) | ||
| 12 | + | ||
| 13 | +var _ = Describe("重置密码(忘记密码)", func() { | ||
| 14 | + var Id int64 | ||
| 15 | + BeforeEach(func() { | ||
| 16 | + _, err := pG.DB.QueryOne( | ||
| 17 | + pg.Scan(&Id), | ||
| 18 | + "INSERT INTO s () VALUES () RETURNING _id", | ||
| 19 | + ) | ||
| 20 | + Expect(err).NotTo(HaveOccurred()) | ||
| 21 | + }) | ||
| 22 | + Describe("重置密码(忘记密码)", func() { | ||
| 23 | + Context("", func() { | ||
| 24 | + It("", func() { | ||
| 25 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
| 26 | + body := map[string]interface{}{ | ||
| 27 | + "phone": "string", | ||
| 28 | + "password": "string", | ||
| 29 | + } | ||
| 30 | + httpExpect.POST("/auth/reset-password"). | ||
| 31 | + WithJSON(body). | ||
| 32 | + Expect(). | ||
| 33 | + Status(http.StatusOK). | ||
| 34 | + JSON(). | ||
| 35 | + Object(). | ||
| 36 | + ContainsKey("code").ValueEqual("code", 0). | ||
| 37 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
| 38 | + ContainsKey("data").Value("data").Object() | ||
| 39 | + }) | ||
| 40 | + }) | ||
| 41 | + }) | ||
| 42 | + AfterEach(func() { | ||
| 43 | + _, err := pG.DB.Exec("DELETE FROM s WHERE true") | ||
| 44 | + Expect(err).NotTo(HaveOccurred()) | ||
| 45 | + }) | ||
| 46 | +}) |
| 1 | +package auth | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "github.com/go-pg/pg/v10" | ||
| 5 | + "net/http" | ||
| 6 | + | ||
| 7 | + "github.com/gavv/httpexpect" | ||
| 8 | + . "github.com/onsi/ginkgo" | ||
| 9 | + . "github.com/onsi/gomega" | ||
| 10 | + pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/pg" | ||
| 11 | +) | ||
| 12 | + | ||
| 13 | +var _ = Describe("重置手机号", func() { | ||
| 14 | + var Id int64 | ||
| 15 | + BeforeEach(func() { | ||
| 16 | + _, err := pG.DB.QueryOne( | ||
| 17 | + pg.Scan(&Id), | ||
| 18 | + "INSERT INTO s () VALUES () RETURNING _id", | ||
| 19 | + ) | ||
| 20 | + Expect(err).NotTo(HaveOccurred()) | ||
| 21 | + }) | ||
| 22 | + Describe("重置手机号", func() { | ||
| 23 | + Context("", func() { | ||
| 24 | + It("", func() { | ||
| 25 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
| 26 | + body := map[string]interface{}{ | ||
| 27 | + "userId": "int64", | ||
| 28 | + "oldPhone": "int", | ||
| 29 | + "newPhone": "int", | ||
| 30 | + } | ||
| 31 | + httpExpect.POST("/auth/reset-phone"). | ||
| 32 | + WithJSON(body). | ||
| 33 | + Expect(). | ||
| 34 | + Status(http.StatusOK). | ||
| 35 | + JSON(). | ||
| 36 | + Object(). | ||
| 37 | + ContainsKey("code").ValueEqual("code", 0). | ||
| 38 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
| 39 | + ContainsKey("data").Value("data").Object() | ||
| 40 | + }) | ||
| 41 | + }) | ||
| 42 | + }) | ||
| 43 | + AfterEach(func() { | ||
| 44 | + _, err := pG.DB.Exec("DELETE FROM s WHERE true") | ||
| 45 | + Expect(err).NotTo(HaveOccurred()) | ||
| 46 | + }) | ||
| 47 | +}) |
| 1 | +package auth | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "github.com/go-pg/pg/v10" | ||
| 5 | + "net/http" | ||
| 6 | + | ||
| 7 | + "github.com/gavv/httpexpect" | ||
| 8 | + . "github.com/onsi/ginkgo" | ||
| 9 | + . "github.com/onsi/gomega" | ||
| 10 | + pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/pg" | ||
| 11 | +) | ||
| 12 | + | ||
| 13 | +var _ = Describe("用户信息 (暂时没有使用)", func() { | ||
| 14 | + var Id int64 | ||
| 15 | + BeforeEach(func() { | ||
| 16 | + _, err := pG.DB.QueryOne( | ||
| 17 | + pg.Scan(&Id), | ||
| 18 | + "INSERT INTO s () VALUES () RETURNING _id", | ||
| 19 | + ) | ||
| 20 | + Expect(err).NotTo(HaveOccurred()) | ||
| 21 | + }) | ||
| 22 | + Describe("用户信息 (暂时没有使用)", func() { | ||
| 23 | + Context("", func() { | ||
| 24 | + It("", func() { | ||
| 25 | + httpExpect := httpexpect.New(GinkgoT(), server.URL) | ||
| 26 | + body := map[string]interface{}{} | ||
| 27 | + httpExpect.POST("/auth/userInfo"). | ||
| 28 | + WithJSON(body). | ||
| 29 | + Expect(). | ||
| 30 | + Status(http.StatusOK). | ||
| 31 | + JSON(). | ||
| 32 | + Object(). | ||
| 33 | + ContainsKey("code").ValueEqual("code", 0). | ||
| 34 | + ContainsKey("msg").ValueEqual("msg", "ok"). | ||
| 35 | + ContainsKey("data").Value("data").Object() | ||
| 36 | + }) | ||
| 37 | + }) | ||
| 38 | + }) | ||
| 39 | + AfterEach(func() { | ||
| 40 | + _, err := pG.DB.Exec("DELETE FROM s WHERE true") | ||
| 41 | + Expect(err).NotTo(HaveOccurred()) | ||
| 42 | + }) | ||
| 43 | +}) |
-
请 注册 或 登录 后发表评论