add: finish forge stuff

This commit is contained in:
trisua 2025-06-10 22:02:06 -04:00
parent 53fb4d5778
commit 68071b96c8
21 changed files with 329 additions and 18 deletions

View file

@ -15,7 +15,10 @@ use tetratto_core::model::{
use crate::{
get_user_from_token,
image::{save_webp_buffer, JsonMultipart},
routes::api::v1::{CreatePost, CreateRepost, UpdatePostContent, UpdatePostContext, VoteInPoll},
routes::api::v1::{
CreatePost, CreateRepost, UpdatePostContent, UpdatePostContext, UpdatePostIsOpen,
VoteInPoll,
},
State,
};
@ -383,3 +386,25 @@ pub async fn vote_request(
Err(e) => Json(e.into()),
}
}
pub async fn update_is_open_request(
jar: CookieJar,
Extension(data): Extension<State>,
Path(id): Path<usize>,
Json(req): Json<UpdatePostIsOpen>,
) -> impl IntoResponse {
let data = &(data.read().await).0;
let user = match get_user_from_token!(jar, data) {
Some(ua) => ua,
None => return Json(Error::NotAllowed.into()),
};
match data.update_post_is_open(id, user, req.open).await {
Ok(_) => Json(ApiReturn {
ok: true,
message: "Post updated".to_string(),
payload: (),
}),
Err(e) => Json(e.into()),
}
}

View file

@ -121,6 +121,10 @@ pub fn routes() -> Router {
"/posts/{id}/poll_vote",
post(communities::posts::vote_request),
)
.route(
"/posts/{id}/open",
post(communities::posts::update_is_open_request),
)
// drafts
.route("/drafts", post(communities::drafts::create_request))
.route("/drafts/{id}", delete(communities::drafts::delete_request))
@ -639,3 +643,8 @@ pub struct VoteInPoll {
pub struct AppendAssociations {
pub tokens: Vec<String>,
}
#[derive(Deserialize)]
pub struct UpdatePostIsOpen {
pub open: bool,
}