Skip to content

Commit

Permalink
[wip] Patch pieces together
Browse files Browse the repository at this point in the history
  • Loading branch information
nilaymaj committed Jul 18, 2020
1 parent 6d64e93 commit 1d8a034
Show file tree
Hide file tree
Showing 41 changed files with 2,346 additions and 499 deletions.
11 changes: 11 additions & 0 deletions .flowconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[ignore]

[include]

[libs]

[lints]

[options]

[strict]
326 changes: 326 additions & 0 deletions backend_endpoints.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,326 @@
# Campus-Discuss-Backend

## API Endpoints

A description of all the API endpoints, their URL and request parameters.

### Users

#### Login

```
url : /users/auth/login/
method : POST
parameters = {
"username" : "<username>",
"password" : "<password>:
}
```

```
Successful : 200_OK
Unsuccessful : 400_BAD_REQUEST / 401_UNAUTHORIZED
```

#### Logout

```
url : /users/auth/logout/
method : POST
parameters = {}
```

```
Successful : 200_OK
Unsuccessful : 401_UNAUTHORIZED
```

#### Follow User

To follow another user.

```
url : /users/follow/
method : PUT
parameters = {"username" : "<username of the user to be followed>"}
```

```
Successful : 200_OK
Unsuccessful : 400_BAD_REQUEST / 401_UNAUTHORIZED
```

#### Unfollow User

To unfollow a user who is already followed.

```
url : /users/unfollow/
method : DELETE
parameters = {"username" : "<username of the user to be unfollowed">}
```

```
Successful : 200_OK
Unsuccessful : 400_BAD_REQUEST / 401_UNAUTHORIZED
```

#### Fetch Feed Posts

To see posts from followed users and streams

```
url : /users/feed/
method : GET
```

```
Successful : {
"post_title",
"post_text",
"pub_date",
"last_modified",
"author",
"stream"
}
Unsuccessful : 401_UNAUTHORIZED
```

#### Fetch Posts by User

To display posts corresponding to a user

```
url : /users/<int:pk>/posts
method : GET
comments : pk in url is the primary key for user
```

```
Successful : {
[
{
"post_title",
"post_text",
"pub_date",
"last_modified",
"author",
"stream"
},
],
"username"
}
Unsuccessful : 404_NOT_FOUND
```

#### Fetch Posts by Bookmarks

To display posts corresponding to bookmarks of a loggedin user

```
url: /users/bookmarks/
method: GET
comments: the user must be logged in
```

```
Successful : {
"post_title",
"post_text",
"pub_date",
"last_modified",
"author",
"stream"
}
Unsuccessful : 400_BAD_REQUEST / 401_UNAUTHORIZED
```

### Posts

#### Create Post

To create a new post

```
url : /posts/create/
method : POST
parameters = {
"title" : "<title of the post to be created>",
"text" : "<contents of the post>",
"stream" : "<title of the stream under which this post comes>"
}
```

```
Successful : 201_CREATED
Unsuccessful : 400_BAD_REQUEST / 401_UNAUTHORIZED
```

#### Delete Post

Allows deletion of a post by its author.

```
url : /posts/delete/
method : DELETE
parameters = {"pk" : "<primary key of the post>"}
```

```
Successful : 204_NO_CONTENT
Unsuccessful : 400_BAD_REQUEST / 401_UNAUTHORIZED
```

#### View Post

To see a post in detail

```
url : /posts/view/<int:pk>/
method : GET
```

```
Successful : {
"post_title",
"post_text",
"pub_date",
"last_modified",
"author",
"stream"
}
Unsuccessful : 404_NOT_FOUND
```

#### Edit Post

Edit post if user is the author.

```
url : /posts/edit/
method : PUT
parameters = {
"pk" : "<primary key of the post>",
"title" : "<new title>",
"text" : "<new content>"
}
```

```
Successful : 201_CREATED
Unsuccessful : 400_BAD_REQUEST / 401_UNAUTHORIZED
```

### Streams

#### Follow Stream

To follow a stream.

```
url : /streams/follow/
method : PUT
parameters = {"title" : "<title of the stream to be followed>"}
```

```
Successful : 200_OK
Unsuccessful : 400_BAD_REQUEST / 401_UNAUTHORIZED
```

#### Unfollow Stream

To unfollow a stream.

```
url : /streams/unfollow/
method : DELETE
parameters = {"title" : "<title of the stream to be unfollowed>"}
```

```
Successful : 200_OK
Unsuccessful : 400_BAD_REQUEST / 401_UNAUTHORIZED
```

#### Fetch Posts by Stream

To display posts corresponding to a stream

```
url : /streams/<int:pk>/posts/
method : GET
```

```
Successful : {
"title",
[
{
"post_title",
"post_text",
"pub_date",
"last_modified",
"author",
"stream"
},
]
}
Unsuccessful : 404_NOT_FOUND
```

### Bookmark

#### Bookmark/Unbookmark

To bookmark a post or to unbookmark already existing bookmark

```
url : /bookmarks/create/
method : POST
parameters = {"pk":"<primary key of the post>"}
```

```
Successful : 201_CREATED / 204_NO_CONTENT
Unsuccessful : 400_BAD_REQUEST / 401_UNAUTHORIZED
```

### Comment

#### Create Comment

To comment on post or sub-comment on a comment

```
url : /comments/create/
method : POST
parameters = {
"content" : "<content of comment>",
"post_id" : "<primary key of the post>",
"parent_id" : "<primary key of the parent comment">
}
comments : parent_id is not required if the comment is not a reply
```

```
Successful : 200_OK
Unsuccessful : 400_BAD_REQUEST / 401_UNAUTHORIZED / 404_NOT_FOUND
```

#### Delete Comment

To delete a comment on a post(all sub-comments will be deleted)/delete sub-comments(all of its sub-comments will be deleted).Recursive deletion will be followed

```
url : /comments/delete
method : DELETE
parameters = {
"pk":"<primary key of the comment>"
}
```

```
Successful : 204_NO_CONTENT
Unsuccessful : 400_BAD_REQUEST / 401_UNAUTHORIZED / 404_NOT_FOUND
```
Loading

0 comments on commit 1d8a034

Please sign in to comment.