This commit is contained in:
		
							
								
								
									
										43
									
								
								router/controller/usersController.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										43
									
								
								router/controller/usersController.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,43 @@ | ||||
| package controller | ||||
|  | ||||
| import ( | ||||
| 	"drive-linked/pkg/dto" | ||||
| 	"drive-linked/pkg/service" | ||||
| 	"encoding/json" | ||||
| 	"github.com/kataras/iris/v12" | ||||
| ) | ||||
|  | ||||
| func UserProfile(ctx iris.Context) { | ||||
| 	serv := service.NewUsersService(ctx) | ||||
| 	resp := dto.NewResponse(ctx) | ||||
|  | ||||
| 	// 获取所有查询条件参数 | ||||
| 	conditions := make(map[string]interface{}) | ||||
| 	for _, field := range service.UserConditions { | ||||
| 		if ctx.URLParam(field) != "" { | ||||
| 			conditions[field] = ctx.URLParam(field) | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	if len(conditions) == 0 { | ||||
| 		resp.ErrBadRequest() | ||||
| 		return | ||||
| 	} | ||||
|  | ||||
| 	serv.GetOneUser(&conditions) | ||||
| } | ||||
|  | ||||
| func UserLogin(ctx iris.Context) { | ||||
| 	serv := service.NewUsersService(ctx) | ||||
| 	resp := dto.NewResponse(ctx) | ||||
| 	var loginParams dto.LoginParams | ||||
|  | ||||
| 	// 转换参数 | ||||
| 	body, _ := ctx.GetBody() | ||||
| 	err := json.Unmarshal(body, &loginParams) | ||||
| 	if err != nil { | ||||
| 		resp.ErrBadRequest() | ||||
| 	} | ||||
|  | ||||
| 	serv.Login(loginParams) | ||||
| } | ||||
		Reference in New Issue
	
	Block a user