-
Notifications
You must be signed in to change notification settings - Fork 0
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
[Feature] Get Papers #8
base: main
Are you sure you want to change the base?
Conversation
Tests don't run because of a tokio runtime bug
This way will allow extensibility for other API needs
Add prerrequisites section
This way will allow extensibility for other API needs
Add how to run tests section
Rename section
* Add test coverage workflow * Downgrade codecov version * Add rusty-hook * Remove codecov for the moment because of a bug * Add CircleCI for fmt, clippy and test running * Fix rust version in workflow * Fix rust version in workflow for allthe jobs * Remove .tarpaulin for the moment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
El código funciona y está muy bien el PR en general. Marqué algunos detalles para refactorizar nada más. En el futuro tratá de que los commits sean autocontenidos, es decir que por ejemplo, los cambios de dependencias hechos en Cargo.toml
y Cargo.lock
pertenezcan a un commit tipo "Agrego dependencias". Te recomiendo leer How to make your code reviewer fall in love with you y How to Write a Git Commit Message
@@ -13,6 +14,12 @@ struct Requester { | |||
voice_channel: u64, | |||
} | |||
|
|||
#[derive(Serialize, Deserialize)] | |||
struct Papers { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
El nombre del struct hace referncia a papers en plural pero parece que se trata de un struct para un paper individual.
.map(|paper_url_github| { | ||
let paper_name = paper_url_github | ||
.split(&['/', '.'][..]) | ||
.collect::<Vec<&str>>()[9] | ||
.to_string(); | ||
|
||
let mut paper_url_to_modify = | ||
paper_url_github.split_inclusive('/').collect::<Vec<&str>>(); | ||
paper_url_to_modify.remove(4); | ||
paper_url_to_modify.remove(3); | ||
paper_url_to_modify.remove(1); | ||
paper_url_to_modify.remove(0); | ||
paper_url_to_modify.insert(0, "https://"); | ||
let paper_url_string = paper_url_to_modify.concat(); | ||
|
||
Papers { | ||
name: paper_name, | ||
url: paper_url_string, | ||
} | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Creo que toda esta función puede ser un try_from
del struct Paper
para que intente armarlo desde el url. ¿Qué les parece @IAvecilla @josuebouchard ?
@@ -13,6 +14,12 @@ struct Requester { | |||
voice_channel: u64, | |||
} | |||
|
|||
#[derive(Serialize, Deserialize)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No estoy del todo seguro pero creo que no hace falta que derive Deserialize
porque en ningún momento lo deserializamos.
/// Create papers.json | ||
async fn get_papers() -> Result<impl Reply, Rejection> { | ||
let body = reqwest::get("https://github.com/algoritmos-iii/algoritmos-iii.github.io/tree/master/assets/bibliografia") | ||
.await.map_err(|e| reject::custom(ServerError::Request(e.to_string())))? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pongamos un new line después del await
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aunque va a ser mejor que implementemos OrRejected
para el Result
de reqwest::get
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pero lo último podemos dejarlo para un PR aparte.
let body = reqwest::get("https://github.com/algoritmos-iii/algoritmos-iii.github.io/tree/master/assets/bibliografia") | ||
.await.map_err(|e| reject::custom(ServerError::Request(e.to_string())))? | ||
.text() | ||
.await.map_err(|e| reject::custom(ServerError::Request(e.to_string())))?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto.
Motivación
Hacemos este endpoint para que el frontend del bot de discord pueda obtener los links de los papers del cuatrimestre.
Endpoints
En el futuro se agregará la documentación pertinente en el README
GET /api/discord/v1/papers
- Obtiene los links y los nombres de los papersPrerrequisitos
Debes tener Rust instalado. Para instalarlo ejecutá los siguientes comandos.
Build and Run
Ejecutar el siguiente comando compilará y ejecutará el binario que estará escuchando requests en el puerto
8080
enlocalhost
por default.La directiva de arriba admite las siguientes opciones:
DOMAIN
: el dominio en el que se alojará el backend. Eshttp://127.0.0.1
por defecto (en un futurohttps
).PORT
: el puerto en el que el backend escuchará requests. Es8080
por defecto.Para probar
El
Makefile
dispone de la siguiente directiva para probar el endpoint: