add: forums ui
This commit is contained in:
parent
2be87c397d
commit
9ec52abfe4
24 changed files with 770 additions and 64 deletions
|
@ -538,7 +538,7 @@ pub async fn add_topic_request(
|
|||
None => return Json(Error::NotAllowed.into()),
|
||||
};
|
||||
|
||||
let mut community = match data.get_community_by_id(id).await {
|
||||
let mut community = match data.get_community_by_id_no_void(id).await {
|
||||
Ok(x) => x,
|
||||
Err(e) => return Json(e.into()),
|
||||
};
|
||||
|
@ -547,8 +547,22 @@ pub async fn add_topic_request(
|
|||
return Json(Error::DoesNotSupportField("community".to_string()).into());
|
||||
}
|
||||
|
||||
let (id, topic) = ForumTopic::new(req.title, req.description, req.color);
|
||||
community.topics.insert(id, topic);
|
||||
// check lengths
|
||||
if req.title.len() > 32 {
|
||||
return Json(Error::DataTooLong("title".to_string()).into());
|
||||
}
|
||||
|
||||
if req.title.len() < 2 {
|
||||
return Json(Error::DataTooShort("title".to_string()).into());
|
||||
}
|
||||
|
||||
if req.description.len() > 256 {
|
||||
return Json(Error::DataTooLong("description".to_string()).into());
|
||||
}
|
||||
|
||||
// ...
|
||||
let (topic_id, topic) = ForumTopic::new(req.title, req.description, req.color, req.position);
|
||||
community.topics.insert(topic_id, topic);
|
||||
|
||||
match data
|
||||
.update_community_topics(id, &user, community.topics)
|
||||
|
@ -575,7 +589,7 @@ pub async fn update_topic_request(
|
|||
None => return Json(Error::NotAllowed.into()),
|
||||
};
|
||||
|
||||
let mut community = match data.get_community_by_id(id).await {
|
||||
let mut community = match data.get_community_by_id_no_void(id).await {
|
||||
Ok(x) => x,
|
||||
Err(e) => return Json(e.into()),
|
||||
};
|
||||
|
@ -584,10 +598,25 @@ pub async fn update_topic_request(
|
|||
return Json(Error::DoesNotSupportField("community".to_string()).into());
|
||||
}
|
||||
|
||||
// check lengths
|
||||
if req.title.len() > 32 {
|
||||
return Json(Error::DataTooLong("title".to_string()).into());
|
||||
}
|
||||
|
||||
if req.title.len() < 2 {
|
||||
return Json(Error::DataTooShort("title".to_string()).into());
|
||||
}
|
||||
|
||||
if req.description.len() > 256 {
|
||||
return Json(Error::DataTooLong("description".to_string()).into());
|
||||
}
|
||||
|
||||
// ...
|
||||
let topic = ForumTopic {
|
||||
title: req.title,
|
||||
description: req.description,
|
||||
color: req.color,
|
||||
position: req.position,
|
||||
};
|
||||
|
||||
community.topics.insert(topic_id, topic);
|
||||
|
@ -616,7 +645,7 @@ pub async fn delete_topic_request(
|
|||
None => return Json(Error::NotAllowed.into()),
|
||||
};
|
||||
|
||||
let mut community = match data.get_community_by_id(id).await {
|
||||
let mut community = match data.get_community_by_id_no_void(id).await {
|
||||
Ok(x) => x,
|
||||
Err(e) => return Json(e.into()),
|
||||
};
|
||||
|
@ -631,11 +660,14 @@ pub async fn delete_topic_request(
|
|||
.update_community_topics(id, &user, community.topics)
|
||||
.await
|
||||
{
|
||||
Ok(_) => Json(ApiReturn {
|
||||
ok: true,
|
||||
message: "Community updated".to_string(),
|
||||
payload: (),
|
||||
}),
|
||||
Ok(_) => match data.delete_topic_posts(id, topic_id).await {
|
||||
Ok(_) => Json(ApiReturn {
|
||||
ok: true,
|
||||
message: "Community updated".to_string(),
|
||||
payload: (),
|
||||
}),
|
||||
Err(e) => Json(e.into()),
|
||||
},
|
||||
Err(e) => Json(e.into()),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue