This commit is contained in:
Gvidas Juknevičius 2024-03-30 19:05:02 +02:00
parent 96a4089bfc
commit 5f9b260d76
Signed by: MCorange
GPG Key ID: 12B1346D720B7FBB
3 changed files with 19 additions and 14 deletions

View File

@ -17,7 +17,7 @@ pub struct Post {
#[allow(dead_code)]
impl Post {
pub async fn create_new(db: &mut Database, title: String, descr: String, img_url: String, origin_url: String, orignal_request: Value) -> anyhow::Result<Uuid> {
pub async fn create_new(db: &mut Database, title: String, descr: String, img_url: String, origin_url: String, orignal_request: String) -> anyhow::Result<Uuid> {
let id = Uuid::new_v4();
let posted_on = chrono::Utc::now().timestamp_millis();

View File

@ -6,21 +6,26 @@ use crate::database::{models::{self, tokens::Token}, Database};
use super::types::ReleaseEvent;
pub async fn release_handler(db: Data<Mutex<Database>>, token: Token, body: ReleaseEvent, raw_body: String,) -> Result<HttpResponseBuilder> {
pub async fn release_handler(db: Data<Mutex<Database>>, token: Token, body: ReleaseEvent, raw_body: String) -> Result<HttpResponseBuilder> {
let title = format!("{} has been released on {}!", body.release.tag_name, body.repository.full_name);
dbg!(body);
// models::posts::Post::create_new(
// db.lock().unwrap().borrow_mut(),
// title,
// descr,
// img_url,
// origin_url,
// orignal_request
// );
let title = format!("(New release {}:{}) {}", body.repository.full_name, body.release.tag_name, body.release.name.unwrap_or("No title provided".into()));
let origin_url = body.repository.html_url.clone();
let descr = body.release.body.unwrap_or("No body provided".into());
let img_url = body.repository.owner.avatar_url.clone();
let res = models::posts::Post::create_new(
db.lock().unwrap().borrow_mut(),
title,
descr,
img_url,
origin_url,
raw_body
).await;
if let Err(e) = res {
log::error!("{e}");
return Ok(HttpResponse::InternalServerError());
}
Ok(HttpResponse::Ok())

View File

@ -50,7 +50,7 @@ pub async fn handler(req: HttpRequest, token: web::Path<String>, body: Bytes, db
match event {
types::Event::Release(body) => events::release_handler(db, token, body, json).await,
_ => {
dbg!(json);
// dbg!(json);
Ok(HttpResponse::Ok())
}
}