Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backend] Travel API #69

Open
dreamsh19 opened this issue Dec 4, 2019 · 10 comments
Open

[Backend] Travel API #69

dreamsh19 opened this issue Dec 4, 2019 · 10 comments
Assignees
Labels
Backend documentation Improvements or additions to documentation

Comments

@dreamsh19
Copy link
Contributor

dreamsh19 commented Dec 4, 2019

지금까지 구현된 Travel API Reference입니다.

1. POST Travel
2. POST TravelCommit
3. GET specific Travel
4. GET recent/popular Travel

수정내역

  • 12.05 08:59 POST TravelCommit url 수정

1. POST Travel

최초로 Create Travel 할 때

# request
curl "http://localhost:8000/api/travel/" \
  -X POST \
  -d "{DATA}" \
  -H "Content-Type: application/json" \
  -H "Authorization: JWT eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoxLCJ1c2VybmFtZSI6InRlc3RAdGVzdC5pbyIsImV4cCI6MTU3NTUzNDQzMSwiZW1haWwiOiJ0ZXN0QHRlc3QuaW8ifQ.FPowpQUqR813O6I6OGmevqjKEHlDeg-JQIshUJMdkbA" 

DATA
{
  "head": {
    "days": [
      {
        "blocks": [
          {
            "title": "travelblock1 title",
            "description": "",
            "time": "16:30",
            "start_location": "travelblock1 start",
            "end_location": "travelblock1 end",
            "block_type": "ACM",
            "modified": true,
            "parent_block": null
          }
        ],
        "title": "travelDay1 title",
        "day": "2019-11-01",
        "modified": true,
        "parent_day": null
      },
      {
        "blocks": [
          {
            "title": "travelblock1 title",
            "description": "",
            "time": null,
            "start_location": "travelblock1 start",
            "end_location": "travelblock1 end",
            "block_type": "ACM",
            "modified": true,
            "parent_block": null
          }
        ],
        "title": "travelDay2 title",
        "day": "2019-11-02",
        "modified": true,
        "parent_day": null
      },
      {
        "blocks": [],
        "title": "travelDay3 title",
        "day": "2019-11-03",
        "modified": true,
        "parent_day": null
      }
    ],
    "title": "travelCommit1 title",
    "summary": "",
    "description": "",
    "start_date": "2019-11-01",
    "end_date": "2019-11-03"
  },
  "fork_parent": null
}

2. POST TravelCommit

Travel Edit 할 때

#request
curl "http://localhost:8000/api/travel/30/travelCommit/" \
  -X POST \
  -d "{DATA}" \
  -H "Content-Type: application/json" \
  -H "Authorization: JWT eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoxLCJ1c2VybmFtZSI6InRlc3RAdGVzdC5pbyIsImV4cCI6MTU3NTUzNDQzMSwiZW1haWwiOiJ0ZXN0QHRlc3QuaW8ifQ.FPowpQUqR813O6I6OGmevqjKEHlDeg-JQIshUJMdkbA" 

DATA
{
  "days": [
    {
      "id" : 72,
      "blocks": [
        {
          "title": "travelblock1 title",
          "description": "",
          "time": "16:30",
          "start_location": "travelblock1 start",
          "end_location": "travelblock1 end",
          "block_type": "ACM",
          "modified": true,
          "parent_block": null
        }
      ],
      "title": "travelDay1 title",
      "day": "2019-11-01",
      "modified": true,
      "parent_day": null
    },
    {
      "blocks": [
        {
          "title": "travelblock1 title",
          "description": "",
          "time": null,
          "start_location": "travelblock1 start",
          "end_location": "travelblock1 end",
          "block_type": "ACM",
          "modified": true,
          "parent_block": null
        }
      ],
      "title": "travelDay2 title",
      "day": "2019-11-02",
      "modified": true,
      "parent_day": null
    },
    {
      "blocks": [],
      "title": "travelDay3 title",
      "day": "2019-11-03",
      "modified": true,
      "parent_day": null
    }
  ],
  "title": "travelCommit1 NEW TITLE",
  "summary": "",
  "description": "",
  "start_date": "2019-11-01",
  "end_date": "2019-11-03"
}

3. GET specific Travel

특정 Travel 가져올 때

# request
curl "http://localhost:8000/api/travel/30" \
  -H "Authorization: JWT eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoxLCJ1c2VybmFtZSI6InRlc3RAdGVzdC5pbyIsImV4cCI6MTU3NTUzNDQzMSwiZW1haWwiOiJ0ZXN0QHRlc3QuaW8ifQ.FPowpQUqR813O6I6OGmevqjKEHlDeg-JQIshUJMdkbA" 

#response
{
  "id": 30,
  "head": {
    "id": 35,
    "days": [
      {
        "id": 93,
        "blocks": [
          {
            "id": 61,
            "title": "travelblock1 title",
            "description": "",
            "time": "16:30:00",
            "start_location": "travelblock1 start",
            "end_location": "travelblock1 end",
            "block_type": "ACM",
            "modified": true,
            "parent_block": null
          }
        ],
        "title": "travelDay1 title",
        "day": "2019-11-01",
        "modified": true,
        "parent_day": null
      },
      {
        "id": 94,
        "blocks": [
          {
            "id": 62,
            "title": "travelblock1 title",
            "description": "",
            "time": null,
            "start_location": "travelblock1 start",
            "end_location": "travelblock1 end",
            "block_type": "ACM",
            "modified": true,
            "parent_block": null
          }
        ],
        "title": "travelDay2 title",
        "day": "2019-11-02",
        "modified": true,
        "parent_day": null
      },
      {
        "id": 95,
        "blocks": [],
        "title": "travelDay3 title",
        "day": "2019-11-03",
        "modified": true,
        "parent_day": null
      }
    ],
    "title": "travelCommit1 NEW TITLE",
    "summary": "",
    "description": "",
    "start_date": "2019-11-01",
    "end_date": "2019-11-03",
    "travel": 30,
    "author": 1
  },
  "is_public": true,
  "allow_comments": true,
  "author": 1,
  "fork_parent": null,
  "collaborators": [
    2
  ],
  "likes": [
    1,
    2
  ]
}

4. GET Recent Travel & GET Popular Travel

Recent Travel : 가장 최신의 Travel 10개 가져올 때(최종수정시간 기준)
Popular Travel : 가장 인기있는 Travel 10개 가져올 때(like수 기준)

#request
curl "http://localhost:8000/api/travel/recent/" \  
(또는 curl "http://localhost:8000/api/travel/popular/" \ )
  -H "Authorization: JWT eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoxLCJ1c2VybmFtZSI6InRlc3RAdGVzdC5pbyIsImV4cCI6MTU3NTUzNDQzMSwiZW1haWwiOiJ0ZXN0QHRlc3QuaW8ifQ.FPowpQUqR813O6I6OGmevqjKEHlDeg-JQIshUJMdkbA" 

#response
[
  {
    "id": 38,
    "head": {
      "id": 37,
      "days": [
        {
          "id": 96,
          "blocks": [
            {
              "id": 63,
              "title": "travelblock1 title",
              "description": "",
              "time": "16:30:00",
              "start_location": "travelblock1 start",
              "end_location": "travelblock1 end",
              "block_type": "ACM",
              "modified": true,
              "parent_block": null
            }
          ],
          "title": "travelDay1 title",
          "day": "2019-11-01",
          "modified": true,
          "parent_day": null
        },
        {
          "id": 97,
          "blocks": [
            {
              "id": 64,
              "title": "travelblock1 title",
              "description": "",
              "time": null,
              "start_location": "travelblock1 start",
              "end_location": "travelblock1 end",
              "block_type": "ACM",
              "modified": true,
              "parent_block": null
            }
          ],
          "title": "travelDay2 title",
          "day": "2019-11-02",
          "modified": true,
          "parent_day": null
        },
        {
          "id": 98,
          "blocks": [],
          "title": "travelDay3 title",
          "day": "2019-11-03",
          "modified": true,
          "parent_day": null
        }
      ],
      "title": "travelCommit1 title",
      "summary": "",
      "description": "",
      "start_date": "2019-11-01",
      "end_date": "2019-11-03",
      "travel": 38,
      "author": 1
    },
    "is_public": true,
    "allow_comments": true,
    "author": 1,
    "fork_parent": null,
    "collaborators": [],
    "likes": []
  },
  {
    "id": 37,
    "head": {
      "id": 36,
      "days": [],
      "title": "travelCommit1 title",
      "summary": "",
      "description": "",
      "start_date": "2019-11-01",
      "end_date": "2019-11-03",
      "travel": 37,
      "author": 1
    },
    "is_public": true,
    "allow_comments": true,
    "author": 1,
    "fork_parent": null,
    "collaborators": [],
    "likes": []
  }, 
...
]
@deploy-soon
Copy link
Contributor

정말 감사합니다!

2. POST TravelCommit 에서 url에 추가 정보 없이 data에 있는 id를 통해 travel을 구분하게 되는건가요?

@deploy-soon deploy-soon added Backend documentation Improvements or additions to documentation labels Dec 4, 2019
@dreamsh19
Copy link
Contributor Author

2. POST TravelCommit 에서 url에 추가 정보 없이 data에 있는 id를 통해 travel을 구분하게 되는건가요?

네 맞습니다. 근데 생각해보니 travel/id로 POST 요청을 보내도록 수정하는 게 좀 더 자연스러울것 같네요

@jang1suh
Copy link
Contributor

jang1suh commented Dec 5, 2019

@dreamsh19
유저 페이지를 구현할 때 travel에 user id를 주면 해당 유저가 작성한 모든 plan의 list를 주는 API가 필요할 것 같습니다. 작성하신 백엔드 코드 참고해 filter 이용하면 간단히 만들 수 있을 것 같은데, 제가 작성해도 괜찮을까요? /api/travel/user/:id로 요청 보내는 걸로요.
나중에 collaborator 관련해서나 user search 구현할 때도 제가 백엔드까지 만드는 게 효율적일 것 같습니다.

@jang1suh
Copy link
Contributor

jang1suh commented Dec 6, 2019

5. GET Travel List of an Author User

# request
curl "http://localhost:8000/api/travel/user/1/" \  
    -H "Authorization: JWT eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoxLCJ1c2VybmFtZSI6InRlc3RAdGVzdC5pbyIsImV4cCI6MTU3NTUzNDQzMSwiZW1haWwiOiJ0ZXN0QHRlc3QuaW8ifQ.FPowpQUqR813O6I6OGmevqjKEHlDeg-JQIshUJMdkbA" 
# response
[
  {
  ...
   "author": 1,
    ...
  },
   ...
  (List of travels whose author is "1") 
]

@jang1suh
Copy link
Contributor

jang1suh commented Dec 8, 2019

@dreamsh19
likes는 like를 누른 유저의 리스트로 구현된 게 맞나요? 그러면 like 수 집계할 때 likes.length 써도 될까요?

@dreamsh19
Copy link
Contributor Author

likes는 like를 누른 유저의 리스트로 구현된 게 맞나요? 그러면 like 수 집계할 때 likes.length 써도 될까요?
@rxwe 넵 맞습니다! 프론트에서 쓸 때는 likes.length를 쓰면 될 것 같습니다!

@jang1suh
Copy link
Contributor

jang1suh commented Dec 8, 2019

@dreamsh19
넵 감사합니다ㅎㅎ

@jang1suh
Copy link
Contributor

6. GET Travel list that a user is a collaborator of the travel

# request
curl "http://localhost:8000/api/travel/collaborator/1/" \  
    -H "Authorization: JWT eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoxLCJ1c2VybmFtZSI6InRlc3RAdGVzdC5pbyIsImV4cCI6MTU3NTUzNDQzMSwiZW1haWwiOiJ0ZXN0QHRlc3QuaW8ifQ.FPowpQUqR813O6I6OGmevqjKEHlDeg-JQIshUJMdkbA" 

# response
[
  {
  ...
   "collaborators": [1, ...],
    ...
  },
   ...
  (List of travels which include "1" in collaborators field) 
]

@jang1suh
Copy link
Contributor

jang1suh commented Dec 11, 2019

7. PUT Travel settings

# request
curl "http://localhost:8000/api/travel/settings/1/" \
  -X PUT \
  -d "{DATA}" \
  -H "Content-Type: application/json" \
  -H "Authorization: JWT eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoxLCJ1c2VybmFtZSI6InRlc3RAdGVzdC5pbyIsImV4cCI6MTU3NTUzNDQzMSwiZW1haWwiOiJ0ZXN0QHRlc3QuaW8ifQ.FPowpQUqR813O6I6OGmevqjKEHlDeg-JQIshUJMdkbA" 

DATA
{
  "id": 1,
  "added_collaborator": 'testnickname',  // added_collaborator엔 nickname이 들어갑니다.
  "deleted_collaborator": 20  // deleted_collaborator엔 id가 들어갑니다.
  "is_public": true,
  "allow_comments": false
}
(한두개 필드만 담아서 요청 보내도 됩니다.)

# response
{
  "id": 1,
  ... a travel data with the same id value
}

@jang1suh
Copy link
Contributor

jang1suh commented Dec 13, 2019

DELETE travel을 구현해야 할 것 같은데, id가 30인 travel을 삭제해야 한다고 하면

  • Travel model에선 id가 30인 travel 하나
  • TravelCommit model에선 travel 필드(FK)의 id 30인 모든 travel commits

를 모두 삭제하는 식으로 구현해야 하는 게 맞나요?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backend documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

3 participants