generated from adrienaury/go-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Description
Add an endpoint to create a new user.
Request
Method
POST
URL
/users
Request Parameters
| Parameter | Description | Required | Example |
|---|---|---|---|
username |
The username of the new user. | No | johndoe |
email |
The email address of the new user. | No | john.doe@example.com |
role |
The role of the new user. | No | user |
password |
The password of the new user. | Yes | password |
Request Body
The request body should be a JSON object with the following format:
{
"username": "johndoe",
"email": "john.doe@example.com",
"role": "user",
"password": "password"
}Result
Result parameters
| Parameter | Description | Required | Example |
|---|---|---|---|
id |
The id of the new user. | Yes | 00000000-0000-0000-0000-000000000000 |
organization_id |
The id of the organization to which the user belongs. | Yes | 00000000-0000-0000-0000-000000000000 |
username |
The username of the new user. | Yes | johndoe |
email |
The email address of the new user. | Yes | john.doe@example.com |
role |
The role of the new user. | Yes | user |
max_allowed_dimensions_per_dataset |
The maximum number of dimensions allowed per dataset for the user. | No | 100 |
max_allowed_lines_per_dataset |
The maximum number of lines allowed per dataset for the user. | No | 100000 |
Result Body
The response body will be a JSON object with the following format:
{
"id": "00000000-0000-0000-0000-000000000000",
"organization_id": "00000000-0000-0000-0000-000000000000",
"username": "johndoe",
"email": "john.doe@example.com",
"role": "user",
"max_allowed_dimensions_per_dataset": 100,
"max_allowed_lines_per_dataset": 100000
}Example Curl Request
Request
curl -X POST \
-H "Content-Type: application/json" \
-d '{
"username": "johndoe",
"email": "john.doe@example.com",
"role": "user",
"password": "password"
}' \
http://localhost:8080/users
Curl Response
{
"id": "00000000-0000-0000-0000-000000000000",
"organization_id": "00000000-0000-0000-0000-000000000000",
"username": "johndoe",
"email": "john.doe@example.com",
"role": "user",
"max_allowed_dimensions_per_dataset": 100,
"max_allowed_lines_per_dataset": 100000
}
Go server
Struct
type CreateUserRequest struct {
Username string `json:"username"`
Email string `json:"email"`
Role UserRole `json:"role"`
Password string `json:"password"`
MaxAllowedDimensions int `json:"max_allowed_dimensions"`
MaxAllowedLines int `json:"max_allowed_lines"`
MaxAllowedBytes int `json:"max_allowed_bytes"`
MaxAllowedDatasets int `json:"max_allowed_datasets"`
MaxAllowedDataSources int `json:"max_allowed_datasources"`
MaxAllowedWorkspaces int `json:"max_allowed_workspaces"`
MaxAllowedMemberships int `json:"max_allowed_memberships"`
MaxAllowedIntegrations int `json:"max_allowed_integrations"`
MaxAllowedWebhooks int `json:"max_allowed_webhooks"`
DefaultDatasetSettings *DatasetSettings `json:"default_dataset_settings"`
DefaultWorkspaceSettings *WorkspaceSettings `json:"default_workspace_settings"`
DefaultDataSourceSettings *DataSourceSettings `json:"default_datasource_settings"`
}
Handler
// @Summary Creates a user
// @Description Creates a user with the specified username, email and role.
// @Tags Users
// @Accept json
// @Produce json
// @Param data body CreateUserRequest true "User data"
// @Success 200 {object} User "OK"
// @Router /users [post]
func (a *API) handleCreateUser(w http.ResponseWriter, r *http.Request) {
var request CreateUserRequest
// Parse the request body
if err := json.NewDecoder(r.Body).Decode(&request); err != nil {
http.Error(w, "Bad request", http.StatusBadRequest)
return
}
// Validate the request
if err := request.Validate(); err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
// Create the user
user, err := a.services.UserService.Create(r.Context(), &request)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
// Write the response
if err := json.NewEncoder(w).Encode(user); err != nil {
http.Error(w, "Internal server error", http.StatusInternalServerError)
return
}
}
Links
Automated Issue Details
Dear visitor,
This issue has been automatically generated from the Octopize project avatar-python to make SIGO compatible. Please vote with a thumbs up or thumbs down to assess the quality of the automatic generation.
Best regards,
The SIGO Team
Reactions are currently unavailable