Skip to content

Commit

Permalink
Updated Assigment V_0_15_810
Browse files Browse the repository at this point in the history
I update.

=>Edit controllers update methods.
with one data format.

=>Make BookTest, BuyBookTest classes. and add test methods on it.
  • Loading branch information
13014932 committed May 16, 2018
1 parent a543fbe commit f8dfabb
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 41 deletions.
20 changes: 9 additions & 11 deletions app/Http/Controllers/Crud/BooksController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class BooksController extends Controller
// method to get adminbooks View.
public function adminbooks()
{
return view('admin.adminbooks');
return view('admin.adminbooks');

}

Expand All @@ -29,7 +29,7 @@ public function userbooks()
return view('user.userbooks', ['showdata' => $Books]);

} catch (\Exception $e) {
return redirect('errors')->withErrors( 'OOPS.! Error In Loading... Books.');
return redirect('errors')->withErrors('OOPS.! Error In Loading... Books.');


}
Expand All @@ -41,7 +41,7 @@ public function userbooks()
public function storeNewBook(Request $request)
{
$validator = Validator::make($request->all(), [
'book_name' => 'required|max:8',
'name' => 'required|max:8',
'book_created_date' => 'required|date'

]);
Expand All @@ -54,19 +54,18 @@ public function storeNewBook(Request $request)
try {

$data = new BookShopLib();
$data->storeNewBook($request);
$data->storeNewBook($request->toArray());

return back()->with('success', ['New Book Successfully Created.']);

} catch (\Exception $e) {
return back()->withErrors( 'OOPS.! Error In Creating New Book.');
return back()->withErrors('OOPS.! Error In Creating New Book.');

}

}



//method to UPDATE Book Data.

public function bookUpdate(Request $request)
Expand All @@ -83,12 +82,12 @@ public function bookUpdate(Request $request)
}
try {
$bookUpdate = new BookShopLib();
$bookUpdate->bookUpdate($request);
$bookUpdate->bookUpdate($request->toArray());

return back()->with('success', ['Book Successfully Updated.']);

} catch (\Exception $e) {
return back()->withErrors( 'OOPS.! Error In Book Update.');
return back()->withErrors('OOPS.! Error In Book Update.');


}
Expand All @@ -105,17 +104,16 @@ public function bookdelete(Request $request)
return back()->with('success', ['Book Successfully Deleted.']);

} catch (\Exception $e) {
return back()->withErrors( 'OOPS. Error In Book Delete..!');
return back()->withErrors('OOPS. Error In Book Delete..!');

}
}

// Method to display error on a page.
// Method to display error on a page.
public function errors()
{
return view('post.errors');
}



}
2 changes: 1 addition & 1 deletion app/Http/Controllers/Crud/BuyBooksController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function storeBookAfterBuy(Request $request)
{
try {
$data = new BuyBookShopLib();
$data->storeBookAfterBuy($request);
$data->storeBookAfterBuy($request->toArray());


return redirect('buydbooks')->with('success', ['Book *purchesed* Successfully.']);
Expand Down
19 changes: 10 additions & 9 deletions app/Lib/Crud/BookShopLib.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,16 @@ public function getBooks(): array
// method to store NEW BOOK data
public function storeNewBook($data)
{
// dd($data);

$saveBooks = new Book;

$saveBooks->name = $data->book_name;
$saveBooks->price = $data->price;
$saveBooks->author_name = $data->author_name;
$saveBooks->special_price = $data->special_price;
$saveBooks->book_created_date = $data->book_created_date;
$saveBooks->quantity = $data->quantity;
$saveBooks->name = $data['name'];
$saveBooks->price = $data['price'];
$saveBooks->author_name = $data['author_name'];
$saveBooks->special_price = $data['special_price'];
$saveBooks->book_created_date = $data['book_created_date'];
$saveBooks->quantity = $data['quantity'];

return $saveBooks->save();

Expand All @@ -53,11 +54,11 @@ public function storeNewBook($data)
//method to UPDATE Book Data.
public function bookUpdate($data)
{
$id = array("id" => $data->id);
$id = array("id" => $data['id']);


$bookUpdates = array("name" => $data->name, "price" => $data->price, "author_name" => $data->author_name,
"special_price" => $data->special_price, "book_created_date" => $data->book_created_date, "quantity" => $data->quantity);
$bookUpdates = array("name" => $data['name'], "price" => $data['price'], "author_name" => $data['author_name'],
"special_price" => $data['special_price'], "book_created_date" => $data['book_created_date'], "quantity" => $data['quantity']);


$updates= Book::updateOrCreate($id, $bookUpdates);
Expand Down
10 changes: 5 additions & 5 deletions app/Lib/Crud/BuyBookShopLib.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ public function storeBookAfterBuy($data)

$saveBook = new Buybook;

$saveBook->book_id = $data->book_id;
$saveBook->book_price = $data->book_price;
$saveBook->quantity = $data->model_book_quantity;
$saveBook->book_id = $data['book_id'];
$saveBook->book_price = $data['book_price'];
$saveBook->quantity = $data['model_book_quantity'];

$saveBook->save();
// SUBTRACT the buying quantity from BOOKS table.
$buyedBookQty=$data->model_book_quantity;
$book_id=$data->book_id;
$buyedBookQty=$data['model_book_quantity'];
$book_id=$data['book_id'];

$subBook = new BookShopLib();
$subBook->subtractBookQuantity($book_id,$buyedBookQty);
Expand Down
10 changes: 5 additions & 5 deletions resources/views/admin/adminbooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

if (Session::has('success')) {

echo "<div class=\"alert alert-success\" > <ul >" ;
echo "<div class=\"alert alert-success alert-dismissible\" > <a href=\"#\" class=\"close\" data-dismiss=\"alert\" aria-label=\"close\">&times;</a><ul >" ;

foreach (Session::get('success') as $suc) {

Expand All @@ -22,20 +22,20 @@

if ($errors->any()) {

echo "<div class=\"alert alert-danger\" > <ul >" ;
echo "<div class=\"alert alert-danger alert-dismissible\" > <a href=\"#\" class=\"close\" data-dismiss=\"alert\" aria-label=\"close\">&times;</a><ul >" ;

foreach ($errors->all() as $error) {


echo "<h2 ><li >".$error."</li ></h2 >";
echo "<h2 ><li >".$error."</li ></h2 ></ul></div>";


}

}
?>
</ul>
</div>



<div class="container">
<div class="table-wrapper">
Expand Down
2 changes: 1 addition & 1 deletion resources/views/layouts/BootStrapTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ function myFunction(split) {
<div class="modal-body">
<div class="form-group">
<label>book_name</label>
<input type="text" name="book_name" value="mybook" class="form-control" required>
<input type="text" name="name" value="mybook" class="form-control" required>
</div>
<div class="form-group">
<label>price</label>
Expand Down
50 changes: 41 additions & 9 deletions tests/Feature/BookTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,60 @@
class BookTest extends TestCase
{

//temprory method check Sum of Two Digit.

//temprory- method check Sum of Two Digit.
public function testCheckSum()
{
$data=BookShopLib::sum(3,2);
$data = BookShopLib::sum(3, 2);

$this->assertEquals(5, $data);
}
//Method to test book update.

//Method to test store new book.
public function testStoreBook()
{

$data = ["name" => "mybook",
"price" => "250",
"author_name" => "satpal",
"special_price" => "220",
"book_created_date" => "2018-06-07",
"quantity" => "5"];


$store = new BookShopLib();

$store->storeNewBook($data);
}


//Method to test book update.
public function testBookUpdate()
{
$data = [
"id" => "10",
"name" => "mybook",
"price" => "250",
"author_name" => "satpal",
"special_price" => "220",
"book_created_date" => "2018-06-07",
"quantity" => "400"];

$update = new BookShopLib();

$update=new BookShopLib();
$update->bookUpdate($data);



}
//Method to test book delete.
public function testBookDelete(){

$delete=new BookShopLib();
//Method to test book delete.

public function testBookDelete()
{

$delete = new BookShopLib();

$delete->bookdelete(40);
$delete->bookdelete(124);


}
Expand Down
27 changes: 27 additions & 0 deletions tests/Feature/BuyBookTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Tests\Feature;

use Tests\TestCase;
use App\Lib\Crud\BuyBookShopLib;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;

class BuyBookTest extends TestCase
{

//method to test book is store BOOK AFTER BUY.
public function teststoreBookAfterBuy(){

$data=[
"book_id" => "10",
"book_price" => "250",
"model_book_quantity" => "10"
];

$buyedbook=new BuyBookShopLib();
$buyedbook->storeBookAfterBuy($data);
}


}

0 comments on commit f8dfabb

Please sign in to comment.