大面积重构
Response部分 usersController部分 中间件部分
This commit is contained in:
		
							
								
								
									
										20
									
								
								pkg/service/controller/usersController.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								pkg/service/controller/usersController.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,20 @@ | ||||
| package controller | ||||
|  | ||||
| import ( | ||||
| 	"drive-linked/pkg/service" | ||||
| 	"github.com/kataras/iris/v12" | ||||
| ) | ||||
|  | ||||
| func UserProfile(ctx iris.Context) { | ||||
| 	serv := service.NewUsersService(ctx) | ||||
|  | ||||
| 	// 获取所有查询条件参数 | ||||
| 	var conditions map[string]interface{} | ||||
| 	for _, field := range service.UserConditions { | ||||
| 		if ctx.Params().GetString(field) != "" { | ||||
| 			conditions[field] = ctx.Params().GetString(field) | ||||
| 		} | ||||
| 	} | ||||
| 	serv.GetOneUser(&conditions) | ||||
| 	ctx.Next() | ||||
| } | ||||
| @@ -13,26 +13,20 @@ type UsersService struct { | ||||
| 	Ctx iris.Context | ||||
| } | ||||
|  | ||||
| const ( | ||||
| 	MethodUserName  = "name" | ||||
| 	MethodUserEmail = "email" | ||||
| var ( | ||||
| 	UserConditions = [...]string{"id", "name", "email", "nickname"} | ||||
| ) | ||||
|  | ||||
| func NewUsersService(ctx iris.Context) *UsersService { | ||||
| 	return &UsersService{Ctx: ctx} | ||||
| } | ||||
|  | ||||
| func (serv *UsersService) GetOneUser(field, method string) { | ||||
| func (serv *UsersService) GetOneUser(conditions *map[string]interface{}) { | ||||
| 	var err error | ||||
| 	resp := dto.NewResponse(serv.Ctx) | ||||
| 	user := &model.User{} | ||||
|  | ||||
| 	switch method { | ||||
| 	case MethodUserName: | ||||
| 		err = user.GetByName(field) | ||||
| 	case MethodUserEmail: | ||||
| 		err = user.GetByEmail(field) | ||||
| 	} | ||||
| 	err = user.GetWithConditions(conditions) | ||||
|  | ||||
| 	switch err { | ||||
| 	case nil: | ||||
|   | ||||
		Reference in New Issue
	
	Block a user