chat history added to context and patching text content

This commit is contained in:
Per Stark
2025-03-16 21:24:24 +01:00
parent f2a434a071
commit 2931724009
13 changed files with 141 additions and 166 deletions

View File

@@ -1,8 +1,9 @@
use axum::{
extract::{Path, State},
response::IntoResponse,
Form,
};
use serde::Serialize;
use serde::{Deserialize, Serialize};
use common::storage::types::{text_content::TextContent, user::User};
@@ -33,12 +34,6 @@ pub async fn show_content_page(
))
}
#[derive(Serialize)]
pub struct TextContentEditModal {
pub user: User,
pub text_content: TextContent,
}
pub async fn show_text_content_edit_form(
State(state): State<HtmlState>,
RequireUser(user): RequireUser,
@@ -46,20 +41,40 @@ pub async fn show_text_content_edit_form(
) -> Result<impl IntoResponse, HtmlError> {
let text_content = User::get_and_validate_text_content(&id, &user.id, &state.db).await?;
#[derive(Serialize)]
pub struct TextContentEditModal {
pub user: User,
pub text_content: TextContent,
}
Ok(TemplateResponse::new_template(
"content/edit_text_content_modal.html",
TextContentEditModal { user, text_content },
))
}
#[derive(Deserialize)]
pub struct PatchTextContentParams {
instructions: String,
category: String,
text: String,
}
pub async fn patch_text_content(
State(state): State<HtmlState>,
RequireUser(user): RequireUser,
Path(id): Path<String>,
Form(form): Form<PatchTextContentParams>,
) -> Result<impl IntoResponse, HtmlError> {
let text_content = User::get_and_validate_text_content(&id, &user.id, &state.db).await?;
User::get_and_validate_text_content(&id, &user.id, &state.db).await?;
// ADD FUNCTION TO PATCH CONTENT
TextContent::patch(
&id,
&form.instructions,
&form.category,
&form.text,
&state.db,
)
.await?;
let text_contents = User::get_text_contents(&user.id, &state.db).await?;