remove warnings

This commit is contained in:
appflowy 2021-09-01 16:37:46 +08:00
parent 77a5e84979
commit 06a1c96a28
16 changed files with 53 additions and 75 deletions

View File

@ -1,7 +1,4 @@
use crate::{
config::env::{domain, jwt_secret},
entities::user::UserTable,
};
use crate::config::env::{domain, jwt_secret};
use chrono::{Duration, Local};
use derive_more::{From, Into};
use flowy_net::errors::ServerError;

View File

@ -22,7 +22,6 @@ use flowy_user::{
SignUpResponse,
UpdateUserParams,
UserDetail,
UserToken,
},
};
use sqlx::{PgPool, Postgres};
@ -57,8 +56,8 @@ pub async fn sign_in(pool: &PgPool, params: SignInParams) -> Result<SignInRespon
Ok(response_data)
}
pub async fn sign_out(params: UserToken) -> Result<FlowyResponse, ServerError> {
let _ = AUTHORIZED_USERS.store_auth(LoggedUser::from_token(params.token.clone())?, false)?;
pub async fn sign_out(logged_user: LoggedUser) -> Result<FlowyResponse, ServerError> {
let _ = AUTHORIZED_USERS.store_auth(logged_user, false)?;
Ok(FlowyResponse::success())
}

View File

@ -4,7 +4,6 @@ use chrono::{DateTime, Utc};
use dashmap::DashMap;
use flowy_net::errors::ServerError;
use actix_http::header::ToStrError;
use actix_web::http::HeaderValue;
use lazy_static::lazy_static;
@ -59,10 +58,7 @@ impl LoggedUser {
use actix_web::{dev::Payload, FromRequest, HttpRequest};
use flowy_net::config::HEADER_TOKEN;
use futures::{
executor::block_on,
future::{ready, Ready},
};
use futures::future::{ready, Ready};
use std::convert::TryInto;
impl FromRequest for LoggedUser {

View File

@ -15,7 +15,7 @@ use crate::user_service::{
};
use actix_identity::Identity;
use flowy_net::{errors::ServerError, response::FlowyResponse};
use flowy_user::protobuf::{SignInParams, SignUpParams, UpdateUserParams, UserToken};
use flowy_user::protobuf::{SignInParams, SignUpParams, UpdateUserParams};
use sqlx::PgPool;
pub async fn sign_in_handler(
@ -30,11 +30,13 @@ pub async fn sign_in_handler(
Ok(response.into())
}
pub async fn sign_out_handler(payload: Payload, id: Identity) -> Result<HttpResponse, ServerError> {
let params: UserToken = parse_from_payload(payload).await?;
pub async fn sign_out_handler(
logged_user: LoggedUser,
id: Identity,
) -> Result<HttpResponse, ServerError> {
id.forget();
let response = sign_out(params).await?;
let response = sign_out(logged_user).await?;
Ok(response.into())
}

View File

@ -3,4 +3,4 @@ pub mod router;
mod view;
pub use builder::*;
pub use view::*;
pub(crate) use view::*;

View File

@ -1,15 +1,5 @@
use crate::helper::{spawn_app, TestApp};
use flowy_user::{
entities::{
SignInParams,
SignInResponse,
SignUpParams,
SignUpResponse,
UpdateUserParams,
UserToken,
},
errors::UserError,
};
use flowy_user::entities::{SignInParams, SignUpParams, SignUpResponse, UpdateUserParams};
#[actix_rt::test]
async fn user_register() {
@ -63,10 +53,7 @@ async fn user_sign_out() {
};
let sign_in_resp = app.sign_in(params).await.unwrap();
let token = sign_in_resp.token.clone();
let user_token = UserToken {
token: token.clone(),
};
app.sign_out(user_token).await;
app.sign_out(&token).await;
// user_detail will be empty because use was sign out.
app.get_user_detail(&token).await;

View File

@ -26,9 +26,9 @@ impl TestApp {
user_sign_in(params, &url).await
}
pub async fn sign_out(&self, params: UserToken) {
pub async fn sign_out(&self, token: &str) {
let url = format!("{}/api/auth", self.address);
let _ = user_sign_out(params, &url).await.unwrap();
let _ = user_sign_out(token, &url).await.unwrap();
}
pub async fn get_user_detail(&self, token: &str) -> UserDetail {

View File

@ -8,5 +8,5 @@ lazy_static! {
pub static ref SIGN_UP_URL: String = format!("{}/api/register", HOST);
pub static ref SIGN_IN_URL: String = format!("{}/api/auth", HOST);
pub static ref SIGN_OUT_URL: String = format!("{}/api/auth", HOST);
pub static ref USER_DETAIL_URL: String = format!("{}/api/user", HOST);
pub static ref USER_PROFILE_URL: String = format!("{}/api/user", HOST);
}

View File

@ -2,7 +2,7 @@ use bytes::Bytes;
use derive_more::Display;
use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
use flowy_dispatch::prelude::{EventResponse, ResponseBuilder};
use flowy_net::errors::ServerError;
use std::{
convert::TryInto,
fmt::{Debug, Formatter},

View File

@ -1,10 +1,6 @@
use crate::{
entities::*,
errors::UserError,
services::user::{update_user, UserSession},
};
use crate::{entities::*, errors::UserError, services::user::UserSession};
use flowy_dispatch::prelude::*;
use flowy_infra::future::ResultFuture;
use std::{convert::TryInto, sync::Arc};
#[tracing::instrument(name = "get_user_status", skip(session))]

View File

@ -1,9 +1,9 @@
use crate::{
entities::{SignInParams, SignInResponse, SignUpParams, SignUpResponse, UserDetail},
errors::{ErrorBuilder, ErrorCode, UserError},
errors::UserError,
};
use crate::entities::{UpdateUserParams, UserToken};
use crate::entities::UpdateUserParams;
use flowy_infra::future::ResultFuture;
use flowy_net::{config::*, request::HttpRequestBuilder};
use std::sync::Arc;
@ -14,7 +14,7 @@ pub trait UserServerAPI {
fn sign_up(&self, params: SignUpParams) -> ResultFuture<SignUpResponse, UserError>;
fn sign_in(&self, params: SignInParams) -> ResultFuture<SignInResponse, UserError>;
fn sign_out(&self, token: &str) -> ResultFuture<(), UserError>;
fn update_user(&self, params: UpdateUserParams) -> ResultFuture<(), UserError>;
fn update_user(&self, token: &str, params: UpdateUserParams) -> ResultFuture<(), UserError>;
fn get_user_detail(&self, token: &str) -> ResultFuture<UserDetail, UserError>;
}
@ -33,22 +33,23 @@ impl UserServerAPI for UserServer {
}
fn sign_out(&self, token: &str) -> ResultFuture<(), UserError> {
let params = UserToken {
token: token.to_string(),
};
let token = token.to_owned();
ResultFuture::new(async move {
let _ = user_sign_out(params, SIGN_OUT_URL.as_ref()).await;
let _ = user_sign_out(&token, SIGN_OUT_URL.as_ref()).await;
Ok(())
})
}
fn update_user(&self, params: UpdateUserParams) -> ResultFuture<(), UserError> {
unimplemented!();
fn update_user(&self, token: &str, params: UpdateUserParams) -> ResultFuture<(), UserError> {
let token = token.to_owned();
ResultFuture::new(async move {
update_user_detail(&token, params, USER_PROFILE_URL.as_ref()).await
})
}
fn get_user_detail(&self, token: &str) -> ResultFuture<UserDetail, UserError> {
let token = token.to_owned();
ResultFuture::new(async move { get_user_detail(&token, USER_DETAIL_URL.as_ref()).await })
ResultFuture::new(async move { get_user_detail(&token, USER_PROFILE_URL.as_ref()).await })
}
}
@ -72,9 +73,9 @@ pub async fn user_sign_in(params: SignInParams, url: &str) -> Result<SignInRespo
Ok(response)
}
pub async fn user_sign_out(params: UserToken, url: &str) -> Result<(), UserError> {
pub async fn user_sign_out(token: &str, url: &str) -> Result<(), UserError> {
let _ = HttpRequestBuilder::delete(&url.to_owned())
.protobuf(params)?
.header(HEADER_TOKEN, token)
.send()
.await?;
Ok(())

View File

@ -4,10 +4,9 @@ use crate::{
services::user::UserServerAPI,
};
use crate::entities::{UpdateUserParams, UserToken};
use crate::entities::UpdateUserParams;
use flowy_infra::future::ResultFuture;
use std::sync::Arc;
pub struct UserServerMock {}
@ -27,13 +26,12 @@ impl UserServerAPI for UserServerMock {
}
fn sign_in(&self, params: SignInParams) -> ResultFuture<SignInResponse, UserError> {
let uid = params.email.clone();
ResultFuture::new(async {
Ok(SignInResponse {
uid,
name: params.email.clone(),
uid: "fake id".to_owned(),
name: "fake name".to_owned(),
email: params.email,
token: "".to_string(),
token: "fake token".to_string(),
})
})
}
@ -42,11 +40,15 @@ impl UserServerAPI for UserServerMock {
ResultFuture::new(async { Ok(()) })
}
fn update_user(&self, _params: UpdateUserParams) -> ResultFuture<(), UserError> {
fn update_user(&self, _token: &str, _params: UpdateUserParams) -> ResultFuture<(), UserError> {
ResultFuture::new(async { Ok(()) })
}
fn get_user_detail(&self, _token: &str) -> ResultFuture<UserDetail, UserError> {
ResultFuture::new(async { Err(ErrorBuilder::new(ErrorCode::Unknown).build()) })
ResultFuture::new(async {
Err(ErrorBuilder::new(ErrorCode::Unknown)
.msg("mock data, ignore this error")
.build())
})
}
}

View File

@ -1,5 +1,4 @@
use crate::services::user::{UserSession, UserSessionConfig};
use std::sync::Arc;
pub struct UserSessionBuilder {
config: Option<UserSessionConfig>,

View File

@ -1,7 +1,7 @@
use crate::{
entities::{SignInParams, SignUpParams, UpdateUserParams, UserDetail},
errors::{ErrorBuilder, ErrorCode, UserError},
services::user::{construct_user_server, database::UserDB, UserServerAPI},
services::user::{construct_user_server, database::UserDB},
sql_tables::{UserTable, UserTableChangeset},
};
@ -13,12 +13,12 @@ use flowy_database::{
UserDatabaseConnection,
};
use crate::{entities::UserToken, services::server::Server};
use crate::services::server::Server;
use flowy_infra::kv::KVStore;
use flowy_sqlite::ConnectionPool;
use parking_lot::RwLock;
use serde::{Deserialize, Serialize};
use serde_json::Error;
use std::sync::Arc;
pub struct UserSessionConfig {
@ -112,13 +112,9 @@ impl UserSession {
}
pub async fn user_detail(&self) -> Result<UserDetail, UserError> {
let user_id = self.get_session()?.user_id;
let user = dsl::user_table
.filter(user_table::id.eq(&user_id))
.first::<UserTable>(&*(self.get_db_connection()?))?;
let session = self.get_session()?;
let token = session.token;
let server = self.server.clone();
let token = user.token.clone();
tokio::spawn(async move {
match server.get_user_detail(&token).await {
Ok(user_detail) => {
@ -133,6 +129,10 @@ impl UserSession {
})
.await;
let user = dsl::user_table
.filter(user_table::id.eq(&session.user_id))
.first::<UserTable>(&*(self.get_db_connection()?))?;
Ok(UserDetail::from(user))
}
@ -194,7 +194,7 @@ impl UserSession {
}
pub async fn update_user(
server: Server,
_server: Server,
pool: Arc<ConnectionPool>,
params: UpdateUserParams,
) -> Result<(), UserError> {

View File

@ -21,7 +21,6 @@ fn user_detail_get() {
};
let response = TestBuilder::new()
.logout()
.event(SignIn)
.request(request)
.sync_send()

View File

@ -5,7 +5,7 @@ use crate::{
observable::{send_observable, WorkspaceObservable},
sql_tables::view::{ViewTable, ViewTableChangeset, ViewTableSql},
};
use flowy_net::{errors::ServerError, request::HttpRequestBuilder};
use flowy_net::request::HttpRequestBuilder;
use std::sync::Arc;
pub struct ViewController {