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

Adds comments #42

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
245 changes: 244 additions & 1 deletion docs/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,14 @@ components:
type: object
required:
- error
- value
properties:
error:
type: 'null'
example: {error: null}
example: null
value:
type: 'null'
example: null
username:
type: string
minLength: 1
Expand Down Expand Up @@ -369,6 +373,7 @@ paths:
- text
- created_at
- votes
- replies
properties:
id:
$ref: '#/components/schemas/masked-id'
Expand All @@ -387,6 +392,8 @@ paths:
type: string
created_at:
type: string
replies:
type: integer
votes:
$ref: '#/components/schemas/votes'

Expand Down Expand Up @@ -431,6 +438,7 @@ paths:
- reply_context
- text
- created_at
- replies
- votes
properties:
id:
Expand All @@ -450,6 +458,8 @@ paths:
type: string
created_at:
type: string
replies:
type: integer
votes:
$ref: '#/components/schemas/votes'

Expand Down Expand Up @@ -541,3 +551,236 @@ paths:
- type: 'null'
- type: number
minimum: 0
/comments/{comment_id}/:
delete:
summary: Delete a comment
parameters:
- name: comment_id
in: path
required: true
schema:
id:
type: string
responses:
'200':
content:
application/json:
schema:
type: object
required:
- error
- value
properties:
error:
type: string
example: null
value:
type: string
example: null
'400':
content:
application/json:
schema:
type: object
required:
- BadRequest
properties:
BadRequest:
type: string
'401':
$ref: '#/components/responses/unauthenticated'
'500':
$ref: '#/components/responses/unexpected'

/comments/{comment_id}/vote:
put:
summary: Vote on comment
parameters:
- name: post_id
in: path
required: true
schema:
$ref: '#/components/schemas/masked-id'
requestBody:
required: true
content:
application/json:
schema:
type: integer
enum:
- -1
- 0
- 1
responses:
'200':
content:
application/json:
schema:
type: 'object'
required:
- value
properties:
value:
$ref: '#/components/schemas/votes'
'400':
content:
application/json:
schema:
type: 'object'
properties:
BadRequest:
type: string
'401':
$ref: '#/components/responses/unauthenticated'
'500':
$ref: '#/components/responses/unexpected'
/comments/:
post:
summary: Create comment
requestBody:
required: true
content:
application/json:
schema:
type: object
required:
- text
- parent_post
- parent_comments
properties:
text:
type: string
parent_post:
$ref: '#/components/schemas/masked-id'
parent_comments:
type: array
items:
$ref: '#/components/schemas/masked-id'
responses:
'200':
content:
application/json:
schema:
type: object
required:
- error
- value
properties:
error:
type: string
example: null
value:
type: object
required:
- id
properties:
id:
$ref: '#/components/schemas/masked-id'
'400':
content:
application/json:
schema:
type: 'object'
properties:
BadRequest:
type: string
'401':
$ref: '#/components/responses/unauthenticated'
'500':
$ref: '#/components/responses/unexpected'
get:
summary: Fetch comments from a post, or from a parent comment
requestBody:
required: true
content:
application/json:
schema:
type: object
required:
- kind
- sort
- parent
- seen
properties:
kind:
type: string
enum:
- thread
- root
sort:
type: string
enum:
- new
- top
- worst
- controversial
- best
- replies
parent:
$ref: '#/components/schemas/masked-id'
seen:
type: array
items:
$ref: '#/components/schemas/masked-id'
responses:
'200':
content:
application/json:
schema:
type: object
required:
- error
- value
properties:
error:
type: string
example: null
value:
type: array
items:
type: object
required:
- id
- parent_comments
- parent_post
- text
- replies
- children
- votes
properties:
id:
$ref: '#/components/schemas/masked-id'
parent_comments:
type: array
items:
$ref: '#/components/schemas/masked-id'
parent_post:
$ref: '#/components/schemas/masked-id'
text:
type: string
replies:
type: integer
children:
type: array
items:
$ref: '#/components/schemas/masked-id'
votes:
type: object
required:
- up
- down
properties:
up:
type: integer
down:
type: integer
'400':
content:
application/json:
schema:
type: 'object'
properties:
BadRequest:
type: string
'500':
$ref: '#/components/responses/unexpected'
1 change: 0 additions & 1 deletion src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use actix_web::{
ResponseError,
};
use log::{
debug,
error,
warn,
};
Expand Down
12 changes: 12 additions & 0 deletions src/conf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@ pub const POST_MAX_SIZE: usize = 1000;
/// The maximum length of a comment in UTF-8 bytes.
pub const COMMENT_MAX_SIZE: usize = 500;

/// The max depth of a comment thread.
pub const COMMENT_MAX_DEPTH: usize = 5;

/// The number of comments to return for each request to a comments list.
pub const COMMENTS_PAGE_SIZE: u16 = 5;

/// The max number of comments to return for each request to build a comment thread
pub const MAX_REPLYING_COMMENTS_PER_LOAD: u16 = 3;

/// The minimum number of comments to return for each request to build a comment thread (if available).
pub const MIN_REPLYING_COMMENTS_PER_LOAD_IF_AVAILABLE: u16 = 2;

/// The maximum length of a username.
pub const USERNAME_MAX_LENGTH: usize = 32;

Expand Down
Loading