diff options
author | Dessalines <happydooby@gmail.com> | 2019-04-25 14:52:18 -0700 |
---|---|---|
committer | Dessalines <happydooby@gmail.com> | 2019-04-25 14:52:18 -0700 |
commit | 4b76cccce44da59ca1da64d28e35f7d128ca606e (patch) | |
tree | 8e053b3843acddfa3c36b593e3239d0fd6e38e73 /server | |
parent | b776912697f2e152d9526a30bcff58bcda56cc25 (diff) |
Adding /f/ and /u/ in links now.
- Fixes #102
Diffstat (limited to 'server')
-rw-r--r-- | server/src/actions/community.rs | 8 | ||||
-rw-r--r-- | server/src/actions/user.rs | 4 | ||||
-rw-r--r-- | server/src/websocket_server/server.rs | 35 |
3 files changed, 36 insertions, 11 deletions
diff --git a/server/src/actions/community.rs b/server/src/actions/community.rs index 7a69c807..42c95c7d 100644 --- a/server/src/actions/community.rs +++ b/server/src/actions/community.rs @@ -59,6 +59,14 @@ impl Crud<CommunityForm> for Community { } } +impl Community { + pub fn read_from_name(conn: &PgConnection, community_name: String) -> Result<Self, Error> { + use schema::community::dsl::*; + community.filter(name.eq(community_name)) + .first::<Self>(conn) + } +} + #[derive(Identifiable, Queryable, Associations, PartialEq, Debug)] #[belongs_to(Community)] #[table_name = "community_moderator"] diff --git a/server/src/actions/user.rs b/server/src/actions/user.rs index ea6f36e6..58cfd89d 100644 --- a/server/src/actions/user.rs +++ b/server/src/actions/user.rs @@ -67,6 +67,10 @@ impl User_ { Self::create(&conn, &edited_user) } + pub fn read_from_name(conn: &PgConnection, from_user_name: String) -> Result<Self, Error> { + user_.filter(name.eq(from_user_name)) + .first::<Self>(conn) + } } #[derive(Debug, Serialize, Deserialize)] diff --git a/server/src/websocket_server/server.rs b/server/src/websocket_server/server.rs index dee42726..dbd1be8d 100644 --- a/server/src/websocket_server/server.rs +++ b/server/src/websocket_server/server.rs @@ -188,7 +188,8 @@ pub struct GetPostsResponse { #[derive(Serialize, Deserialize)] pub struct GetCommunity { - id: i32, + id: Option<i32>, + name: Option<String>, auth: Option<String> } @@ -311,7 +312,8 @@ pub struct GetFollowedCommunitiesResponse { #[derive(Serialize, Deserialize)] pub struct GetUserDetails { - user_id: i32, + user_id: Option<i32>, + username: Option<String>, sort: String, page: Option<i64>, limit: Option<i64>, @@ -1176,14 +1178,19 @@ impl Perform for GetCommunity { None => None }; - let community_view = match CommunityView::read(&conn, self.id, user_id) { + let community_id = match self.id { + Some(id) => id, + None => Community::read_from_name(&conn, self.name.to_owned().unwrap_or("main".to_string()))?.id + }; + + let community_view = match CommunityView::read(&conn, community_id, user_id) { Ok(community) => community, Err(_e) => { return Err(self.error("Couldn't find Community"))? } }; - let moderators = match CommunityModeratorView::for_community(&conn, self.id) { + let moderators = match CommunityModeratorView::for_community(&conn, community_id) { Ok(moderators) => moderators, Err(_e) => { return Err(self.error("Couldn't find Community"))? @@ -2042,7 +2049,13 @@ impl Perform for GetUserDetails { //TODO add save let sort = SortType::from_str(&self.sort)?; - let user_view = UserView::read(&conn, self.user_id)?; + let user_details_id = match self.user_id { + Some(id) => id, + None => User_::read_from_name(&conn, self.username.to_owned().unwrap_or("admin".to_string()))?.id + }; + + let user_view = UserView::read(&conn, user_details_id)?; + // If its saved only, you don't care what creator it was let posts = if self.saved_only { PostView::list(&conn, @@ -2051,7 +2064,7 @@ impl Perform for GetUserDetails { self.community_id, None, None, - Some(self.user_id), + Some(user_details_id), self.saved_only, false, self.page, @@ -2061,7 +2074,7 @@ impl Perform for GetUserDetails { PostListingType::All, &sort, self.community_id, - Some(self.user_id), + Some(user_details_id), None, None, self.saved_only, @@ -2075,7 +2088,7 @@ impl Perform for GetUserDetails { None, None, None, - Some(self.user_id), + Some(user_details_id), self.saved_only, self.page, self.limit)? @@ -2083,7 +2096,7 @@ impl Perform for GetUserDetails { CommentView::list(&conn, &sort, None, - Some(self.user_id), + Some(user_details_id), None, None, self.saved_only, @@ -2091,8 +2104,8 @@ impl Perform for GetUserDetails { self.limit)? }; - let follows = CommunityFollowerView::for_user(&conn, self.user_id)?; - let moderates = CommunityModeratorView::for_user(&conn, self.user_id)?; + let follows = CommunityFollowerView::for_user(&conn, user_details_id)?; + let moderates = CommunityModeratorView::for_user(&conn, user_details_id)?; // Return the jwt Ok( |