You've already forked AstralRinth
forked from didirus/AstralRinth
Fix report create route
This commit is contained in:
@@ -20,6 +20,7 @@ pub struct Report {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone)]
|
#[derive(Serialize, Deserialize, Clone)]
|
||||||
|
#[serde(rename_all = "kebab-case")]
|
||||||
pub enum ItemType {
|
pub enum ItemType {
|
||||||
Mod,
|
Mod,
|
||||||
Version,
|
Version,
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ use crate::models::ids::{ModId, UserId, VersionId};
|
|||||||
use crate::models::reports::{ItemType, Report};
|
use crate::models::reports::{ItemType, Report};
|
||||||
use crate::routes::ApiError;
|
use crate::routes::ApiError;
|
||||||
use actix_web::{delete, get, post, web, HttpRequest, HttpResponse};
|
use actix_web::{delete, get, post, web, HttpRequest, HttpResponse};
|
||||||
|
use futures::StreamExt;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use sqlx::PgPool;
|
use sqlx::PgPool;
|
||||||
|
|
||||||
@@ -18,7 +19,7 @@ pub struct CreateReport {
|
|||||||
pub async fn report_create(
|
pub async fn report_create(
|
||||||
req: HttpRequest,
|
req: HttpRequest,
|
||||||
pool: web::Data<PgPool>,
|
pool: web::Data<PgPool>,
|
||||||
new_report: web::Json<CreateReport>,
|
mut body: web::Payload,
|
||||||
) -> Result<HttpResponse, ApiError> {
|
) -> Result<HttpResponse, ApiError> {
|
||||||
let mut transaction = pool
|
let mut transaction = pool
|
||||||
.begin()
|
.begin()
|
||||||
@@ -27,6 +28,14 @@ pub async fn report_create(
|
|||||||
|
|
||||||
let current_user = get_user_from_headers(req.headers(), &mut *transaction).await?;
|
let current_user = get_user_from_headers(req.headers(), &mut *transaction).await?;
|
||||||
|
|
||||||
|
let mut bytes = web::BytesMut::new();
|
||||||
|
while let Some(item) = body.next().await {
|
||||||
|
bytes.extend_from_slice(&item.map_err(|_| {
|
||||||
|
ApiError::InvalidInputError("Error while parsing request payload!".to_string())
|
||||||
|
})?);
|
||||||
|
}
|
||||||
|
let new_report: CreateReport = serde_json::from_slice(bytes.as_ref())?;
|
||||||
|
|
||||||
let id = crate::database::models::generate_report_id(&mut transaction).await?;
|
let id = crate::database::models::generate_report_id(&mut transaction).await?;
|
||||||
let report_type = crate::database::models::categories::ReportType::get_id(
|
let report_type = crate::database::models::categories::ReportType::get_id(
|
||||||
&*new_report.report_type,
|
&*new_report.report_type,
|
||||||
|
|||||||
Reference in New Issue
Block a user