From 6f94000c8031b52007ccc4fa7ffb2b2daf241723 Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Mon, 17 Jul 2023 18:56:41 +0100 Subject: [PATCH] remove methods from paths --- databases/mysql/README.md | 12 ++---- databases/mysql/apis/addbank.txt | 17 -------- databases/mysql/apis/bank.txt | 41 +++++++++++++++++++ .../mysql/apis/{addbranch.txt => branch.txt} | 28 ++++++++++++- .../apis/{addcustomer.txt => customer.txt} | 24 +++++++++++ databases/mysql/apis/getbank.txt | 23 ----------- databases/mysql/apis/getbranch.txt | 23 ----------- databases/mysql/apis/getcustomer.txt | 23 ----------- databases/mysql/apis/getteller.txt | 23 ----------- .../mysql/apis/{addteller.txt => teller.txt} | 28 ++++++++++++- databases/mysql/src/db_layer.rs | 2 - databases/mysql/src/main.rs | 16 ++++---- 12 files changed, 129 insertions(+), 131 deletions(-) delete mode 100644 databases/mysql/apis/addbank.txt create mode 100644 databases/mysql/apis/bank.txt rename databases/mysql/apis/{addbranch.txt => branch.txt} (51%) rename databases/mysql/apis/{addcustomer.txt => customer.txt} (58%) delete mode 100644 databases/mysql/apis/getbank.txt delete mode 100644 databases/mysql/apis/getbranch.txt delete mode 100644 databases/mysql/apis/getcustomer.txt delete mode 100644 databases/mysql/apis/getteller.txt rename databases/mysql/apis/{addteller.txt => teller.txt} (51%) diff --git a/databases/mysql/README.md b/databases/mysql/README.md index 36ebcbbb..48dc2b4a 100644 --- a/databases/mysql/README.md +++ b/databases/mysql/README.md @@ -71,13 +71,9 @@ You may need to ensure that you are running the commands with the correct MySQL Directory "mysql/apis" contains below listed API's files: - - `addbank.txt` - - `addbranch.txt` - - `addteller.txt` - - `addcustomer.txt` - - `getbank.txt` - - `getbranch.txt` - - `getteller.txt` - - `getcustomer.txt` + - `bank.txt` + - `branch.txt` + - `teller.txt` + - `customer.txt` Copy the curl request on each of the ".txt" and execute them on separate terminals. Each ".txt" contains curl request and expected JSON response data. diff --git a/databases/mysql/apis/addbank.txt b/databases/mysql/apis/addbank.txt deleted file mode 100644 index 849e41f6..00000000 --- a/databases/mysql/apis/addbank.txt +++ /dev/null @@ -1,17 +0,0 @@ -1. -Linux - -curl -d '{"bank_name":"Bank ABC","country":"Kenya"}' -H 'Content-Type: application/json' http://127.0.0.1:8080/addbank - -2. -Windows - -curl -H "Content-type:application/json" --data-binary "{\"bank_name\":\"Bank ABC\",\"country\":\"Kenya\"}" http://127.0.0.1:8080/addbank - -3. -JSON response - -{ - "status_code": 0, - "status_description": "Successful" -} diff --git a/databases/mysql/apis/bank.txt b/databases/mysql/apis/bank.txt new file mode 100644 index 00000000..da956c00 --- /dev/null +++ b/databases/mysql/apis/bank.txt @@ -0,0 +1,41 @@ +1. +Linux + +curl -d '{"bank_name":"Bank ABC","country":"Kenya"}' -H 'Content-Type: application/json' http://127.0.0.1:8080/bank + +2. +Windows + +curl -H "Content-type:application/json" --data-binary "{\"bank_name\":\"Bank ABC\",\"country\":\"Kenya\"}" http://127.0.0.1:8080/bank + +3. +JSON response + +{ + "status_code": 0, + "status_description": "Successful" +} + +4. +Linux + +curl 'http://localhost:8080/bank' + +5. +Windows + +curl http://localhost:8080/bank + +6. +JSON response + +{ + "status_code": 0, + "status_description": "Successful", + "bank_data": [ + { + "bank_name": "bank abc", + "country": "kenya" + } + ] +} diff --git a/databases/mysql/apis/addbranch.txt b/databases/mysql/apis/branch.txt similarity index 51% rename from databases/mysql/apis/addbranch.txt rename to databases/mysql/apis/branch.txt index 375a2ec1..01a44798 100644 --- a/databases/mysql/apis/addbranch.txt +++ b/databases/mysql/apis/branch.txt @@ -1,12 +1,12 @@ 1. Linux -curl -d '{"branch_name":"HQ branch", "location":"Central Business District"}' -H 'Content-Type: application/json' http://127.0.0.1:8080/addbranch +curl -d '{"branch_name":"HQ branch", "location":"Central Business District"}' -H 'Content-Type: application/json' http://127.0.0.1:8080/branch 2. Windows -curl -H "Content-type:application/json" --data-binary "{\"branch_name\":\"HQ branch\", \"location\":\"Central Business District\"}" http://127.0.0.1:8080/addbranch +curl -H "Content-type:application/json" --data-binary "{\"branch_name\":\"HQ branch\", \"location\":\"Central Business District\"}" http://127.0.0.1:8080/branch 3. @@ -16,3 +16,27 @@ JSON response "status_code": 0, "status_description": "Successful" } + +4. +Linux + +curl 'http://localhost:8080/branch' + +5. +Windows + +curl http://localhost:8080/branch + +6. +JSON response + +{ + "status_code": 0, + "status_description": "Successful", + "branch_data": [ + { + "branch_name": "hq branch", + "location": "central business district" + } + ] +} diff --git a/databases/mysql/apis/addcustomer.txt b/databases/mysql/apis/customer.txt similarity index 58% rename from databases/mysql/apis/addcustomer.txt rename to databases/mysql/apis/customer.txt index 86c125f9..a0869278 100644 --- a/databases/mysql/apis/addcustomer.txt +++ b/databases/mysql/apis/customer.txt @@ -16,3 +16,27 @@ JSON response "status_code": 0, "status_description": "Successful" } + +4. +Linux + +curl 'http://localhost:8080/customer' + +5. +Windows + +curl http://localhost:8080/customer + +6. +JSON response + +{ + "status_code": 0, + "status_description": "Successful", + "customer_data": [ + { + "customer_name": "peter paul", + "branch_name": "central business district" + } + ] +} diff --git a/databases/mysql/apis/getbank.txt b/databases/mysql/apis/getbank.txt deleted file mode 100644 index 58d33099..00000000 --- a/databases/mysql/apis/getbank.txt +++ /dev/null @@ -1,23 +0,0 @@ -1. -Linux - -curl 'http://localhost:8080/getbank' - -2. -Windows - -curl http://localhost:8080/getbank - -3. -JSON response - -{ - "status_code": 0, - "status_description": "Successful", - "bank_data": [ - { - "bank_name": "bank abc", - "country": "kenya" - } - ] -} diff --git a/databases/mysql/apis/getbranch.txt b/databases/mysql/apis/getbranch.txt deleted file mode 100644 index efa3300c..00000000 --- a/databases/mysql/apis/getbranch.txt +++ /dev/null @@ -1,23 +0,0 @@ -1. -Linux - -curl 'http://localhost:8080/getbranch' - -2. -Windows - -curl http://localhost:8080/getbranch - -3. -JSON response - -{ - "status_code": 0, - "status_description": "Successful", - "branch_data": [ - { - "branch_name": "hq branch", - "location": "central business district" - } - ] -} diff --git a/databases/mysql/apis/getcustomer.txt b/databases/mysql/apis/getcustomer.txt deleted file mode 100644 index 1236c4db..00000000 --- a/databases/mysql/apis/getcustomer.txt +++ /dev/null @@ -1,23 +0,0 @@ -1. -Linux - -curl 'http://localhost:8080/getcustomer' - -2. -Windows - -curl http://localhost:8080/getcustomer - -3. -JSON response - -{ - "status_code": 0, - "status_description": "Successful", - "customer_data": [ - { - "customer_name": "peter paul", - "branch_name": "central business district" - } - ] -} diff --git a/databases/mysql/apis/getteller.txt b/databases/mysql/apis/getteller.txt deleted file mode 100644 index 251e503a..00000000 --- a/databases/mysql/apis/getteller.txt +++ /dev/null @@ -1,23 +0,0 @@ -1. -Linux - -curl 'http://localhost:8080/getteller' - -2. -Windows - -curl http://localhost:8080/getteller - -3. -JSON response - -{ - "status_code": 0, - "status_description": "Successful", - "teller_data": [ - { - "teller_name": "john doe", - "branch_name": "central business district" - } - ] -} diff --git a/databases/mysql/apis/addteller.txt b/databases/mysql/apis/teller.txt similarity index 51% rename from databases/mysql/apis/addteller.txt rename to databases/mysql/apis/teller.txt index 034d3489..02310b83 100644 --- a/databases/mysql/apis/addteller.txt +++ b/databases/mysql/apis/teller.txt @@ -1,12 +1,12 @@ 1. Linux -curl -d '{"teller_name":"John Doe", "branch_name":"Central Business District"}' -H 'Content-Type: application/json' http://127.0.0.1:8080/addteller +curl -d '{"teller_name":"John Doe", "branch_name":"Central Business District"}' -H 'Content-Type: application/json' http://127.0.0.1:8080/teller 2. Windows -curl -H "Content-type:application/json" --data-binary "{\"teller_name\":\"John Doe\", \"branch_name\":\"Central Business District\"}" http://127.0.0.1:8080/addteller +curl -H "Content-type:application/json" --data-binary "{\"teller_name\":\"John Doe\", \"branch_name\":\"Central Business District\"}" http://127.0.0.1:8080/teller 3. @@ -16,3 +16,27 @@ JSON response "status_code": 0, "status_description": "Successful" } + +4. +Linux + +curl 'http://localhost:8080/teller' + +5. +Windows + +curl http://localhost:8080/teller + +6. +JSON response + +{ + "status_code": 0, + "status_description": "Successful", + "teller_data": [ + { + "teller_name": "john doe", + "branch_name": "central business district" + } + ] +} diff --git a/databases/mysql/src/db_layer.rs b/databases/mysql/src/db_layer.rs index 24935ad5..0f463b5e 100644 --- a/databases/mysql/src/db_layer.rs +++ b/databases/mysql/src/db_layer.rs @@ -206,8 +206,6 @@ pub fn get_branch_data(pool: &mysql::Pool) -> BranchResponseData { my_status_description = "Successful".to_owned(); } - //Assign values to struct variable - BranchResponseData { status_code: my_status_code, status_description: my_status_description, diff --git a/databases/mysql/src/main.rs b/databases/mysql/src/main.rs index a6937a06..bb8f2fd2 100644 --- a/databases/mysql/src/main.rs +++ b/databases/mysql/src/main.rs @@ -94,7 +94,7 @@ async fn index() -> impl Responder { String::new() } -#[post("/addbank")] +#[post("/bank")] async fn add_bank(bank_data: web::Json, data: web::Data) -> impl Responder { let bank_name = &bank_data.bank_name; let _country = &bank_data.country; @@ -104,7 +104,7 @@ async fn add_bank(bank_data: web::Json, data: web::Data) web::Json(response_data) } -#[post("/addbranch")] +#[post("/branch")] async fn add_branch( branch_data: web::Json, data: web::Data, @@ -118,7 +118,7 @@ async fn add_branch( web::Json(response_data) } -#[post("/addteller")] +#[post("/teller")] async fn add_teller( teller_data: web::Json, data: web::Data, @@ -132,7 +132,7 @@ async fn add_teller( web::Json(response_data) } -#[post("/addcustomer")] +#[post("/customer")] async fn add_customer( customer_data: web::Json, data: web::Data, @@ -146,28 +146,28 @@ async fn add_customer( web::Json(response_data) } -#[get("/getbank")] +#[get("/bank")] async fn get_bank(data: web::Data) -> impl Responder { let bank_response_data = db_layer::get_bank_data(&data); web::Json(bank_response_data) } -#[get("/getbranch")] +#[get("/branch")] async fn get_branch(data: web::Data) -> impl Responder { let branch_response_data = db_layer::get_branch_data(&data); web::Json(branch_response_data) } -#[get("/getteller")] +#[get("/teller")] async fn get_teller(data: web::Data) -> impl Responder { let teller_response_data = db_layer::get_teller_data(&data); web::Json(teller_response_data) } -#[get("/getcustomer")] +#[get("/customer")] async fn get_customer(data: web::Data) -> impl Responder { let customer_response_data = db_layer::get_customer_data(&data);