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 reporting to posts #51

Open
wants to merge 7 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
282 changes: 281 additions & 1 deletion docs/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,31 @@ paths:
type: string
votes:
$ref: '#/components/schemas/votes'

'409':
description: This post has been removed.
content:
application/json:
schema:
type: object
required:
- error
properties:
error:
type: string
enum:
- PostRemoved
example:
error: PostRemoved
'400':
content:
application/json:
schema:
type: 'object'
properties:
BadRequest:
type: string
'500':
$ref: '#/components/responses/unexpected'
/posts/:
get:
summary: List posts
Expand Down Expand Up @@ -541,3 +565,259 @@ paths:
- type: 'null'
- type: number
minimum: 0
/posts/{post_id}/report:
put:
summary: Reports a post.
parameters:
- name: post_id
in: path
required: true
schema:
id:
type: string
example: some-masked-id
requestBody:
required: true
content:
application/json:
schema:
type: object
required:
- reason
- category
properties:
reason:
type: string
example: I don't like this content.
category:
type: string
enum:
- spam
- identifying_information
- self_harm_or_suicide
- illegal
- discriminatory
- mean
- child_related
- nsfw
- violent
- false_information
- just_dislike_it
- other
responses:
'200':
description: Successfully reported the post.
content:
application/json:
schema:
type: object
properties:
error:
type: null
value:
type: null
'400':
content:
application/json:
schema:
type: 'object'
properties:
BadRequest:
type: string
'409':
description: This post has already been reported by this user.
content:
application/json:
schema:
type: object
required:
- error
properties:
error:
type: string
enum:
- AlreadyReported
example:
error: AlreadyReported
'401':
$ref: '#/components/responses/unauthenticated'
'500':
$ref: '#/components/responses/unexpected'
/reports/posts/:
get:
summary: Lists posts based on report-based criteria.
requestBody:
content:
application/json:
schema:
type: object
properties:
seen:
type: array
items:
type: string
min_reports:
type: integer
show_removed:
type: boolean
required:
- seen
- min_reports
- show_removed
example:
seen:
- biyKRAO0HIdU8YUqST4B5g
min_reports: 0
show_removed: true
responses:
'200':
description: Successfully retrieved the list of posts.
content:
application/json:
schema:
type: object
required:
- value
properties:
value:
type: array
items:
type: object
required:
- id
- sequential_id
- reply_context
- text
- created_at
- votes
- reports
- removed
properties:
id:
$ref: '#/components/schemas/masked-id'
sequential_id:
$ref: '#/components/schemas/masked-sequential-id'
reply_context:
anyOf:
- type: 'null'
- type: object
required:
- id
properties:
id:
$ref: '#/components/schemas/masked-id'
text:
type: string
created_at:
type: string
votes:
$ref: '#/components/schemas/votes'
reports:
type: integer
example: 4
removed:
type: boolean
example: false
'400':
content:
application/json:
schema:
type: 'object'
properties:
BadRequest:
type: string
'500':
$ref: '#/components/responses/unexpected'
/reports/{post_id}/:
get:
summary: Lists detailed reports for a specific post.
parameters:
- name: post_id
in: path
required: true
schema:
id:
type: string
example: some-masked-id
requestBody:
required: true
content:
application/json:
schema:
type: string
example: some-masked-sequential-id or null
responses:
'200':
description: Success response
content:
application/json:
schema:
type: object
properties:
error:
type: null
value:
type: object
properties:
reports:
type: array
items:
type: object
properties:
reason:
type: string
category:
type: string
next:
type: string
example: some-masked-sequential-id
'400':
content:
application/json:
schema:
type: 'object'
properties:
BadRequest:
type: string
'500':
$ref: '#/components/responses/unexpected'
/posts/{post_id}/remove:
put:
summary: Updates the `removed` status of a post in the database.
parameters:
- name: post_id
in: path
required: true
schema:
id:
type: string
example: some-masked-id
requestBody:
required: true
content:
application/json:
schema:
type: boolean
example: true
responses:
'200':
description: Successfully updated the `removed` status of the post.
content:
application/json:
schema:
type: object
properties:
error:
type: null
value:
type: null
'400':
content:
application/json:
schema:
type: 'object'
properties:
BadRequest:
type: string
'500':
$ref: '#/components/responses/unexpected'
9 changes: 9 additions & 0 deletions src/conf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,21 @@ pub const SESSION_MIN_TIME_BETWEEN_REFRESH: Duration = Duration::from_secs(3600
/// The number of posts to return for each request to a post list.
pub const POSTS_PAGE_SIZE: u16 = 5;

/// The number of detailed reports to return per page.
pub const REPORT_DETAILS_PAGE_SIZE: u16 = 5;

/// The number of reported posts to return per page.
pub const REPORTED_POSTS_PAGE_SIZE: u16 = 5;

/// The maximum length of a post in UTF-8 bytes.
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 maximum length of a report reason in UTF-8 bytes.
pub const REPORT_REASON_MAX_SIZE: usize = 500;

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

Expand Down
Loading