User Management
This is a small microservice to manage access to Users.
Requirements
These dependencies can also be installed with Homebrew.
- Requires Go 1.18 or greater. This can be installed with brew
brew install go
or
downloaded here. - Requires Golangci Lint. This can be installed with brew
brew install golangci-lint
or
downloaded here. - Requires Docker and Docker Compose. This can be installed with brew
brew install docker
or
downloaded here.
Install Dependencies
Install dependencies, issue the following command(s):
make install
Testing and Formatting
To run the tests, issue the following command(s):
make test
Lint only
Run linting only:
make lint
How to Run
To run the application, simply issue the following example command(s):
make local
Environment Variables
Environment variables needed to start the application are:
Variable | Description | Required | Example/Default |
---|
API_HOST | Host that the exposed api endpoints should be run on | :x: | 0.0.0.0 |
API_PORT | Port that the exposed api endpoints will listen on for request | :x: | 8000 |
API_MONGO_URI | Mongo instance URI | ✓ | mongodb://mongo:27017 |
API_MONGO_DB_NAME | Mongo Database Name to initialize | ✓ | usermanagement |
API Endpoints
Base URLs:
Health check
GET /_healthz
Returns 200 if the service is up and running
Example responses
200 Response
"OK"
Responses
Status | Meaning | Description | Schema |
---|
200 | OK | Service is up and running | string |
getUsers
GET /users
Parameters
Name | In | Type | Required | Description |
---|
country | query | string | false | User country |
email | query | string | false | User email |
page | query | integer(int64) | true | Page number |
limit | query | integer(int64) | true | Number of users per page |
Example responses
200 Response
{
"users": [
{
"_id": "string",
"first_name": "John",
"last_name": "Doe",
"nickname": "jd",
"email": "js@example.com",
"country": "UK",
"created_at": "2019-08-24T14:15:22Z",
"updated_at": "2019-08-24T14:15:22Z"
}
]
}
Responses
This operation does not require authentication
createUser
POST /users
Body parameter
{
"first_name": "John",
"last_name": "Doe",
"nickname": "jd",
"email": "js@example.com",
"password": "worm",
"country": "UK"
}
Parameters
Example responses
201 Response
{
"_id": "string"
}
Responses
deleteUser
DELETE /users/{id}
Parameters
Name | In | Type | Required | Description |
---|
id | path | string | true | User ID |
Example responses
400 Response
{
"message": "string"
}
Responses
updateUser
PUT /users/{id}
Body parameter
{
"first_name": "John",
"last_name": "Doe",
"nickname": "jd",
"email": "js@example.com",
"password": "worm",
"country": "UK"
}
Parameters
Name | In | Type | Required | Description |
---|
id | path | string | true | User ID |
body | body | UserUpdateData | false | none |
Example responses
200 Response
{
"_id": "string",
"first_name": "John",
"last_name": "Doe",
"nickname": "jd",
"email": "js@example.com",
"country": "UK",
"created_at": "2019-08-24T14:15:22Z",
"updated_at": "2019-08-24T14:15:22Z"
}
Responses
Schemas
GetUsersResponse
{
"users": [
{
"_id": "string",
"first_name": "John",
"last_name": "Doe",
"nickname": "jd",
"email": "js@example.com",
"country": "UK",
"created_at": "2019-08-24T14:15:22Z",
"updated_at": "2019-08-24T14:15:22Z"
}
]
}
Properties
Name | Type | Required | Restrictions | Description |
---|
users | [User] | false | none | none |
CreateUserResponse
{
"_id": "string"
}
Properties
Name | Type | Required | Restrictions | Description |
---|
_id | Id | true | none | none |
User
{
"_id": "string",
"first_name": "John",
"last_name": "Doe",
"nickname": "jd",
"email": "js@example.com",
"country": "UK",
"created_at": "2019-08-24T14:15:22Z",
"updated_at": "2019-08-24T14:15:22Z"
}
Properties
UserUpdateData
{
"first_name": "John",
"last_name": "Doe",
"nickname": "jd",
"email": "js@example.com",
"password": "worm",
"country": "UK"
}
Properties
UserCreateData
{
"first_name": "John",
"last_name": "Doe",
"nickname": "jd",
"email": "js@example.com",
"password": "worm",
"country": "UK"
}
Properties
Error
{
"message": "string"
}
Properties
Name | Type | Required | Restrictions | Description |
---|
message | string | true | none | none |
Id
"string"
Properties
Name | Type | Required | Restrictions | Description |
---|
anonymous | string | false | none | none |
FirstName
"John"
Properties
Name | Type | Required | Restrictions | Description |
---|
anonymous | string | false | none | none |
LastName
"Doe"
Properties
Name | Type | Required | Restrictions | Description |
---|
anonymous | string | false | none | none |
Nickname
"jd"
Properties
Name | Type | Required | Restrictions | Description |
---|
anonymous | string | false | none | none |
Email
"js@example.com"
Properties
Name | Type | Required | Restrictions | Description |
---|
anonymous | string | false | none | none |
Password
"worm"
Properties
Name | Type | Required | Restrictions | Description |
---|
anonymous | string | false | none | none |
Country
"UK"
Properties
Name | Type | Required | Restrictions | Description |
---|
anonymous | string | false | none | none |
CreatedAt
"2019-08-24T14:15:22Z"
Properties
Name | Type | Required | Restrictions | Description |
---|
anonymous | string(date-time) | false | none | none |
UpdatedAt
"2019-08-24T14:15:22Z"
Properties
Name | Type | Required | Restrictions | Description |
---|
anonymous | string(date-time) | false | none | none |