Skip to content
This repository has been archived by the owner on Jul 20, 2023. It is now read-only.

Commit

Permalink
Merge pull request #7 from PAXANDDOS/dev
Browse files Browse the repository at this point in the history
README and small fixes.
  • Loading branch information
PAXANDDOS authored Jan 21, 2022
2 parents 0980e77 + 9b752d5 commit 569fee9
Show file tree
Hide file tree
Showing 49 changed files with 6,037 additions and 104 deletions.
7 changes: 7 additions & 0 deletions .env.testing.example

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.DS_Store
._.DS_Store
.env
.env.testing
/vendor/
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 Paul

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
103 changes: 103 additions & 0 deletions README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 11 additions & 10 deletions app/Http/Controllers/Api/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

namespace App\Http\Controllers\Api;

use Framework\{API, Auth};
use Framework\Api\{Http, Auth, Validation};
use App\Models\{User, Session};

/**
* API methods for authorization
* Contains API methods for authorization
*/
class AuthController extends Controller
{
Expand All @@ -18,15 +18,16 @@ class AuthController extends Controller
*/
public function signIn(mixed $data): void
{
Validation::validateUser($data->name, null, $data->password);
if (!$user = User::findWhere('name', $data->name))
API::response('json', ["message" => "Invalid credentials."], 400);
Http::response('json', ["message" => "Invalid credentials."], 400);
if ($user[0]->password !== hash('md5', $data->password))
API::response('json', ["message" => "Invalid password."], 403);
Http::response('json', ["message" => "Invalid password."], 403);
if ($session = Session::findWhere('user_id', $user[0]->id))
Session::destroy($session[0]->token);

$token = Auth::attempt($user[0]);
API::response('json', [
Http::response('json', [
'message' => "Signed in.",
'cookie' => [
'id' => $user[0]->id,
Expand All @@ -45,18 +46,18 @@ public function signIn(mixed $data): void
*/
public function signUp(mixed $data): void
{
Validation::validateUser($data->name, $data->email, $data->password);
Validation::validatePassMatch($data->password, $data->password_confirmation);
if (User::findWhere('name', $data->name))
API::response('json', ["message" => "This user name is already taken."], 400);
if ($data->password !== $data->password_confirmation)
API::response('json', ["message" => "Passwords did not match."], 400);
Http::response('json', ["message" => "This user name is already taken."], 400);

User::create([
"name" => $data->name,
"email" => $data->email,
"password" => hash("md5", $data->password)
]);

API::response('json', [
Http::response('json', [
'message' => "Successfully signed up."
], 201);
}
Expand All @@ -69,7 +70,7 @@ public function signUp(mixed $data): void
public function signOut(): void
{
Session::destroy(Auth::token());
API::response('json', [
Http::response('json', [
"message" => 'Successfully signed out.'
]);
}
Expand Down
6 changes: 3 additions & 3 deletions app/Http/Controllers/Api/CatalogController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Http\Controllers\Api;

use Framework\API;
use Framework\Api\Http;
use App\Models\Product;

/**
Expand All @@ -17,7 +17,7 @@ class CatalogController extends Controller
*/
public function index(): void
{
API::response('json', Product::getAll());
Http::response('json', Product::getAll());
}

/**
Expand All @@ -28,6 +28,6 @@ public function index(): void
*/
public function show(int $id): void
{
API::response('json', Product::findOne($id));
Http::response('json', Product::findOne($id));
}
}
13 changes: 6 additions & 7 deletions app/Http/Controllers/Api/OrderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Http\Controllers\Api;

use Framework\{API, Auth};
use Framework\Api\{Http, Auth};
use App\Models\Order;

/**
Expand All @@ -17,7 +17,7 @@ class OrderController extends Controller
*/
public function index(): void
{
API::response('json', Order::findWhere('user_id', Auth::user()->id));
Http::response('json', Order::findWhere('user_id', Auth::user()->id));
}

/**
Expand All @@ -29,7 +29,7 @@ public function index(): void
public function show(int $id): void
{
Auth::user();
API::response('json', Order::findOne($id));
Http::response('json', Order::findOne($id));
}

/**
Expand All @@ -41,14 +41,13 @@ public function create(array $data): void
{
$user = Auth::user();
foreach ($data as $product) {
$quantity = property_exists($product, 'quantity') ? $product->quantity : 1;
Order::create([
'user_id' => $user->id,
'product_id' => $product->id,
'quantity' => $quantity,
'quantity' => property_exists($product, 'quantity') ? $product->quantity : 1,
]);
}
API::response('json', [
Http::response('json', [
'message' => "Order succesfully created."
], 201);
}
Expand All @@ -61,6 +60,6 @@ public function create(array $data): void
public function destroy(int $id): void
{
Auth::user();
API::response('json', Order::destroy($id), 201);
Http::response('json', Order::destroy($id), 201);
}
}
6 changes: 3 additions & 3 deletions app/Http/Controllers/Api/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Http\Controllers\Api;

use Framework\API;
use Framework\Api\Http;
use App\Models\User;

/**
Expand All @@ -17,7 +17,7 @@ class UserController extends Controller
*/
public function index(): void
{
API::response('json', User::getAll());
Http::response('json', User::getAll());
}

/**
Expand All @@ -28,6 +28,6 @@ public function index(): void
*/
public function show(int $id): void
{
API::response('json', User::findOne($id));
Http::response('json', User::findOne($id));
}
}
3 changes: 2 additions & 1 deletion app/Http/Controllers/CartController.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ public function index(): void
foreach (Session::get('cart') as $product_id)
\App\Models\Order::create([
'user_id' => $user_id,
'product_id' => $product_id
'product_id' => $product_id,
'quantity' => 1,
]);
Session::create('cart', []);
header("Refresh:0");
Expand Down
12 changes: 12 additions & 0 deletions codeception.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
paths:
tests: tests
output: tests/_output
data: tests/_data
support: tests/_support
envs: tests/_envs
actor_suffix: Tester
extensions:
enabled:
- Codeception\Extension\RunFailed
params:
- .env.testing
48 changes: 45 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,51 @@
"email": "pashalitovka@gmail.com"
}
],
"require": {},
"require-dev": {},
"scripts": {},
"require-dev": {
"codeception/codeception": "^4.1",
"codeception/module-asserts": "^2.0",
"codeception/module-db": "^2.0",
"codeception/module-phpbrowser": "^2.0",
"codeception/module-rest": "^2.0",
"vlucas/phpdotenv": "^5.4"
},
"scripts": {
"serve": [
"Composer\\Config::disableProcessTimeout",
"@php -S 0.0.0.0:8000"
],
"build": [
"@composer install --no-dev"
],
"test": [
"@php vendor/bin/codecept run --steps"
],
"test-boot": [
"@php vendor/bin/codecept bootstrap"
],
"test-generate-cest": [
"@php vendor/bin/codecept generate:cest"
],
"test-generate-cept": [
"@php vendor/bin/codecept generate:cept"
],
"test-generate-suite": [
"@php vendor/bin/codecept generate:suite"
],
"test-build": [
"@php vendor/bin/codecept build"
]
},
"scripts-descriptions": {
"serve": "Starts the server.",
"build": "Creates autoload file. Ignores dev dependencies.",
"test": "Runs all tests or of specific type.",
"test-boot": "Bootstraps the codeception.",
"test-generate-cest": "Generates test of CEST type.",
"test-generate-cept": "Generates test of CEPT type.",
"test-generate-suite": "Generates suite for codeception.",
"test-build": "Builds codeception classes for suites."
},
"extra": {},
"config": {
"optimize-autoloader": true,
Expand Down
Loading

0 comments on commit 569fee9

Please sign in to comment.