mirror of
https://github.com/actix/examples
synced 2024-11-23 14:31:07 +01:00
Minor lints and clippies (#557)
This commit is contained in:
parent
7a957cee6e
commit
912de4aa46
@ -5,6 +5,7 @@ use serde::Deserialize;
|
|||||||
use crate::errors::ServiceError;
|
use crate::errors::ServiceError;
|
||||||
use crate::models::{Invitation, Pool, SlimUser, User};
|
use crate::models::{Invitation, Pool, SlimUser, User};
|
||||||
use crate::utils::hash_password;
|
use crate::utils::hash_password;
|
||||||
|
|
||||||
// UserData is used to extract data from a post request by the client
|
// UserData is used to extract data from a post request by the client
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
pub struct UserData {
|
pub struct UserData {
|
||||||
|
@ -103,7 +103,7 @@ mod tests {
|
|||||||
.build(manager)
|
.build(manager)
|
||||||
.expect("Failed to create pool.");
|
.expect("Failed to create pool.");
|
||||||
|
|
||||||
let mut app = test::init_service(
|
let app = test::init_service(
|
||||||
App::new()
|
App::new()
|
||||||
.app_data(web::Data::new(pool.clone()))
|
.app_data(web::Data::new(pool.clone()))
|
||||||
.wrap(middleware::Logger::default())
|
.wrap(middleware::Logger::default())
|
||||||
@ -120,7 +120,7 @@ mod tests {
|
|||||||
})
|
})
|
||||||
.to_request();
|
.to_request();
|
||||||
|
|
||||||
let resp: models::User = test::call_and_read_body_json(&mut app, req).await;
|
let resp: models::User = test::call_and_read_body_json(&app, req).await;
|
||||||
|
|
||||||
assert_eq!(resp.name, "Test user");
|
assert_eq!(resp.name, "Test user");
|
||||||
|
|
||||||
@ -129,7 +129,7 @@ mod tests {
|
|||||||
.uri(&format!("/user/{}", resp.id))
|
.uri(&format!("/user/{}", resp.id))
|
||||||
.to_request();
|
.to_request();
|
||||||
|
|
||||||
let resp: models::User = test::call_and_read_body_json(&mut app, req).await;
|
let resp: models::User = test::call_and_read_body_json(&app, req).await;
|
||||||
|
|
||||||
assert_eq!(resp.name, "Test user");
|
assert_eq!(resp.name, "Test user");
|
||||||
|
|
||||||
|
@ -33,9 +33,8 @@ async fn index() -> HttpResponse {
|
|||||||
<head><title>Upload Test</title></head>
|
<head><title>Upload Test</title></head>
|
||||||
<body>
|
<body>
|
||||||
<form target="/" method="post" enctype="multipart/form-data" id="myForm" >
|
<form target="/" method="post" enctype="multipart/form-data" id="myForm" >
|
||||||
<input type="text" id="text" name="text" value="test_text"/>
|
<input type="text" id="text" name="text" value="test_text"/>
|
||||||
<input type="number" id="number" name="number" value="123123"/>
|
<input type="number" id="number" name="number" value="123123"/>
|
||||||
|
|
||||||
<input type="button" value="Submit" onclick="myFunction()"></button>
|
<input type="button" value="Submit" onclick="myFunction()"></button>
|
||||||
</form>
|
</form>
|
||||||
<input type="file" multiple name="file" id="myFile"/>
|
<input type="file" multiple name="file" id="myFile"/>
|
||||||
@ -45,7 +44,7 @@ async fn index() -> HttpResponse {
|
|||||||
function myFunction(){
|
function myFunction(){
|
||||||
var myForm = document.getElementById('myForm');
|
var myForm = document.getElementById('myForm');
|
||||||
var myFile = document.getElementById('myFile');
|
var myFile = document.getElementById('myFile');
|
||||||
|
|
||||||
let formData = new FormData();
|
let formData = new FormData();
|
||||||
const obj = {
|
const obj = {
|
||||||
text: document.getElementById('text').value,
|
text: document.getElementById('text').value,
|
||||||
@ -54,17 +53,15 @@ async fn index() -> HttpResponse {
|
|||||||
const json = JSON.stringify(obj);
|
const json = JSON.stringify(obj);
|
||||||
console.log(obj);
|
console.log(obj);
|
||||||
console.log(json);
|
console.log(json);
|
||||||
|
|
||||||
|
|
||||||
formData.append("data", json);
|
formData.append("data", json);
|
||||||
formData.append("myFile", myFile.files[0]);
|
formData.append("myFile", myFile.files[0]);
|
||||||
|
|
||||||
var request = new XMLHttpRequest();
|
var request = new XMLHttpRequest();
|
||||||
request.open("POST", "");
|
request.open("POST", "");
|
||||||
request.send(formData);
|
request.send(formData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
</html>"#;
|
</html>"#;
|
||||||
|
|
||||||
|
@ -1,6 +1,3 @@
|
|||||||
#[macro_use]
|
|
||||||
extern crate juniper;
|
|
||||||
|
|
||||||
use actix_cors::Cors;
|
use actix_cors::Cors;
|
||||||
use actix_web::{middleware::Logger, web::Data, App, HttpServer};
|
use actix_web::{middleware::Logger, web::Data, App, HttpServer};
|
||||||
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
use juniper::GraphQLInputObject;
|
||||||
use mysql::{from_row, params, Error as DBError, Row};
|
use mysql::{from_row, params, Error as DBError, Row};
|
||||||
|
|
||||||
use crate::schemas::root::Context;
|
use crate::schemas::root::Context;
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
use juniper::{EmptySubscription, FieldError, FieldResult, RootNode};
|
use juniper::{
|
||||||
|
graphql_object, graphql_value, EmptySubscription, FieldError, FieldResult, RootNode,
|
||||||
|
};
|
||||||
use mysql::{from_row, params, Error as DBError, Row};
|
use mysql::{from_row, params, Error as DBError, Row};
|
||||||
|
|
||||||
use crate::db::Pool;
|
use crate::db::Pool;
|
||||||
@ -14,7 +16,7 @@ impl juniper::Context for Context {}
|
|||||||
|
|
||||||
pub struct QueryRoot;
|
pub struct QueryRoot;
|
||||||
|
|
||||||
#[juniper::graphql_object(Context = Context)]
|
#[graphql_object(Context = Context)]
|
||||||
impl QueryRoot {
|
impl QueryRoot {
|
||||||
#[graphql(description = "List of all users")]
|
#[graphql(description = "List of all users")]
|
||||||
fn users(context: &Context) -> FieldResult<Vec<User>> {
|
fn users(context: &Context) -> FieldResult<Vec<User>> {
|
||||||
@ -99,7 +101,7 @@ impl QueryRoot {
|
|||||||
|
|
||||||
pub struct MutationRoot;
|
pub struct MutationRoot;
|
||||||
|
|
||||||
#[juniper::graphql_object(Context = Context)]
|
#[graphql_object(Context = Context)]
|
||||||
impl MutationRoot {
|
impl MutationRoot {
|
||||||
fn create_user(context: &Context, user: UserInput) -> FieldResult<User> {
|
fn create_user(context: &Context, user: UserInput) -> FieldResult<User> {
|
||||||
let mut conn = context.dbpool.get().unwrap();
|
let mut conn = context.dbpool.get().unwrap();
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
use juniper::{graphql_object, GraphQLInputObject};
|
||||||
use mysql::{from_row, params};
|
use mysql::{from_row, params};
|
||||||
|
|
||||||
use crate::schemas::product::Product;
|
use crate::schemas::product::Product;
|
||||||
@ -18,7 +19,7 @@ pub struct UserInput {
|
|||||||
pub email: String,
|
pub email: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[juniper::graphql_object(Context = Context)]
|
#[graphql_object(Context = Context)]
|
||||||
impl User {
|
impl User {
|
||||||
fn id(&self) -> &str {
|
fn id(&self) -> &str {
|
||||||
&self.id
|
&self.id
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
#[macro_use]
|
|
||||||
extern crate prost_derive;
|
|
||||||
|
|
||||||
use actix_protobuf::{ProtoBuf, ProtoBufResponseBuilder as _};
|
use actix_protobuf::{ProtoBuf, ProtoBufResponseBuilder as _};
|
||||||
use actix_web::{middleware, web, App, HttpResponse, HttpServer, Result};
|
use actix_web::{middleware, web, App, HttpResponse, HttpServer, Result};
|
||||||
|
use prost_derive::Message;
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Message)]
|
#[derive(Clone, PartialEq, Message)]
|
||||||
pub struct MyObj {
|
pub struct MyObj {
|
||||||
|
Loading…
Reference in New Issue
Block a user