This is a small API that handles User entity, where the storage is a JSON file.
- The storage must remain a JSON file.
- User structure should not be reduced.
- The application should not lose any existing functionality.
Clone the repository and download dependencies.
git clone [email protected]:pershin-daniil/userapi_assessment.git
cd userapi_assessment
go mod tidy
Use make run
- to start service locally on localhost:3333
OR make rund
- to start service in docker
on localhost:8080
.
If you want to test service use command below and then use scripts in API Endpoints.
Also, you can run service locally and test it with http requests here
make rund
Returns a list of all users in the storage.
curl --location 'http://localhost:8080/api/v1/users'
{
"increment": 2,
"list": {
"1": {
"id": 1,
"displayName": "Ivan",
"email": "[email protected]",
"created": "2023-04-16T19:04:53.525308741Z",
"updated": "2023-04-16T19:04:53.525308741Z"
},
"2": {
"id": 2,
"displayName": "Ivan",
"email": "[email protected]",
"created": "2023-04-16T19:07:52.723930891Z",
"updated": "2023-04-16T19:07:52.723930891Z"
}
}
}
Adds a new user to the storage.
curl --location 'localhost:8080/api/v1/users' \
--header 'Content-Type: application/json' \
--data-raw '{
"displayName": "Ivan",
"email": "[email protected]"
}'
{
"id": 1,
"displayName": "Ivan",
"email": "[email protected]",
"created": "2023-04-16T19:04:53.525308741Z",
"updated": "2023-04-16T19:04:53.525308741Z"
}
Returns a specific user by ID.
curl --location 'localhost:8080/api/v1/users/1'
{
"id": 1,
"displayName": "Ivan",
"email": "[email protected]",
"created": "2023-04-16T19:04:53.525308741Z",
"updated": "2023-04-16T19:04:53.525308741Z"
}
Updates an existing user by ID. You can change only displayName.
curl --location --request PATCH 'localhost:8080/api/v1/users/1' \
--header 'Content-Type: application/json' \
--data '{
"displayName": "MASHA"
}'
{
"id": 1,
"displayName": "MASHA",
"email": "[email protected]",
"created": "2023-04-16T19:04:53.525308741Z",
"updated": "2023-04-16T19:28:45.540040396Z"
}
Deletes a user from the storage by ID.
curl --location --request DELETE 'localhost:8080/api/v1/users/4'
Status: 204 No Content
👉 Full task text here
👉 Make file commands
lint:
gofumpt -w .
go mod tidy
golangci-lint run
run:
go run cmd/userapi/main.go
test:
go test -v ./tests/userapi_test.go
build:
docker build -f ./deploy/local/Dockerfile -t userapi .
rund: build
docker run --rm --name userapi -p 8080:3333 userapi