Search User @Tags users @Summary Search users @Description Search users by Condition @Accept json @Produce json @Success 200 {object} api.Page @Security ApiKeyAuth @Router /users/search [post]
()
| 55 | // @Security ApiKeyAuth |
| 56 | // @Router /users/search [post] |
| 57 | func (h *Handler) SearchUsers() iris.Handler { |
| 58 | return func(ctx *context.Context) { |
| 59 | pageNum, _ := ctx.Values().GetInt(pkgV1.PageNum) |
| 60 | pageSize, _ := ctx.Values().GetInt(pkgV1.PageSize) |
| 61 | |
| 62 | //pattern := ctx.URLParam("pattern") |
| 63 | var conditions commons.SearchConditions |
| 64 | if err := ctx.ReadJSON(&conditions); err != nil { |
| 65 | ctx.StatusCode(iris.StatusBadRequest) |
| 66 | ctx.Values().Set("message", err.Error()) |
| 67 | return |
| 68 | } |
| 69 | users, total, err := h.userService.Search(pageNum, pageSize, conditions.Conditions, common.DBOptions{}) |
| 70 | if err != nil { |
| 71 | if !errors.Is(err, storm.ErrNotFound) { |
| 72 | ctx.StatusCode(iris.StatusInternalServerError) |
| 73 | ctx.Values().Set("message", err.Error()) |
| 74 | return |
| 75 | } |
| 76 | } |
| 77 | us := make([]User, 0) |
| 78 | for i := range users { |
| 79 | users[i] = sanitizeUser(users[i]) |
| 80 | bindings, err := h.roleBindingService.GetRoleBindingBySubject(v1Role.Subject{Kind: "User", Name: users[i].Name}, common.DBOptions{}) |
| 81 | if err != nil && !errors.Is(err, storm.ErrNotFound) { |
| 82 | ctx.StatusCode(iris.StatusInternalServerError) |
| 83 | ctx.Values().Set("message", err.Error()) |
| 84 | return |
| 85 | } |
| 86 | roles := collections.NewStringSet() |
| 87 | for i := range bindings { |
| 88 | roles.Add(bindings[i].RoleRef) |
| 89 | } |
| 90 | us = append(us, User{ |
| 91 | User: users[i], |
| 92 | Roles: roles.ToSlice(), |
| 93 | }) |
| 94 | } |
| 95 | ctx.Values().Set("data", pkgV1.Page{Items: us, Total: total}) |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | // Create User |
| 100 | // @Tags users |
no test coverage detected