add: questions api endpoints

This commit is contained in:
trisua 2025-06-13 23:25:10 -04:00
parent b29760d7ec
commit d128b2c438
5 changed files with 321 additions and 4 deletions

View file

@ -76,6 +76,21 @@ impl DataManager {
Ok(out)
}
/// Filter to update questions to clean their owner for public APIs.
pub fn questions_owner_filter(
&self,
questions: &Vec<(Question, User)>,
) -> Vec<(Question, User)> {
let mut out: Vec<(Question, User)> = Vec::new();
for mut question in questions.clone() {
question.1.clean();
out.push(question);
}
out
}
/// Get all questions by `owner`.
pub async fn get_questions_by_owner(&self, owner: usize) -> Result<Vec<Question>> {
let conn = match self.0.connect().await {

View file

@ -58,6 +58,8 @@ pub enum AppScope {
UserReadNotifications,
/// Read the user's requests.
UserReadRequests,
/// Read questions as the user.
UserReadQuestions,
/// Create posts as the user.
UserCreatePosts,
/// Create messages as the user.
@ -155,6 +157,7 @@ impl AppScope {
"user-read-sockets" => Self::UserReadSockets,
"user-read-notifications" => Self::UserReadNotifications,
"user-read-requests" => Self::UserReadRequests,
"user-read-questions" => Self::UserReadQuestions,
"user-create-posts" => Self::UserCreatePosts,
"user-create-messages" => Self::UserCreateMessages,
"user-create-questions" => Self::UserCreateQuestions,