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] Add an endpoint to retrieve the current user #89

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

[FEAT][API] Add an endpoint to retrieve the current user #89

youen opened this issue Mar 31, 2024 · 0 comments

Comments

@youen
Copy link
Member

youen commented Mar 31, 2024

Description

This endpoint allows a user to retrieve their own user information.

Request

Method

GET

URL

/users/me

Request Parameters

Parameter Description Required Example
timeout The amount of time, in seconds, to wait for the request to complete. No 30

Result

Result parameters

Parameter Description Type
id The unique identifier for the user. UUID
organization_id The unique identifier for the organization the user belongs to. UUID
username The username of the user. string
email The email address of the user. string
role The role of the user. UserRole
max_allowed_dimensions_per_dataset The maximum number of dimensions allowed per dataset for the user. int
max_allowed_lines_per_dataset The maximum number of lines allowed per dataset for the user. int

Result Body

The result body is a JSON object with the following structure:

{
  "id": "d810b289-53a3-48d9-a5e0-a16a64185635",
  "organization_id": "30e13e75-574c-42c1-8c13-c374c372c320",
  "username": "john.smith",
  "email": "[email protected]",
  "role": "user",
  "max_allowed_dimensions_per_dataset": 1000,
  "max_allowed_lines_per_dataset": 1000000
}

Example Curl Request

Request

curl -X GET http://localhost:8080/users/me

Curl Response

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

{
  "id": "d810b289-53a3-48d9-a5e0-a16a64185635",
  "organization_id": "30e13e75-574c-42c1-8c13-c374c372c320",
  "username": "john.smith",
  "email": "[email protected]",
  "role": "user",
  "max_allowed_dimensions_per_dataset": 1000,
  "max_allowed_lines_per_dataset": 1000000
}

Go server

Struct

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"`
}

Handler

func (s *server) handleGetMe(ctx context.Context, w http.ResponseWriter, r *http.Request) {

	ctx, cancel := context.WithTimeout(ctx, s.timeout)
	defer cancel()

	user, err := s.service.GetMe(ctx)
	if err != nil {
		log.Printf("failed to get user: %v", err)
		http.Error(w, http.StatusInternalServerError, http.StatusText(http.StatusInternalServerError))
		return
	}

	if err := json.NewEncoder(w).Encode(user); err != nil {
		log.Printf("failed to encode user: %v", err)
		http.Error(w, http.StatusInternalServerError, http.StatusText(http.StatusInternalServerError))
		return
	}
}
``` to the response.
    w.Write(json)
}

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