forge
Explore
Log in

Don't you dare go Hollow

hezarfen_backend

Clone
★ 0

0 watching0 forksRust8.3 MiB6d68754Ahmet Kaan Gümüş2 months ago566 commits

rag_output.rs43 lines, 1.6 KiBHistoryRawDownload
1//! RAG-output workflows on the course-notes surface: list a note's outputs,
2//! read and delete one, and cascade-drop every output of a note or of one
3//! of its source files. The rows are derived data (the note is the source
4//! of truth), so every path here is disposable by design. The queries live
5//! in [`crate::db::rag_output`].
6
7use crate::database::Database;
8use crate::db::rag_output;
9use crate::domain::course_note::CourseNoteId;
10use crate::domain::course_note_file::CourseNoteFileId;
11use crate::domain::rag_output::{RagOutput, RagOutputId};
12use crate::error::AppError;
13
14pub async fn read(db: &Database, id: &RagOutputId) -> Result<Option<RagOutput>, AppError> {
15 rag_output::read(db, id).await
16}
17
18/// A note's outputs, newest first.
19pub async fn list_for(
20 db: &Database,
21 note: &CourseNoteId,
22 limit: Option<i64>,
23 offset: i64,
24) -> Result<(Vec<RagOutput>, i64), AppError> {
25 rag_output::list_for(db, note, limit, offset).await
26}
27
28pub async fn delete(db: &Database, id: &RagOutputId) -> Result<RagOutput, AppError> {
29 rag_output::delete(db, id).await
30}
31
32/// Cascade: every output of `note`. Deleting none is a success — a note
33/// no service ever indexed has nothing to drop.
34pub async fn delete_for_note(db: &Database, note: &CourseNoteId) -> Result<(), AppError> {
35 rag_output::delete_for_note(db, note).await
36}
37
38/// Cascade: the citation links pointing at `file`. Runs on a file delete
39/// even with no AI service connected — the file row refuses to go while a
40/// link still cites it.
41pub async fn delete_with_source(db: &Database, file: &CourseNoteFileId) -> Result<(), AppError> {
42 rag_output::delete_with_source(db, file).await
43}