Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
billy1624 committed Sep 21, 2022
1 parent 2fbb964 commit 4f7f11c
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 91 deletions.
1 change: 1 addition & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ on:
branches:
- master
- 0.2.x
- pr/890

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
Expand Down
20 changes: 10 additions & 10 deletions examples/actix3_example/core/src/mutation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ impl Mutation {
id: i32,
form_data: post::Model,
) -> Result<post::Model, DbErr> {
let post: post::ActiveModel = if let Ok(Some(post)) = Post::find_by_id(id).one(db).await {
post.into()
} else {
return Err(DbErr::Custom("Cannot find post.".to_owned()));
};
let post: post::ActiveModel = Post::find_by_id(id)
.one(db)
.await?
.ok_or(DbErr::Custom("Cannot find post.".to_owned()))
.map(Into::into)?;

post::ActiveModel {
id: post.id,
Expand All @@ -38,11 +38,11 @@ impl Mutation {
}

pub async fn delete_post(db: &DbConn, id: i32) -> Result<DeleteResult, DbErr> {
let post: post::ActiveModel = if let Ok(Some(post)) = Post::find_by_id(id).one(db).await {
post.into()
} else {
return Err(DbErr::Custom("Cannot find post.".to_owned()));
};
let post: post::ActiveModel = Post::find_by_id(id)
.one(db)
.await?
.ok_or(DbErr::Custom("Cannot find post.".to_owned()))
.map(Into::into)?;

post.delete(db).await
}
Expand Down
20 changes: 10 additions & 10 deletions examples/actix_example/core/src/mutation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ impl Mutation {
id: i32,
form_data: post::Model,
) -> Result<post::Model, DbErr> {
let post: post::ActiveModel = if let Ok(Some(post)) = Post::find_by_id(id).one(db).await {
post.into()
} else {
return Err(DbErr::Custom("Cannot find post.".to_owned()));
};
let post: post::ActiveModel = Post::find_by_id(id)
.one(db)
.await?
.ok_or(DbErr::Custom("Cannot find post.".to_owned()))
.map(Into::into)?;

post::ActiveModel {
id: post.id,
Expand All @@ -38,11 +38,11 @@ impl Mutation {
}

pub async fn delete_post(db: &DbConn, id: i32) -> Result<DeleteResult, DbErr> {
let post: post::ActiveModel = if let Ok(Some(post)) = Post::find_by_id(id).one(db).await {
post.into()
} else {
return Err(DbErr::Custom("Cannot find post.".to_owned()));
};
let post: post::ActiveModel = Post::find_by_id(id)
.one(db)
.await?
.ok_or(DbErr::Custom("Cannot find post.".to_owned()))
.map(Into::into)?;

post.delete(db).await
}
Expand Down
20 changes: 10 additions & 10 deletions examples/axum_example/core/src/mutation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ impl Mutation {
id: i32,
form_data: post::Model,
) -> Result<post::Model, DbErr> {
let post: post::ActiveModel = if let Ok(Some(post)) = Post::find_by_id(id).one(db).await {
post.into()
} else {
return Err(DbErr::Custom("Cannot find post.".to_owned()));
};
let post: post::ActiveModel = Post::find_by_id(id)
.one(db)
.await?
.ok_or(DbErr::Custom("Cannot find post.".to_owned()))
.map(Into::into)?;

post::ActiveModel {
id: post.id,
Expand All @@ -38,11 +38,11 @@ impl Mutation {
}

pub async fn delete_post(db: &DbConn, id: i32) -> Result<DeleteResult, DbErr> {
let post: post::ActiveModel = if let Ok(Some(post)) = Post::find_by_id(id).one(db).await {
post.into()
} else {
return Err(DbErr::Custom("Cannot find post.".to_owned()));
};
let post: post::ActiveModel = Post::find_by_id(id)
.one(db)
.await?
.ok_or(DbErr::Custom("Cannot find post.".to_owned()))
.map(Into::into)?;

post.delete(db).await
}
Expand Down
20 changes: 10 additions & 10 deletions examples/graphql_example/core/src/mutation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ impl Mutation {
id: i32,
form_data: note::Model,
) -> Result<note::Model, DbErr> {
let note: note::ActiveModel = if let Ok(Some(note)) = Note::find_by_id(id).one(db).await {
note.into()
} else {
return Err(DbErr::Custom("Cannot find note.".to_owned()));
};
let note: note::ActiveModel = Note::find_by_id(id)
.one(db)
.await?
.ok_or(DbErr::Custom("Cannot find note.".to_owned()))
.map(Into::into)?;

note::ActiveModel {
id: note.id,
Expand All @@ -39,11 +39,11 @@ impl Mutation {
}

pub async fn delete_note(db: &DbConn, id: i32) -> Result<DeleteResult, DbErr> {
let note: note::ActiveModel = if let Ok(Some(note)) = Note::find_by_id(id).one(db).await {
note.into()
} else {
return Err(DbErr::Custom("Cannot find note.".to_owned()));
};
let note: note::ActiveModel = Note::find_by_id(id)
.one(db)
.await?
.ok_or(DbErr::Custom("Cannot find note.".to_owned()))
.map(Into::into)?;

note.delete(db).await
}
Expand Down
2 changes: 1 addition & 1 deletion examples/jsonrpsee_example/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl PostRpcServer for PpcImpl {
async fn insert(&self, p: post::Model) -> RpcResult<i32> {
let new_post = Mutation::create_post(&self.conn, p)
.await
.expect("could not insert post");
.internal_call_error()?;

Ok(new_post.id.unwrap())
}
Expand Down
20 changes: 10 additions & 10 deletions examples/jsonrpsee_example/core/src/mutation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ impl Mutation {
id: i32,
form_data: post::Model,
) -> Result<post::Model, DbErr> {
let post: post::ActiveModel = if let Ok(Some(post)) = Post::find_by_id(id).one(db).await {
post.into()
} else {
return Err(DbErr::Custom("Cannot find post.".to_owned()));
};
let post: post::ActiveModel = Post::find_by_id(id)
.one(db)
.await?
.ok_or(DbErr::Custom("Cannot find post.".to_owned()))
.map(Into::into)?;

post::ActiveModel {
id: post.id,
Expand All @@ -38,11 +38,11 @@ impl Mutation {
}

pub async fn delete_post(db: &DbConn, id: i32) -> Result<DeleteResult, DbErr> {
let post: post::ActiveModel = if let Ok(Some(post)) = Post::find_by_id(id).one(db).await {
post.into()
} else {
return Err(DbErr::Custom("Cannot find post.".to_owned()));
};
let post: post::ActiveModel = Post::find_by_id(id)
.one(db)
.await?
.ok_or(DbErr::Custom("Cannot find post.".to_owned()))
.map(Into::into)?;

post.delete(db).await
}
Expand Down
20 changes: 10 additions & 10 deletions examples/poem_example/core/src/mutation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ impl Mutation {
id: i32,
form_data: post::Model,
) -> Result<post::Model, DbErr> {
let post: post::ActiveModel = if let Ok(Some(post)) = Post::find_by_id(id).one(db).await {
post.into()
} else {
return Err(DbErr::Custom("Cannot find post.".to_owned()));
};
let post: post::ActiveModel = Post::find_by_id(id)
.one(db)
.await?
.ok_or(DbErr::Custom("Cannot find post.".to_owned()))
.map(Into::into)?;

post::ActiveModel {
id: post.id,
Expand All @@ -38,11 +38,11 @@ impl Mutation {
}

pub async fn delete_post(db: &DbConn, id: i32) -> Result<DeleteResult, DbErr> {
let post: post::ActiveModel = if let Ok(Some(post)) = Post::find_by_id(id).one(db).await {
post.into()
} else {
return Err(DbErr::Custom("Cannot find post.".to_owned()));
};
let post: post::ActiveModel = Post::find_by_id(id)
.one(db)
.await?
.ok_or(DbErr::Custom("Cannot find post.".to_owned()))
.map(Into::into)?;

post.delete(db).await
}
Expand Down
20 changes: 10 additions & 10 deletions examples/rocket_example/core/src/mutation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ impl Mutation {
id: i32,
form_data: post::Model,
) -> Result<post::Model, DbErr> {
let post: post::ActiveModel = if let Ok(Some(post)) = Post::find_by_id(id).one(db).await {
post.into()
} else {
return Err(DbErr::Custom("Cannot find post.".to_owned()));
};
let post: post::ActiveModel = Post::find_by_id(id)
.one(db)
.await?
.ok_or(DbErr::Custom("Cannot find post.".to_owned()))
.map(Into::into)?;

post::ActiveModel {
id: post.id,
Expand All @@ -38,11 +38,11 @@ impl Mutation {
}

pub async fn delete_post(db: &DbConn, id: i32) -> Result<DeleteResult, DbErr> {
let post: post::ActiveModel = if let Ok(Some(post)) = Post::find_by_id(id).one(db).await {
post.into()
} else {
return Err(DbErr::Custom("Cannot find post.".to_owned()));
};
let post: post::ActiveModel = Post::find_by_id(id)
.one(db)
.await?
.ok_or(DbErr::Custom("Cannot find post.".to_owned()))
.map(Into::into)?;

post.delete(db).await
}
Expand Down
20 changes: 10 additions & 10 deletions examples/salvo_example/core/src/mutation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ impl Mutation {
id: i32,
form_data: post::Model,
) -> Result<post::Model, DbErr> {
let post: post::ActiveModel = if let Ok(Some(post)) = Post::find_by_id(id).one(db).await {
post.into()
} else {
return Err(DbErr::Custom("Cannot find post.".to_owned()));
};
let post: post::ActiveModel = Post::find_by_id(id)
.one(db)
.await?
.ok_or(DbErr::Custom("Cannot find post.".to_owned()))
.map(Into::into)?;

post::ActiveModel {
id: post.id,
Expand All @@ -38,11 +38,11 @@ impl Mutation {
}

pub async fn delete_post(db: &DbConn, id: i32) -> Result<DeleteResult, DbErr> {
let post: post::ActiveModel = if let Ok(Some(post)) = Post::find_by_id(id).one(db).await {
post.into()
} else {
return Err(DbErr::Custom("Cannot find post.".to_owned()));
};
let post: post::ActiveModel = Post::find_by_id(id)
.one(db)
.await?
.ok_or(DbErr::Custom("Cannot find post.".to_owned()))
.map(Into::into)?;

post.delete(db).await
}
Expand Down
20 changes: 10 additions & 10 deletions examples/tonic_example/core/src/mutation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ impl Mutation {
id: i32,
form_data: post::Model,
) -> Result<post::Model, DbErr> {
let post: post::ActiveModel = if let Ok(Some(post)) = Post::find_by_id(id).one(db).await {
post.into()
} else {
return Err(DbErr::Custom("Cannot find post.".to_owned()));
};
let post: post::ActiveModel = Post::find_by_id(id)
.one(db)
.await?
.ok_or(DbErr::Custom("Cannot find post.".to_owned()))
.map(Into::into)?;

post::ActiveModel {
id: post.id,
Expand All @@ -38,11 +38,11 @@ impl Mutation {
}

pub async fn delete_post(db: &DbConn, id: i32) -> Result<DeleteResult, DbErr> {
let post: post::ActiveModel = if let Ok(Some(post)) = Post::find_by_id(id).one(db).await {
post.into()
} else {
return Err(DbErr::Custom("Cannot find post.".to_owned()));
};
let post: post::ActiveModel = Post::find_by_id(id)
.one(db)
.await?
.ok_or(DbErr::Custom("Cannot find post.".to_owned()))
.map(Into::into)?;

post.delete(db).await
}
Expand Down

0 comments on commit 4f7f11c

Please sign in to comment.