Add community search request
Browse files at this commite86062ef8b1c2d2482e311547fb823b0cc524f0eParent: 4e8ba23- feat
- add community search request
3 changed files +23 -1
- crates/common/src/request.rs +4 -1
- crates/common/src/request/community.rs +18 -0
- crates/common/src/response.rs +1 -0
crates/common/src/request.rsmodified+4 -1
| @@ -1,7 +1,9 @@ | ||
| 1 | 1 | use bitcode::{Decode, Encode}; |
| 2 | 2 | |
| 3 | 3 | use crate::request::{ |
| 4 | - community::{CreateCommunity, DeleteCommunity, ReadCommunity, UpdateCommunity}, | |
| 4 | + community::{ | |
| 5 | + CreateCommunity, DeleteCommunity, ReadCommunity, SearchCommunity, UpdateCommunity, | |
| 6 | + }, | |
| 5 | 7 | message::{ |
| 6 | 8 | CreateMessage, DeleteMessage, ReadMessage, ReadMessageByCommunityIDWithMarkerAndLimit, |
| 7 | 9 | UpdateMessage, |
| @@ -63,4 +65,5 @@ pub enum Request { | ||
| 63 | 65 | IsUserIn(IsUserIn), |
| 64 | 66 | UsersIn(UsersIn), |
| 65 | 67 | CommunityOf(CommunityOf), |
| 68 | + SearchCommunity(SearchCommunity), | |
| 66 | 69 | } |
crates/common/src/request/community.rsmodified+18 -0
| @@ -80,3 +80,21 @@ impl DeleteCommunity { | ||
| 80 | 80 | &self.community_id |
| 81 | 81 | } |
| 82 | 82 | } |
| 83 | + | |
| 84 | +#[derive(Debug, Clone, Encode, Decode)] | |
| 85 | +pub struct SearchCommunity { | |
| 86 | + community_name: String, | |
| 87 | +} | |
| 88 | + | |
| 89 | +impl SearchCommunity { | |
| 90 | + pub fn new(community_name: &str) -> Result<Self, Error> { | |
| 91 | + let community_name = community_name.to_string(); | |
| 92 | + validate_community_name(&community_name)?; | |
| 93 | + | |
| 94 | + Ok(Self { community_name }) | |
| 95 | + } | |
| 96 | + | |
| 97 | + pub fn get_community_name(&self) -> &str { | |
| 98 | + &self.community_name | |
| 99 | + } | |
| 100 | +} |
crates/common/src/response.rsmodified+1 -0
| @@ -28,5 +28,6 @@ pub enum Response { | ||
| 28 | 28 | IsUserIn(bool), |
| 29 | 29 | UsersIn(Vec<String>), |
| 30 | 30 | CommunityOf(Vec<String>), |
| 31 | + SearchCommunity(Vec<Community>), | |
| 31 | 32 | Error(Error), |
| 32 | 33 | } |