philiplambok
7/19/2018 - 6:33 AM

ayano-with-tdd.md

Ayano with TDD

Overview

Ayano is sharing links api-only project. Ayano was build on testing driven development. Ayano project's just for learning purpose.

Enpoints

The Enpoints will be written based on features.

Authentication

Request

POST 
/api/auth
Params
{
  "auth": {
    "username": "your_username", 
    "password": "your_password"
  }
}

Response

If username and password is true

{
  "jwt": "your_token_here"
}

If username and password is false

{
  "error": {
    "code": 422,
    "message": "username or password is wrong"
  }
}

Add New Link

Request

POST 
/api/links
Params
{
  "link": {
    "title": "title of links", 
    "url": "https://philiplambok.github.io"
  }
}

Response

If success

{
  "link": {
    "title": "title of links", 
    "url": "https://philiplambok.github.io"
  }
}

if error, user not authenticate

{
  "error": {
    "code": 401, 
    "message": "you not authenticate"
  }
}

Show Link

Request

Show link data

GET 
/api/link/:id

Response

If success

{
  "link": {
    "title": "title of links", 
    "url": "https://philiplambok.github.io"
  }
}

If link not found

{
  "error": {
    "code": 404, 
    "message": "link not found"
  }
}

Show the owner of link

Resquest

GET 
/api/link/:id/user 

Response

If success

{
  "user": {
    "username": "futurebugs", 
    "role_name": "user"
  }
}

If link not found

{
  "error": {
    "code": 404, 
    "message": "link not found"
  }
}

Edit Link

Aktors:

  • Owner User
  • Admin

Request

PUT/PATCH 
/api/link/:id 

Params

{
  "link": {
    "title": "your updated name", 
    "url": "https://philiplambok.moe"
  }
}

Response

if success

{
  "link": {
    "title": "your updated name", 
    "url": "https://philiplambok.moe"
  }
}

If error, request by not owner or admin

{
  "error": {
    "code": 403, 
    "message": "Sorry, you can't update this link"
  }
}

if user not authenticated

{
  "error": {
    "code": 401, 
    "message": "you not authenticate"
  }
}

Delete Link

Aktors:

  • Owner User
  • Admin

Request

DELETE 
/api/link/:id 

Response

If success

{
  "link": {
    "title": "you updated name", 
    "url": "https://philiplambok.moe"
  } 
}

If error, request by not owner or admin

{
  "error": {
    "code": 403, 
    "message": "Sorry, you can't delete this link"
  }
}

if user not authenticated

{
  "error": {
    "code": 401, 
    "message": "you not authenticate"
  }
}

Show List Users

Request

GET 
/api/users 

Response

{
  "users": [
    {
      "user": {
        "username": "pquest",
        "role_name": "admin"
      }
    }, 
    {
      "user": {
        "username": "futurebugs", 
        "role_name": "user"
      }
    }
  ]
}

Show User

Request

GET
/api/user/:id

Response

if success

{
  "user": {
    "username": "pquest", 
    "role_name": "admin"
  }
}

if error, user not found

{
  "error": {
    "code": 404, 
    "message": "Sorry, user not found"
  }
}

Show User links

Request

GET 
/api/user/:id/links 

Response

if success

{
  "links": [
    {
      "link":{
        "title": "link one", 
        "url": "https://link.one"
      }
    }, 
    {
      "link":{
        "title": "link two", 
        "url": "https://link.two"
      }
    }, 
  ]
}

MIT License

You be free to use, copying, or something that i don't know :)