diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml new file mode 100644 index 000000000..bd41c414c --- /dev/null +++ b/.github/workflows/docker-image.yml @@ -0,0 +1,20 @@ +name: Docker Image CI + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +jobs: + + deploy: + name: Deploy + runs-on: ubuntu-latest + + steps: + - name: Deploy to production + uses: johnbeynon/render-deploy-action@v0.0.8 + with: + service-id: ${{ secrets.SERVICE_ID }} + api-key: ${{ secrets.RENDER_API_KEY }} diff --git a/Makefile b/Makefile new file mode 100644 index 000000000..19a443a70 --- /dev/null +++ b/Makefile @@ -0,0 +1,8 @@ +start: + docker run -p 80:8181 peace-for-hair + +build: + docker build -t peace-for-hair . + +stop: + docker stop php-laravel-docker \ No newline at end of file diff --git a/app/Clients.php b/app/Clients.php new file mode 100644 index 000000000..161c8ec63 --- /dev/null +++ b/app/Clients.php @@ -0,0 +1,29 @@ +string('first_name'); + $table->string('second_name'); + $table->string('third_name'); + $table->enum('sex', ['male', 'female']); + */ + protected $fillable = [ + 'first_name', + 'second_name', + 'third_name', + 'sex', + 'has_discount', + ]; + + public function works() + { + return $this->hasMany(Works::class); + } +} diff --git a/app/Haircuts.php b/app/Haircuts.php new file mode 100644 index 000000000..9a5d47003 --- /dev/null +++ b/app/Haircuts.php @@ -0,0 +1,22 @@ +string('name'); + $table->float('cost'); + $table->enum('sex', ['male', 'female']); + */ + protected $fillable = [ + 'name', + 'cost', + 'sex', + ]; +} diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index 7cbc2c3f0..7648b1c12 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -2,20 +2,13 @@ namespace App\Http\Controllers; +use App\Clients; +use App\Haircuts; +use App\Works; use Illuminate\Http\Request; class HomeController extends Controller { - /** - * Create a new controller instance. - * - * @return void - */ - public function __construct() - { - $this->middleware('auth'); - } - /** * Show the application dashboard. * @@ -23,6 +16,90 @@ public function __construct() */ public function index() { - return view('home'); + $this->createCL(); + + return view('welcome', [ + 'haircuts' => Haircuts::all()->toArray() ?? [], + 'works' => Works::with('client')->with('haircut')->get()->toArray() ?? [], + 'clients' => Clients::all()->map(function ($client) { + $client['haircut_count'] = Works::where('client_id', $client->id)->count(); + return $client; + })->toArray(), + 'maleRegularClients' => Clients::where('sex', 'male')->where('has_discount', true)->get() + ]); + } + + public function create() + { + + $hair = Haircuts::firstWhere('id', request()->get('haircut_id')); + + $client = Clients::where([ + ['first_name', request()->get('first_name')], + ['second_name', request()->get('second_name')], + ['third_name', request()->get('third_name')], + ['sex', $hair->sex] + ])->first(); + + if (!$client) { + + + $client = Clients::create([ + 'first_name' => request()->get('first_name'), + 'second_name' => request()->get('second_name'), + 'third_name' => request()->get('third_name'), + 'sex' => $hair->sex, + ]); + + $client->save(); + } + + $work = Works::create([ + 'haircut_id' => request()->get('haircut_id'), + 'cost' => $client->has_discount ? $hair->cost * 0.97 : $hair->cost, + 'client_id' => $client->id, + ]); + + $work->save(); + + + $count = Works::where('client_id', $client->id)->get()->count(); + + if ($count > 3) { + $client->has_discount = true; + + $client->save(); + } + + return redirect()->route('home'); + } + + public function createCL() + { + if(Haircuts::all()->count() > 0) return; + + \App\Haircuts::create([ + 'cost' => 100, + 'name' => 'Male superman haircut', + 'sex' => 'male', + ]); + + \App\Haircuts::create([ + 'cost' => 150, + 'name' => 'Male superwoman haircut', + 'sex' => 'female', + ]); + + \App\Haircuts::create([ + 'cost' => 10, + 'name' => 'Easy cut for male', + 'sex' => 'male', + ]); + + \App\Haircuts::create([ + 'cost' => 3, + 'name' => 'Easy cut for female', + 'sex' => 'female', + ]); } } diff --git a/app/Works.php b/app/Works.php new file mode 100644 index 000000000..9bfc89583 --- /dev/null +++ b/app/Works.php @@ -0,0 +1,33 @@ +foreignId('haircut_id')->references('id')->on('haircuts'); + * $table->foreignId('client_id')->references('id')->on('clients'); + * + * @var array + */ + protected $fillable = [ + 'haircut_id', + 'client_id', + 'cost', + ]; + + public function client() + { + return $this->belongsTo(Clients::class); + } + + public function haircut() + { + return $this->belongsTo(Haircuts::class); + } +} diff --git a/database/migrations/2024_11_17_182831_create_clients_table.php b/database/migrations/2024_11_17_182831_create_clients_table.php new file mode 100644 index 000000000..2f95db763 --- /dev/null +++ b/database/migrations/2024_11_17_182831_create_clients_table.php @@ -0,0 +1,32 @@ +id(); + $table->string('first_name'); + $table->string('second_name'); + $table->string('third_name'); + $table->enum('sex', ['male', 'female']); + $table->boolean('has_discount')->default(false); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('clients'); + } +}; diff --git a/database/migrations/2024_11_17_183052_create_haircuts_table.php b/database/migrations/2024_11_17_183052_create_haircuts_table.php new file mode 100644 index 000000000..a8734fb64 --- /dev/null +++ b/database/migrations/2024_11_17_183052_create_haircuts_table.php @@ -0,0 +1,31 @@ +id(); + $table->string('name'); + $table->float('cost'); + $table->enum('sex', ['male', 'female']); + + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('haircuts'); + } +}; diff --git a/database/migrations/2024_11_17_183060_create_works_table.php b/database/migrations/2024_11_17_183060_create_works_table.php new file mode 100644 index 000000000..d7596b704 --- /dev/null +++ b/database/migrations/2024_11_17_183060_create_works_table.php @@ -0,0 +1,30 @@ +id(); + $table->float('cost'); + $table->foreignId('haircut_id')->references('id')->on('haircuts'); + $table->foreignId('client_id')->references('id')->on('clients'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('works'); + } +}; diff --git a/resources/views/welcome.blade.php b/resources/views/welcome.blade.php index af1c02a70..55a78212b 100644 --- a/resources/views/welcome.blade.php +++ b/resources/views/welcome.blade.php @@ -1,99 +1,99 @@ - - - - - Laravel - - - - - - - - -
- @if (Route::has('login')) -