add: communities list page
TODO(ui): implement community creation, community viewing, community posting TODO(ui): implement profile following, followers, and posts feed
This commit is contained in:
parent
5cfca49793
commit
d6fbfc3cd6
28 changed files with 497 additions and 313 deletions
|
@ -1,11 +1,11 @@
|
|||
use axum::{Extension, Json, extract::Path, response::IntoResponse};
|
||||
use axum_extra::extract::CookieJar;
|
||||
use tetratto_core::model::{ApiReturn, Error, journal::Journal};
|
||||
use tetratto_core::model::{ApiReturn, Error, communities::Community};
|
||||
|
||||
use crate::{
|
||||
State, get_user_from_token,
|
||||
routes::api::v1::{
|
||||
CreateJournal, UpdateJournalPrompt, UpdateJournalReadAccess, UpdateJournalTitle,
|
||||
CreateCommunity, UpdateCommunityContext, UpdateJournalReadAccess, UpdateJournalTitle,
|
||||
UpdateJournalWriteAccess,
|
||||
},
|
||||
};
|
||||
|
@ -13,7 +13,7 @@ use crate::{
|
|||
pub async fn create_request(
|
||||
jar: CookieJar,
|
||||
Extension(data): Extension<State>,
|
||||
Json(req): Json<CreateJournal>,
|
||||
Json(req): Json<CreateCommunity>,
|
||||
) -> impl IntoResponse {
|
||||
let data = &(data.read().await).0;
|
||||
let user = match get_user_from_token!(jar, data) {
|
||||
|
@ -22,12 +22,12 @@ pub async fn create_request(
|
|||
};
|
||||
|
||||
match data
|
||||
.create_page(Journal::new(req.title, req.prompt, user.id))
|
||||
.create_community(Community::new(req.title, user.id))
|
||||
.await
|
||||
{
|
||||
Ok(_) => Json(ApiReturn {
|
||||
ok: true,
|
||||
message: "Page created".to_string(),
|
||||
message: "Community created".to_string(),
|
||||
payload: (),
|
||||
}),
|
||||
Err(e) => return Json(e.into()),
|
||||
|
@ -45,10 +45,10 @@ pub async fn delete_request(
|
|||
None => return Json(Error::NotAllowed.into()),
|
||||
};
|
||||
|
||||
match data.delete_page(id, user).await {
|
||||
match data.delete_community(id, user).await {
|
||||
Ok(_) => Json(ApiReturn {
|
||||
ok: true,
|
||||
message: "Page deleted".to_string(),
|
||||
message: "Community deleted".to_string(),
|
||||
payload: (),
|
||||
}),
|
||||
Err(e) => return Json(e.into()),
|
||||
|
@ -67,21 +67,21 @@ pub async fn update_title_request(
|
|||
None => return Json(Error::NotAllowed.into()),
|
||||
};
|
||||
|
||||
match data.update_page_title(id, user, req.title).await {
|
||||
match data.update_community_title(id, user, req.title).await {
|
||||
Ok(_) => Json(ApiReturn {
|
||||
ok: true,
|
||||
message: "Page updated".to_string(),
|
||||
message: "Community updated".to_string(),
|
||||
payload: (),
|
||||
}),
|
||||
Err(e) => return Json(e.into()),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn update_prompt_request(
|
||||
pub async fn update_context_request(
|
||||
jar: CookieJar,
|
||||
Extension(data): Extension<State>,
|
||||
Path(id): Path<usize>,
|
||||
Json(req): Json<UpdateJournalPrompt>,
|
||||
Json(req): Json<UpdateCommunityContext>,
|
||||
) -> impl IntoResponse {
|
||||
let data = &(data.read().await).0;
|
||||
let user = match get_user_from_token!(jar, data) {
|
||||
|
@ -89,10 +89,10 @@ pub async fn update_prompt_request(
|
|||
None => return Json(Error::NotAllowed.into()),
|
||||
};
|
||||
|
||||
match data.update_page_prompt(id, user, req.prompt).await {
|
||||
match data.update_community_context(id, user, req.context).await {
|
||||
Ok(_) => Json(ApiReturn {
|
||||
ok: true,
|
||||
message: "Page updated".to_string(),
|
||||
message: "Community updated".to_string(),
|
||||
payload: (),
|
||||
}),
|
||||
Err(e) => return Json(e.into()),
|
||||
|
@ -111,10 +111,13 @@ pub async fn update_read_access_request(
|
|||
None => return Json(Error::NotAllowed.into()),
|
||||
};
|
||||
|
||||
match data.update_page_read_access(id, user, req.access).await {
|
||||
match data
|
||||
.update_community_read_access(id, user, req.access)
|
||||
.await
|
||||
{
|
||||
Ok(_) => Json(ApiReturn {
|
||||
ok: true,
|
||||
message: "Page updated".to_string(),
|
||||
message: "Community updated".to_string(),
|
||||
payload: (),
|
||||
}),
|
||||
Err(e) => return Json(e.into()),
|
||||
|
@ -133,10 +136,13 @@ pub async fn update_write_access_request(
|
|||
None => return Json(Error::NotAllowed.into()),
|
||||
};
|
||||
|
||||
match data.update_page_write_access(id, user, req.access).await {
|
||||
match data
|
||||
.update_community_write_access(id, user, req.access)
|
||||
.await
|
||||
{
|
||||
Ok(_) => Json(ApiReturn {
|
||||
ok: true,
|
||||
message: "Page updated".to_string(),
|
||||
message: "Community updated".to_string(),
|
||||
payload: (),
|
||||
}),
|
||||
Err(e) => return Json(e.into()),
|
2
crates/app/src/routes/api/v1/communities/mod.rs
Normal file
2
crates/app/src/routes/api/v1/communities/mod.rs
Normal file
|
@ -0,0 +1,2 @@
|
|||
pub mod communities;
|
||||
pub mod posts;
|
|
@ -1,6 +1,6 @@
|
|||
use axum::{Extension, Json, extract::Path, response::IntoResponse};
|
||||
use axum_extra::extract::CookieJar;
|
||||
use tetratto_core::model::{ApiReturn, Error, journal::JournalPost};
|
||||
use tetratto_core::model::{ApiReturn, Error, communities::Post};
|
||||
|
||||
use crate::{
|
||||
State, get_user_from_token,
|
||||
|
@ -19,7 +19,7 @@ pub async fn create_request(
|
|||
};
|
||||
|
||||
match data
|
||||
.create_post(JournalPost::new(
|
||||
.create_post(Post::new(
|
||||
req.content,
|
||||
req.journal,
|
||||
req.replying_to,
|
||||
|
@ -29,7 +29,7 @@ pub async fn create_request(
|
|||
{
|
||||
Ok(_) => Json(ApiReturn {
|
||||
ok: true,
|
||||
message: "Entry created".to_string(),
|
||||
message: "Post created".to_string(),
|
||||
payload: (),
|
||||
}),
|
||||
Err(e) => return Json(e.into()),
|
||||
|
@ -50,7 +50,7 @@ pub async fn delete_request(
|
|||
match data.delete_post(id, user).await {
|
||||
Ok(_) => Json(ApiReturn {
|
||||
ok: true,
|
||||
message: "Entry deleted".to_string(),
|
||||
message: "Post deleted".to_string(),
|
||||
payload: (),
|
||||
}),
|
||||
Err(e) => return Json(e.into()),
|
||||
|
@ -72,7 +72,7 @@ pub async fn update_content_request(
|
|||
match data.update_post_content(id, user, req.content).await {
|
||||
Ok(_) => Json(ApiReturn {
|
||||
ok: true,
|
||||
message: "Entry updated".to_string(),
|
||||
message: "Post updated".to_string(),
|
||||
payload: (),
|
||||
}),
|
||||
Err(e) => return Json(e.into()),
|
||||
|
@ -94,7 +94,7 @@ pub async fn update_context_request(
|
|||
match data.update_post_context(id, user, req.context).await {
|
||||
Ok(_) => Json(ApiReturn {
|
||||
ok: true,
|
||||
message: "Entry updated".to_string(),
|
||||
message: "Post updated".to_string(),
|
||||
payload: (),
|
||||
}),
|
||||
Err(e) => return Json(e.into()),
|
|
@ -1,2 +0,0 @@
|
|||
pub mod journals;
|
||||
pub mod posts;
|
|
@ -1,5 +1,5 @@
|
|||
pub mod auth;
|
||||
pub mod journal;
|
||||
pub mod communities;
|
||||
pub mod reactions;
|
||||
|
||||
use axum::{
|
||||
|
@ -8,7 +8,7 @@ use axum::{
|
|||
};
|
||||
use serde::Deserialize;
|
||||
use tetratto_core::model::{
|
||||
journal::{JournalPostContext, JournalReadAccess, JournalWriteAccess},
|
||||
communities::{CommunityContext, CommunityReadAccess, CommunityWriteAccess, PostContext},
|
||||
reactions::AssetType,
|
||||
};
|
||||
|
||||
|
@ -19,34 +19,40 @@ pub fn routes() -> Router {
|
|||
.route("/reactions/{id}", get(reactions::get_request))
|
||||
.route("/reactions/{id}", delete(reactions::delete_request))
|
||||
// journal journals
|
||||
.route("/journals", post(journal::journals::create_request))
|
||||
.route("/journals/{id}", delete(journal::journals::delete_request))
|
||||
.route(
|
||||
"/journals/{id}/title",
|
||||
post(journal::journals::update_title_request),
|
||||
"/communities",
|
||||
post(communities::communities::create_request),
|
||||
)
|
||||
.route(
|
||||
"/journals/{id}/prompt",
|
||||
post(journal::journals::update_prompt_request),
|
||||
"/communities/{id}",
|
||||
delete(communities::communities::delete_request),
|
||||
)
|
||||
.route(
|
||||
"/communities/{id}/title",
|
||||
post(communities::communities::update_title_request),
|
||||
)
|
||||
.route(
|
||||
"/communities/{id}/context",
|
||||
post(communities::communities::update_context_request),
|
||||
)
|
||||
.route(
|
||||
"/journals/{id}/access/read",
|
||||
post(journal::journals::update_read_access_request),
|
||||
post(communities::communities::update_read_access_request),
|
||||
)
|
||||
.route(
|
||||
"/journals/{id}/access/write",
|
||||
post(journal::journals::update_write_access_request),
|
||||
post(communities::communities::update_write_access_request),
|
||||
)
|
||||
// journal posts
|
||||
.route("/posts", post(journal::posts::create_request))
|
||||
.route("/posts/{id}", delete(journal::posts::delete_request))
|
||||
// posts
|
||||
.route("/posts", post(communities::posts::create_request))
|
||||
.route("/posts/{id}", delete(communities::posts::delete_request))
|
||||
.route(
|
||||
"/posts/{id}/content",
|
||||
post(journal::posts::update_content_request),
|
||||
post(communities::posts::update_content_request),
|
||||
)
|
||||
.route(
|
||||
"/posts/{id}/context",
|
||||
post(journal::posts::update_context_request),
|
||||
post(communities::posts::update_context_request),
|
||||
)
|
||||
// auth
|
||||
// global
|
||||
|
@ -99,9 +105,8 @@ pub struct AuthProps {
|
|||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct CreateJournal {
|
||||
pub struct CreateCommunity {
|
||||
pub title: String,
|
||||
pub prompt: String,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
|
@ -110,18 +115,18 @@ pub struct UpdateJournalTitle {
|
|||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct UpdateJournalPrompt {
|
||||
pub prompt: String,
|
||||
pub struct UpdateCommunityContext {
|
||||
pub context: CommunityContext,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct UpdateJournalReadAccess {
|
||||
pub access: JournalReadAccess,
|
||||
pub access: CommunityReadAccess,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct UpdateJournalWriteAccess {
|
||||
pub access: JournalWriteAccess,
|
||||
pub access: CommunityWriteAccess,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
|
@ -139,7 +144,7 @@ pub struct UpdateJournalEntryContent {
|
|||
|
||||
#[derive(Deserialize)]
|
||||
pub struct UpdateJournalEntryContext {
|
||||
pub context: JournalPostContext,
|
||||
pub context: PostContext,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue