GPCDZ code challenge
Design and implement a simple service provide REST API for Entity,
the service will have an endpoint for managing Entity(create, update, delete, list all entities, get entity).
The entity is described like this:
- socialMedia : string required
- dateCreation : date required
- dateUpdate : date required
- createdBy : user required
- latitud : long required
- longitud long required
- description : string
- type : string
for the column createdBy [user] we need to use another service called userService, this service will be provided to you
the user service Expose endpoint to manage users.
the service is protected by a simple token to secure the endpoints just for the simplicity, to get a token you need just to
use GET /api/token
GET /api/token
HTTP/1.1 200 OK
Content-Type: application/json
{
"token":"wAUnAd9ZEhwbAfFX2n5b",
"timestamp":1487176014645
}
the token expired after 10 minutes from the token creation. the timestamp is the creation date of the token.
To use the userService API you need to add token in the header for every request
key = Authorization, value = Bearer wAUnAd9ZEhwbAfFX2n5b
If the token is invalid or expired, or even if its not included in the header, you will get http status 401 unauthorized
.
- 200 No error
- 201 Created
- 400 Bad reaquest
- 401 unauthorized
- 204 No Content
POST /api/users
POST /api/users/
Content-Type: application/json
{
"username": "gpcdz",
"email":"contact@gpcdz.com",
"firstName":"gpc",
"lastName":"dz"
}
HTTP/1.1 201 Created
Content-Type: application/json
{
"id": "58a48a51ed187c0688694301",
"username": "gpcdz",
"firstName": "gpc",
"lastName": "dz",
"email": "contact@gpcdz.com"
}
GET /api/users/id or name
GET /api/users/58a48a51ed187c0688694301
HTTP/1.1 200 Ok
Content-Type: application/json
{
"id": "58a48a51ed187c0688694301",
"username": "gpcdz",
"firstName": "gpc",
"lastName": "dz",
"email": "contact@gpcdz.com"
}
GET /api/users
GET /api/users
HTTP/1.1 200 Ok
Content-Type: application/json
[
{
"id": "58a48a51ed187c0688694301",
"username": "gpcdz",
"firstName": "gpc",
"lastName": "dz",
"email": "contact@gpcdz.com"
},
{
"id": "58a48c06ed187c0688694303",
"username": "new",
"firstName": "foo",
"lastName": "bar",
"email": "contact@me.com"
}
]
DELETE /api/users/id
DELETE /api/users/58a48a51ed187c0688694301
HTTP/1.1 204 No Content
The username and the email they can not be updated
PUT /api/users
PUT /api/users
Content-Type: application/json
{
"id": "58a48a51ed187c0688694301",
"username": "gpcdz",
"email":"contact@gpcdz.com",
"firstName":"gpc",
"lastName":"dz"
}
HTTP/1.1 200 Ok
to use the api you run it locally using docker
Pull mongodb image
docker pull mongo
Pull userservice image
docker pull smidaamine/userservice
Run mongodb container don't forget to change '/my/own/datadir'
docker run --name db -v /my/own/datadir:/data/db -d mongo
Run userService container dont forget to change '/my/own/datadir'
docker run --name userserice --link db:db -p 5999:5999 -d smidaamine/userservice
now you can use userserice endpoints
localhost:5999/api/token
localhost:5999/api/users
Technologies we'd like you to use:
- Spring (Boot), but you could use anything you want
- Unit and integration testes
- Git - please create repo and do regular commits just like this was any other production project