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

Hottest endpoint added (2nd time around) #29

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
16 changes: 16 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Cargo.lock
target/
guide/build/
/gh-pages

*.so
*.out
*.pyc
*.pid
*.sock
*~
.DS_Store
**/*.rs.bk
.idea
.vscode
.prettierignore
123 changes: 120 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ ring = { version = '^0.16.0', default-features = false, features = ['std'] }
serde = { version = '^1.0.139', features = ['derive'] }
serde_json = '^1.0.82'
serde_with = '^1.14.0'
chrono = "0.4.23"
73 changes: 73 additions & 0 deletions docs/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,79 @@ paths:
'500':
$ref: '#/components/responses/unexpected'

/posts/hottest/:
get:
summary: Get the hottest posts from a specific day
description: Example => http://localhost:3000/posts/hottest/?date=1676440599281
parameters:
- name: date
in: query
required: false
schema:
type: string
example: 1676440599281
responses:
'400':
description: Some part of the request was malformed, or invalid.
content:
application/json:
schema:
type: object
properties:
error:
type: string
enum:
- BadRequest
'200':
content:
application/json:
schema:
type: 'object'
required:
- value
properties:
error:
type: string
enum:
- null
value:
type: 'object'
required:
- posts
properties:
posts:
type: array
items:
type: object
required:
- id
- sequential_id
- reply_context
- text
- created_at
- votes
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'


/posts/{post_id}/vote:
put:
summary: Vote on post
Expand Down
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::http::StatusCode;
use actix_web::http::header;
use actix_web::web;
use log::{
debug,
error,
warn,
};
Expand Down
3 changes: 3 additions & 0 deletions src/conf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,6 @@ pub const PERMITTED_ORIGINS: &[&str] = &[
pub const TRENDING_EPOCH: i64 = 1640995200; // 2022-01-01T00:00:00Z

pub const TRENDING_DECAY: f64 = 103616.32918473207; // 45000 ln 10

/// The number of hottest posts that are visible daily on the "hottests" tab.
pub const HOTTEST_POSTS_PER_PAGE: u8 = 5;
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
.service(services::posts::create)
.service(services::posts::list)
.service(services::posts::vote)
.service(services::posts::daily_hottest)
.service(services::profile::update_profile)
.service(services::profile::get_profile)
.service(services::posts::get_single_post)
Expand Down
Loading