Skip to content

API Documentation

irfanbozkurt edited this page Dec 17, 2022 · 8 revisions

Hippocrates

When Permission Required == 'IsAuthenticated', Token must be satisfied.

DateFormat = Will be given

Sign Up

Signup user with credentials that are needed to create a user.

URL : /auth/register/

Method : POST

Auth required : NO

Permissions required : None

Success Response

Code : 200 OK

Body

User Types:

{
    "ADMIN": 0
    "DOCTOR": 1,
    "MEMBER": 2,
}

For User:

{
    "email": [email protected],
    "password": joedoepassword,
    "type": 2,
}

Notes

  • Initially, the default signup endpoint handles the fields of the Abstract Base User class.

Login

Log user in with credentials that are needed for a user to login.

URL : /auth/login/

Method : POST

Auth required : NO

Permissions required : None

Success Response

Code : 200 OK

Body

User Types:

{
    "ADMIN": 0
    "DOCTOR": 1,
    "MEMBER": 2,
}

For User:

{
    "email": [email protected],
    "password": joedoepassword,
    "type": 2,
}

For Token:

{
    "data": {
             "email":[email protected],
             "password: joedowpassword
             }
    "token": 9944b09199c62bcf9418ad846dd0e4bbdfc6ee4b
}

Notes

  • Initially, the default signup endpoint handles the fields of the Abstract Base User class.
  • If the user is a Doctor (type: 1), they can only use their e-mail address to login.
  • If the user is a Member (type: 2), they can either use their e-mail address or their username to login. It is checked later which is used.

Me

Validate token and return personal information of the user.

URL : /auth/me/

Method : GET

Auth required : YES

Permissions required : IsAuthenticated

Header

{
    "Authorization": "Token 944b09199c62bcf9418ad846dd0e4bbdfc6ee4b"
}

Body

Success Response

Code : 200 OK

Logout

Remove user's token to invalidate the token

URL : /auth/logout/

Method : GET

Auth required : YES

Permissions required : IsAuthenticated

Header

{
    "Authorization": "Token 944b09199c62bcf9418ad846dd0e4bbdfc6ee4b"
}

Body

Success Response

Code : 200 OK

Get all Posts

This endpoint gives all the posts using pagination. You can also use this endpoint for your search inquiries

URL : /forum/posts

Method : GET

Auth required : YES

Permissions required : IsAuthenticated

Header

{
    "Authorization": "Token 944b09199c62bcf9418ad846dd0e4bbdfc6ee4b"
}

Query

    ?page=int
    ?page_size=int
    ?q=space-separated string values
    ?c=exact category name as string
    ?dist=maximum distance as int
      If you provide a dist param, you also have to provide "latitude" and "longitude" params, 
      which are both float values where decimals and floating part are separated via a dot
      ?longitude=1.233333
      ?latitude=5.555555

Body

Success Response

    "items":[{
             "title" : "Test Title"
             "author" :  "Test Author"
             "body" :  "Test Body"
             "date" :   DateFormat
             "upvote" :  3
             "downvote" :  2
     },
     {
             "title" : "Test Title"
             "author" : "Test Author"
             "body" :  "Test Body"
             "date" :  DateFormat
             "upvote" :  3
             "downvote" :  2
     },
     .
     .
     .
]
     "count": 13,
     "next": link,
     "previous": link
     

Code : 200 OK

Get Post by Id

Fetch post data by id

URL : /forum/post/<id: int>

Method : GET

Auth required : YES

Permissions required : IsAuthenticated

Header

{
    "Authorization": "Token 944b09199c62bcf9418ad846dd0e4bbdfc6ee4b"
}

Body

Success Response

{       "title" : "Test Title"
        "author" :  "Test Author"
        "body" :  "Test Body"
        "date" :  DateFormat
        "upvote" :  3
        "downvote" :  2
}

Code : 200 OK

Get Posts of a User with Pagination

Fetch posts by passing-in user id

URL : /forum/post/user/<user_id: int>

Method : GET

Auth required : YES

Permissions required : IsAuthenticated

Header

{
    "Authorization": "Token 944b09199c62bcf9418ad846dd0e4bbdfc6ee4b"
}

Body

{
    "page_number": 0,
    "sort": "desc" or "asc"
}

Success Response

  • Page size is 10. The example below can be misleading in that sense.
{
    "data": [
        {
            "id": 4,
            "title": "qweqw1111eqwe",
            "body": "asdasf2222dsfasd",
            "date": "2022-11-27T12:41:34.749348",
            "upvote": 0,
            "downvote": 0,
            "author": 13
        }
    ],
    "total": 9,
    "page_number": 2,
    "last_page": 2
}

Code : 200 OK

Get Posts that were upvoted by a User

Fetch posts by passing-in user id.

URL : /profile/upvoted_posts/<user_id: int>

  • Returns upvoted posts of user with given ID

URL : /profile/upvoted_posts/

  • Returns upvoted posts of user who makes the request

Method : GET

Auth required : YES

Permissions required : IsAuthenticated

Header

{
    "Authorization": "Token 944b09199c62bcf9418ad846dd0e4bbdfc6ee4b"
}

Body

{
    "page_number": 0,
    "sort": "desc" or "asc"
}

Success Response

{
    "data": [
        {
            "id": 3,
            "title": "Title",
            "body": "Body",
            "date": "2022-11-21T19:03:12.207500",
            "upvote": 5,
            "downvote": 5,
            "author": 5
        },
        {
            "id": 4,
            "title": "qweqw1111eqwe",
            "body": "asdasf2222dsfasd",
            "date": "2022-11-27T12:41:34.749348",
            "upvote": 1,
            "downvote": 0,
            "author": 13
        },
        {
            "id": 5,
            "title": "ewqeqweqwe",
            "body": "eeeee",
            "date": "2022-11-27T12:41:41.367483",
            "upvote": 1,
            "downvote": 0,
            "author": 13
        }
    ],
    "total": 3,
    "page_number": 0,
    "last_page": 0
}

Code : 200 OK

Create Post

Create a new post with necessary info.

URL : /forum/post

Method : POST

Auth required : YES

Permissions required : IsAuthenticated

Header

{
    "Authorization": "Token 944b09199c62bcf9418ad846dd0e4bbdfc6ee4b"
}

Body

{       "title" : "Test Title"
        "author" :  "Test Author"
        "body" :  "Test Body"
        "image_urls": ["url1", "url2"]
}

Success Response

{       "post: {
               "title" : "Test Title",
               "author" :  "Test Author",
               "body" :  "Test Body",
               "date" :  DateFormat,
               "upvote" :  0,
                "downvote" : 0,
               },
        "image_urls":["url1", "url2"]
}

Code : 200 OK

Upvote and Downvote Post by Id

Fetch post data by id

URL : /forum/post/<id: int>/upvote URL : /forum/post/<id: int>/downvote

Method : POST

Auth required : YES

Permissions required : IsAuthenticated

Header

{
    "Authorization": "Token 944b09199c62bcf9418ad846dd0e4bbdfc6ee4b"
}

Body

Success Response

{       "title" : "Test Title"
        "author" :  "Test Author"
        "body" :   "Test Body"
        "date" :   DateFormat
        "upvote" :   3
        "downvote" :   2
}

Code : 200 OK

Upvote and Downvote Comment by Id

Fetch post data by id

URL : /forum/post/comment/<id: int>/upvote URL : /forum/post/comment/<id: int>/downvote

Method : POST

Auth required : YES

Permissions required : IsAuthenticated

Header

{
    "Authorization": "Token 944b09199c62bcf9418ad846dd0e4bbdfc6ee4b"
}

Body

Success Response

{       
        "author" :  "Test Author"
        "body" :   "Test Body"
        "date" :   DateFormat
        "upvote" :   3
        "downvote" :   2
}

Code : 200 OK

Get all Articles

This endpoint gives all the articles using pagination.

URL : /articles/all

Method : GET

Auth required : YES

Permissions required : IsAuthenticated

Header

{
    "Authorization": "Token 944b09199c62bcf9418ad846dd0e4bbdfc6ee4b"
}

Query

    ?page=int

Body

Success Response

    "items":[{
             "title" : "Test Title"
             "author" :  "Test Author"
             "body" :   "Test Body"
             "date" :   DateFormat
             "upvote" :   3
             "downvote" :  2
     },
     {
             "title" : "Test Title"
             "author" :   "Test Author"
             "body" :   "Test Body"
             "date" :   DateFormat
             "upvote" :   3
             "downvote" :   2
     },
     .
     .
     .
]
     "count": 13,
     "next": link,
     "previous": link
     

Code : 200 OK

Create Article

Create a new article with necessary info.

URL : /articles/article

Method : POST

Auth required : YES

Permissions required : IsAuthenticated

Header

{
    "Authorization": "Token 944b09199c62bcf9418ad846dd0e4bbdfc6ee4b"
}

Body

{       "title" : "Test Title"
        "author" = "Test Author"
        "body" = "Test Body"
}

Success Response

{
               "title" : "Test Title",
               "author" :   "Test Author",
               "body" :  "Test Body",
               "date" :   DateFormat,
               "upvote" :   0,
                "downvote" :  0,
}

Code : 200 OK

Get, Update and Delete Article by Id

Fetch, update or delete article data by id

URL : /articles/article/<id: int>

Method : GET, POST, DELETE

Auth required : YES

Permissions required : IsAuthenticated

Header

{
    "Authorization": "Token 944b09199c62bcf9418ad846dd0e4bbdfc6ee4b"
}

Body

Success Response

if method == GET or UPDATE

{       "title" : "Test Title"
        "author" : "Test Author"
        "body" : "Test Body"
        "date" :  DateFormat
        "upvote" :  3
        "downvote" :  2
}

Code : 200 OK

if method == DELETE Code : 200 OK

Get Articles that were upvoted by a User

Fetch articles by passing-in user id.

URL : /profile/upvoted_articles/<user_id: int>

  • Returns upvoted articles of user with given ID

URL : /profile/upvoted_articles

  • Returns upvoted articles of user who makes the request

Method : GET

Auth required : YES

Permissions required : IsAuthenticated

Header

{
    "Authorization": "Token 944b09199c62bcf9418ad846dd0e4bbdfc6ee4b"
}

Body

{
    "page_number": 0,
    "sort": "desc" or "asc"
}

Success Response

{
    "data": [
        {
            "id": 5,
            "title": "5",
            "body": "test article body",
            "date": "2022-11-27T14:56:08.129099",
            "upvote": 1,
            "downvote": 0,
            "author": 23
        },
        {
            "id": 4,
            "title": "4",
            "body": "test article body",
            "date": "2022-11-27T14:56:04.684648",
            "upvote": 1,
            "downvote": 0,
            "author": 23
        },
        {
            "id": 3,
            "title": "3",
            "body": "test article body",
            "date": "2022-11-27T14:56:01.724406",
            "upvote": 1,
            "downvote": 0,
            "author": 23
        },
        {
            "id": 2,
            "title": "second",
            "body": "test article body",
            "date": "2022-11-27T14:55:58.392944",
            "upvote": 1,
            "downvote": 0,
            "author": 23
        }
    ],
    "total": 4,
    "page_number": 0,
    "last_page": 0
}

Code : 200 OK

Upvote and Downvote Comment by Id

Fetch post data by id

URL : /articles/article/<id: int>/upvote URL : /articles/article/<id: int>/downvote

Method : POST

Auth required : YES

Permissions required : IsAuthenticated

Header

{
    "Authorization": "Token 944b09199c62bcf9418ad846dd0e4bbdfc6ee4b"
}

Body

Success Response

{       
        "title" : "Test Title"
        "author" :   "Test Author"
        "body" : "Test Body"
        "date" : DateFormat
        "upvote" : 3
        "downvote" : 2
}

Code : 200 OK

🏠 Homepage

👤 Team Members

👤 Former Team Members

📘 About Meetings

Meeting Notes From CMPE352
Meeting Notes From CMPE451

General Meetings

Team Meetings

Backend Team Meetings
Frontend Team Meetings
Mobile Team Meetings

📌 Project

Scenarios

📌 Project Artifacts

💹 Diagrams

📝 Project Plan

📝 Deliverables

🔭 Research

📌 Practice-App

❓ Responses

Clone this wiki locally