- This requires docker & docker-compose to be installed, and port 9000 and 5432 to be available
- Run
make db-up
to spawn postgres container - Run
make db-migrate
to sync schema migration to latest version - Run
make db-seed
to run seeder query - Run
make api-up
to build and run API service - For development, run
make serve
instead to run directly from code, for development use go version 1.21.10 and mockery version 2.36.0
To enable sending email there is some env that need to be configured:
// .env.local
EMAIL_ENABLED=false # set to true, if you want to enable sending through google email
EMAIL_APP_PASSWORD= # generate app password from your google email in this link https://myaccount.google.com/apppasswords
EMAIL_SENDER= # put your google email here, ex: my-email@gmail.com
EMAIL_SERVER_ADDR=smtp.gmail.com:587
EMAIL_SERVER_HOST=smtp.gmail.com
This email feature is tested using GMAIL only during development.
If you already run seed query, you can use below credential to login
username | password | |
---|---|---|
user_1 | meet.vekaputra+1@gmail.com | Password1234 |
user_2 | meet.vekaputra+2@gmail.com | Password1234 |
user_3 | meet.vekaputra+3@gmail.com | Password1234 |
user_4 | meet.vekaputra+4@gmail.com | Password1234 |
Postman collection and environment can be found in the root of this project in file named tiger-kittens.postman_collection.json
and tiger-kittens.postman_environment.json
Create new user
Validation:
- email is required, must be an email, max 64 char
- password is required, between 8-20 char, must contain lower case, upper case and number
- username is required, between 6-64 char, only alphanum
Login to existing user
Validation:
- password is required, between 8-20 char, must contain lower case, upper case and number
- username is required, between 6-64 char (can be filled with email)
Create new tiger
Validation:
- lastLat is required, between -90 - 90
- lastLong is required, between -180 - 180
- lastSeen is required, RFC3339 or ISO8601
- lastPhoto is required, can only handle jpeg and png
- date_of_birth is required, date only (2006-01-02)
- name is required, between 3-64 char
- need HTTP Header 'Authorization: Bearer <access_token>'
List all tigers according to pagination
Create new sighting, will update lastLat, lastLong, lastSeen and lastPhoto in related tigerID
Validation:
- lat is required, between -90 - 90
- long is required, between -180 - 180
- photo is required, can only handle jpeg and png
- can only add new sighting if range from previous sighting > 5km, this is calculated using Haversine formula from lat & long value
- need HTTP Header 'Authorization: Bearer <access_token>'
List all sighting of 1 tiger according to pagination
GQL query can be accessed in http://localhost:9000/gql/query
Playground can be accessed in http://localhost:9000/gql/playground
, but for upload files it is recommended to use Altair GQL Client https://altairgraphql.dev/
mutation {
login(
input: {
username: "sample-mail@gmail.com",
password: "Test1234"
}
) {
accessToken
timestamp
}
}
mutation {
register(
input: {
email: "sample-mail@gmail.com",
username: "sample-username",
password: "Test1234"
}
) {
message
timestamp
}
}
// Authorization: Bearer <access_token>
mutation CreateTiger($photo: Upload!) {
createTiger(
input: {
dateOfBirth:"2024-01-01",
lastLat:-6.300428,
lastLong:107.167497,
lastPhoto:$photo,
lastSeen:"2024-05-01T00:00:00Z",
name:"sample-tiger"
}
) {
message
timestamp
}
}
{
tigers(input: {page: 1, perPage: 5}) {
data {
ID
dateOfBirth
lastLat
lastLong
lastSeen
lastPhoto
name
createdAt
updatedAt
}
pagination {
page
perPage
totalPage
totalItem
}
}
}
// Authorization: Bearer <access_token>
mutation CreateSighting($photo: Upload!) {
createSighting(
input: {
tigerID:"6",
lat:-6.400428,
long:107.167497,
photo:$photo
}
) {
message
timestamp
}
}
{
tigerSightings(input: {tigerID: "3", page: 1, perPage: 5}) {
data {
uploadedBy
tigerName
photo
lat
long
createdAt
}
pagination {
page
perPage
totalPage
totalItem
}
}
}