January 2019
Intermediate to advanced
520 pages
14h 32m
English
The next method is create_channel, which creates a new channel for a user. Take a look at the implementation:
pub fn create_channel(&self, user_id: Id, title: &str, is_public: bool) -> Result<Channel, Error>{ self.conn.transaction::<_, _, _>(|| { let channel: Channel = insert_into(channels::table) .values(( channels::user_id.eq(user_id), channels::title.eq(title), channels::is_public.eq(is_public), )) .returning(( channels::id, channels::user_id, channels::title, channels::is_public, channels::created_at, channels::updated_at, )) .get_result(&self.conn) .map_err(Error::from)?; self.add_member(channel.id, user_id)?; Ok(channel) })}
The function expects user_id, the title of a channel, and the is_public flag, which means the ...
Read now
Unlock full access