Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT][API] Find users #88

Open
youen opened this issue Mar 31, 2024 · 0 comments
Open

[FEAT][API] Find users #88

youen opened this issue Mar 31, 2024 · 0 comments

Comments

@youen
Copy link
Collaborator

youen commented Mar 31, 2024

Description

Get users, optionally filtering them by username or email.

Request

Method

GET

URL

/users

Request Parameters

Parameter Description Required Example
email email of the user No [email protected]
username username of the user No jdoe

Request Body

(none)

Result

Result parameters

Parameter Description Type
id id of the user UUID
organization_id id of the organization UUID
username username of the user string
email email of the user string
role role of the user UserRole
max_allowed_dimensions_per_dataset maximum allowed dimensions per dataset int
max_allowed_lines_per_dataset maximum allowed lines per dataset int

Result Body

(none)

Example Curl Request

curl -X GET \
  http://localhost:8080/users \
  -H 'Content-Type: application/json' \
  -H 'Accept: application/json' \
  -d '{
    "email": "[email protected]",
    "username": "jdoe"
  }'

Curl Response

HTTP/1.1 200 OK
Content-Type: application/json

[
  {
    "id": "b225cabd-7227-4901-8077-e7205425c373",
    "organization_id": "83286262-8582-4140-9295-08c32a0415a4",
    "username": "jdoe",
    "email": "[email protected]",
    "role": "user",
    "max_allowed_dimensions_per_dataset": 1000,
    "max_allowed_lines_per_dataset": 1000000
  }
]

Go server

Struct

type FindUsersRequest struct {
	Email    string `json:"email"`
	Username string `json:"username"`
}

type FindUsersResponse struct {
	Users []User `json:"users"`
}

type User struct {
	ID                              string                `json:"id"`
	OrganizationID                  string                `json:"organization_id"`
	Username                        string                `json:"username"`
	Email                           string                `json:"email"`
	Role                            UserRole             `json:"role"`
	MaxAllowedDimensionsPerDataset  int                   `json:"max_allowed_dimensions_per_dataset"`
	MaxAllowedLinesPerDataset       int                   `json:"max_allowed_lines_per_dataset"`
	MaxAllowedDimensionsPerTimeline int                   `json:"max_allowed_dimensions_per_timeline"`
	MaxAllowedLinesPerTimeline      int                   `json:"max_allowed_lines_per_timeline"`
	MaxAllowedDatasets              int                   `json:"max_allowed_datasets"`
	MaxAllowedTimelines             int                   `json:"max_allowed_timelines"`
	MaxAllowedCollaborators         int                   `json:"max_allowed_collaborators"`
	MaxAllowedDataSources           int                   `json:"max_allowed_data_sources"`
	MaxAllowedDashboards            int                   `json:"max_allowed_dashboards"`
	MaxAllowedAlerts                int                   `json:"max_allowed_alerts"`
	MaxAllowedIntegrations          int                   `json:"max_allowed_integrations"`
	MaxAllowedRoles                 int                   `json:"max_allowed_roles"`
	MaxAllowedPolicies              int                   `json:"max_allowed_policies"`
	MaxAllowedAuditLogs            int                   `json:"max_allowed_audit_logs"`
	MaxAllowedDataExports           int                   `json:"max_allowed_data_exports"`
	MaxAllowedDataImports           int                   `json:"max_allowed_data_imports"`
	MaxAllowedWebhooks              int                   `json:"max_allowed_webhooks"`
	DataExportConfiguration         DataExportConfiguration `json:"data_export_configuration"`
	DataImportConfiguration         DataImportConfiguration `json:"data_import_configuration"`
}

Handler

// FindUsers godoc
// @Tags Users
// @Description Get users, optionally filtering them by username or email.
// @Summary Find users
// @Produce json
// @Param email query string false "email of the user"
// @Param username query string false "username of the user"
// @Success 200 {object} FindUsersResponse
// @Failure 400 {object} httpmodels.ErrorResponse
// @Failure 500 {object} httpmodels.ErrorResponse
// @Router /users [get]
func (h *Handler) FindUsers(w http.ResponseWriter, r *http.Request) {
	var req FindUsersRequest
	if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
		httpmodels.RespondWithError(w, http.StatusBadRequest, "failed to decode request body", err)
		return
	}

	users, err := h.DB.FindUsers(context.Background(), req.Email, req.Username)
	if err != nil {
		httpmodels.RespondWithError(w, http.StatusInternalServerError, "failed to find users", err)
		return
	}

	resp := FindUsersResponse{
		Users: users,
	}

	httpmodels.RespondWithJSON(w, http.StatusOK, resp)
}

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant