[FEAT][API] User creation endpoint
- Dominant language
- Go
- Stars
- 6
- Forks
- 0
- PR merge metrics
- No merged PRs in 30d
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:
```json
{
"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:
```json
{
"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
- [Users.create_user](https://github.com/octopize/avatar-python/blob/0.6.2/avatars/api.py#L1150)
- [CreateUser](https://github.com/octopize/avatar-python/blob/0.6.2/avatars/api.py#L1150)
- [User](https://github.com/octopize/avatar-python/blob/0.6.2/avatars/api.py#L1150)
## Automated Issue Details
Dear visitor,
This issue has been automatically generated from the Octopize project [avatar-python](https://github.com/octopize/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
Contributor guide
Research direction
Start by reviewing the linked avatar-python Users.create_user, CreateUser, and User implementations, then inspect the Go API routing and the shown CreateUserRequest and handleCreateUser entry points. Confirm how UserService.Create and request validation are wired. Done means POST /users accepts the documented JSON and returns the specified user fields and errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- api, backend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100