RegisterUserToInternal registers users as internal users and associates them with departments @Summary Register users as internal users and associate with departments @Description Batch process user IDs and department IDs, update user information and add department associations within a transaction
(c *gin.Context)
| 1094 | // @Success 200 {object} model.CommonResponse |
| 1095 | // @Router /api/users/register/to/internal [put] |
| 1096 | func RegisterUserToInternal(c *gin.Context) { |
| 1097 | var req RegisterUserToInternalRequest |
| 1098 | if err := c.ShouldBindJSON(&req); err != nil { |
| 1099 | c.JSON(http.StatusBadRequest, model.ParamError.ToResponse(err)) |
| 1100 | return |
| 1101 | } |
| 1102 | |
| 1103 | if len(req.UserDepartments) == 0 { |
| 1104 | c.JSON(http.StatusBadRequest, model.ParamError.ToNewErrorResponse("User-department mapping cannot be empty")) |
| 1105 | return |
| 1106 | } |
| 1107 | |
| 1108 | eid := config.GetEID(c) |
| 1109 | if eid <= 0 { |
| 1110 | c.JSON(http.StatusBadRequest, model.ParamError.ToNewErrorResponse(model.InvalidEnterpriseID)) |
| 1111 | return |
| 1112 | } |
| 1113 | |
| 1114 | mappings := make([]service.UserDepartmentMapping, len(req.UserDepartments)) |
| 1115 | for i, mapping := range req.UserDepartments { |
| 1116 | mappings[i] = service.UserDepartmentMapping{ |
| 1117 | UserID: mapping.UserID, |
| 1118 | DIDs: mapping.DIDs, |
| 1119 | } |
| 1120 | } |
| 1121 | |
| 1122 | userService := service.UserService{} |
| 1123 | result, err := userService.RegisterUserToInternal(eid, mappings) |
| 1124 | if err != nil { |
| 1125 | c.JSON(http.StatusInternalServerError, model.DBError.ToResponse(err)) |
| 1126 | return |
| 1127 | } |
| 1128 | |
| 1129 | c.JSON(http.StatusOK, model.Success.ToResponse(gin.H{ |
| 1130 | "success_count": result.SuccessCount, |
| 1131 | "failed_users": result.FailedUsers, |
| 1132 | "total": result.Total, |
| 1133 | })) |
| 1134 | } |
| 1135 | |
| 1136 | // InternalUserRequest 定义获取内部用户列表的请求参数 |
| 1137 | type InternalUserRequest struct { |
nothing calls this directly
no test coverage detected