Fixes and more styling

This commit is contained in:
Bad Manners 2025-04-13 11:00:36 -03:00
parent 2c44a69ec3
commit 3619063e68
21 changed files with 203 additions and 94 deletions

View file

@ -133,6 +133,7 @@ pub async fn get_router(
.route_with_tsr("/pools/{page}", get(get_pools_page))
.route_with_tsr("/pool", post(create_pool))
.route_with_tsr("/pool/{pool_id}", get(view_pool))
.route_with_tsr("/pool/{pool_id}/name", put(change_pool_name))
.route_with_tsr("/pool/{pool_id}/public", put(change_pool_visibility))
.route_with_tsr("/pool/{pool_id}/post", post(add_post_to_pool))
.route_with_tsr("/pool/{pool_id}/sort", put(sort_pool))

View file

@ -785,6 +785,57 @@ pub(crate) async fn view_pool(
))
}
#[derive(Debug, Deserialize)]
pub(crate) struct ChangePoolNameForm {
pool_name: String,
}
#[derive(Template)]
#[template(path = "fragments/change_pool_name.html")]
struct ChangePoolNameTemplate {
pool_name: String,
}
pub(crate) async fn change_pool_name(
State(AppState { db, .. }): State<AppState>,
auth_session: AuthSession,
Path(pool_id): Path<i32>,
Form(body): Form<ChangePoolNameForm>,
) -> Result<impl IntoResponse, SameyError> {
let pool = SameyPool::find_by_id(pool_id)
.one(&db)
.await?
.ok_or(SameyError::NotFound)?;
let can_edit = match auth_session.user.as_ref() {
None => false,
Some(user) => user.is_admin || pool.uploader_id == user.id,
};
if !can_edit {
return Err(SameyError::Forbidden);
}
if body.pool_name.trim().is_empty() {
return Err(SameyError::BadRequest("Pool name cannot be empty".into()));
}
SameyPool::update(samey_pool::ActiveModel {
id: Set(pool.id),
name: Set(body.pool_name.clone()),
..Default::default()
})
.exec(&db)
.await?;
Ok(Html(
ChangePoolNameTemplate {
pool_name: body.pool_name,
}
.render()?,
))
}
#[derive(Debug, Deserialize)]
pub(crate) struct ChangePoolVisibilityForm {
is_public: Option<String>,
@ -799,7 +850,7 @@ pub(crate) async fn change_pool_visibility(
let pool = SameyPool::find_by_id(pool_id)
.one(&db)
.await?
.expect("Pool for samey_pool_post must exist");
.ok_or(SameyError::NotFound)?;
let can_edit = match auth_session.user.as_ref() {
None => false,