Skip to content

Commit

Permalink
Merge pull request #13 from yepwoo/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
mahmoodahmad100 authored Oct 1, 2021
2 parents 06c28f2 + 65ed079 commit 899b788
Show file tree
Hide file tree
Showing 23 changed files with 352 additions and 49 deletions.
8 changes: 8 additions & 0 deletions src/Commands/Install.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,13 @@ public function handle()
$this->info('Publishing configuration...');
if(!folder_exist('base_path', 'Core')) {
$this->publishCoreFolderAndFiles();
$this->publishViewsFoldersAndFiles();
$this->info('Published configuration');
} else {
if($this->shouldOverwriteFolders()) {
$this->info('Overwriting configuration file....');
$this->publishCoreFolderAndFiles();
$this->publishViewsFoldersAndFiles();
} else {
$this->info('Existing core was not overwritten');
}
Expand All @@ -69,4 +71,10 @@ private function shouldOverwriteFolders(): bool
false
);
}

private function publishViewsFoldersAndFiles() {
if(BaseHelpers::createViewsFolders() == 'success') {
BaseHelpers::createViewsFiles();
};
}
}
25 changes: 6 additions & 19 deletions src/Core/Base/ApiController.stub
Original file line number Diff line number Diff line change
Expand Up @@ -75,51 +75,38 @@ class Controller extends \App\Http\Controllers\Controller
/**
* Display the specified resource.
*
* @param string $id
* @param int $id
* @return \Illuminate\Http\JsonResponse
*/
public function show($id)
{
return $this->sendResponse(new $this->resource($this->getModel($id)));
return $this->sendResponse(new $this->resource($this->model->find($id)));
}

/**
* Update a resource in storage.
*
* @param string $id
* @param int $id
* @return \Illuminate\Http\JsonResponse
*/
public function update($id)
{
$model = $this->getModel($id);
$model = $this->model->find($id);
$model->update($this->request->all());
return $this->sendResponse(new $this->resource($model), 'successfully updated.');
}

/**
* Remove the specified resource from storage.
*
* @param string $id
* @param int $id
* @return \Illuminate\Http\JsonResponse
* @throws \Exception
*/
public function destroy($id)
{
$model = $this->getModel($id);
$model = $this->model->find($id);
$model->delete();
return $this->sendResponse([], 'successfully deleted.');
}

/**
* get the model by specific column
*
* @codeCoverageIgnore
* @param string $id
* @param string $column
* @return Model
*/
protected function getModel($id, $column = 'uuid')
{
return $this->model->where($column, $id)->first();
}
}
3 changes: 1 addition & 2 deletions src/Core/Base/Base.stub
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ namespace Core\Base\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Core\Base\Traits\Model\Uuid;

class Base extends Model
{
use HasFactory, Uuid;
use HasFactory;

/**
* The attributes that aren't mass assignable.
Expand Down
11 changes: 11 additions & 0 deletions src/Core/Base/unit_template/_form.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<form>
<div class="form-group has-feedback">
<label>Name <span class="text-danger">*</span></label>
<input class="form-control" name="name" required>
<div class="invalid-feedback has-error">
<div>name is required</div>
</div>
</div>

<button type="submit" class="btn btn-primary">Submit</button>
</form>
30 changes: 30 additions & 0 deletions src/Core/Base/unit_template/create.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
@extends($global['base']['namespace'] . 'layouts.master')

@section('content')
<div class="section-header">
<h1>
New Unit
<a class="btn btn-success" href="{{ route($global['module']['routes']['index']) }}">
Go To All Units
</a>
</h1>
</div>

<div class="section-body">
<h2 class="section-title">New Unit</h2>
<p class="section-lead">create new unit</p>

<div class="row">
<div class="col-12">
<div class="card">
<div class="card-header">
<h4>The Form</h4>
</div>
<div class="card-body">
@include($global['module']['path'] .'._form')
</div>
</div>
</div>
</div>
</div>
@endsection
30 changes: 30 additions & 0 deletions src/Core/Base/unit_template/edit.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
@extends($global['base']['namespace'] . 'layouts.master')

@section('content')
<div class="section-header">
<h1>
Edit Unit
<a class="btn btn-success" href="{{ route($global['module']['routes']['index']) }}">
Go To All Units
</a>
</h1>
</div>

<div class="section-body">
<h2 class="section-title">Edit Unit</h2>
<p class="section-lead">edit the unit</p>

<div class="row">
<div class="col-12">
<div class="card">
<div class="card-header">
<h4>The Form</h4>
</div>
<div class="card-body">
@include($global['module']['path'] .'._form')
</div>
</div>
</div>
</div>
</div>
@endsection
58 changes: 58 additions & 0 deletions src/Core/Base/unit_template/index.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
@extends($global['base']['namespace'] . 'layouts.master')

@section('content')
<div class="section-header">
<h1>
All Units
<a class="btn btn-success" href="{{ route($global['module']['routes']['create']) }}">
Create New Unit
</a>
</h1>
</div>

<div class="section-body">
<h2 class="section-title">All Units</h2>
<p class="section-lead">the list of the units</p>

<div class="row">
<div class="col-12">
<div class="card">
<div class="card-header">
<h4>The List</h4>
</div>
<div class="card-body p-0">
<div class="table-responsive">
<table class="table table-striped table-md">
<caption class="d-none">units list</caption>
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Name</th>
<th scope="col">Action</th>
</tr>
</thead>
<tbody>
<tr>
<td>100</td>
<td>Hello World!</td>
<td>
<a class="btn btn-info" href="#">
<i class="fas fa-search" aria-hidden="true"></i>
</a>
<a class="btn btn-primary" href="#">
<i class="fas fa-pencil-alt" aria-hidden="true"></i>
</a>
<a class="btn btn-danger" href="#">
<i class="fas fa-trash-alt" aria-hidden="true"></i>
</a>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
@endsection
35 changes: 35 additions & 0 deletions src/Core/Base/unit_template/show.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@extends($global['base']['namespace'] . 'layouts.master')

@section('content')
<div class="section-header">
<h1>
Unit Details
<a class="btn btn-success" href="{{ route($global['module']['routes']['index']) }}">
Go To All Units
</a>
</h1>
</div>

<div class="section-body">
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-header">
<h4 class="card-title">Unit Info</h4>
</div>
<div class="card-body">
<p class="mb-1">
<strong class="text-capitalize">#</strong> <br>
100
</p>

<p class="mb-1">
<strong class="text-capitalize">Name</strong> <br>
Hello World!
</p>
</div>
</div>
</div>
</div>
</div>
@endsection
27 changes: 27 additions & 0 deletions src/Core/Base/views/layouts/master.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta content="width=device-width, initial-scale=1, maximum-scale=1" name="viewport">
<title>Home</title>

@yield('css')
</head>

<body>
<div class="wrapper">
{{-- NAVBAR --}}
@include($global['base']['namespace'] . 'layouts.partials._navbar')

{{-- SIDEBAR --}}
@include($global['base']['namespace'] . 'layouts.partials._sidebar')

{{-- PAGE CONTENT --}}
<div class="content">
@yield('content')
</div>
</div>

@yield('js')
</body>
</html>
3 changes: 3 additions & 0 deletions src/Core/Base/views/layouts/partials/_navbar.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<nav>
NAVBAR
</nav>
3 changes: 3 additions & 0 deletions src/Core/Base/views/layouts/partials/_sidebar.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<aside>
SIDEBAR
</aside>
19 changes: 13 additions & 6 deletions src/Core/Module/Unit.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
{
"attributes": {
"phone": {
"type": "float:8,2",
"mod": "unique|after:name"
"name": {
"type": "string"
},
"email": {
"type": "enum:2,3,4",
"mod": "unique|after:name"
"description": {
"type": "text",
"mod": "nullable"
},
"priority": {
"type": "enum:low,medium,high",
"mod": "nullable|default:medium"
},
"is_done": {
"type": "boolean",
"mod": "default:false"
}
},
"relations": {
Expand Down
1 change: 0 additions & 1 deletion src/Core/Module/UnitFactory.stub
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class #UNIT_NAME#Factory extends Factory
public function definition()
{
return [
'name' => $this->faker->name,
#CONTENT#
];
}
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Module/UnitResource.stub
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class #UNIT_NAME#Resource extends Resource
public function toArray($request)
{
return [
'id' => $this->uuid,
'id' => $this->id,
#CONTENT#
$this->mergeWhen($request->route()->getName() == 'api.v1.#UNIT_NAME_PLURAL_LOWER_CASE#.show', [

Expand Down
14 changes: 7 additions & 7 deletions src/Core/Module/UnitTest.stub
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ class #UNIT_NAME#Test extends TestCase
}

/**
* get the uuid
* get the id
*
* @return string
* @return int
*/
protected function getUuid()
protected function getId()
{
return $this->getNewEntry()->uuid;
return $this->getNewEntry()->id;
}

/**
Expand Down Expand Up @@ -104,7 +104,7 @@ class #UNIT_NAME#Test extends TestCase
*/
public function testItShouldGetSpecifiedResource()
{
$this->json('GET', $this->base_url . $this->getUuid(), [], $this->getHeaders())
$this->json('GET', $this->base_url . $this->getId(), [], $this->getHeaders())
->assertStatus(200)
->assertJsonStructure($this->json);
}
Expand All @@ -116,7 +116,7 @@ class #UNIT_NAME#Test extends TestCase
*/
public function testItShouldUpdateSpecifiedResource()
{
$this->json('PUT', $this->base_url . $this->getUuid(), $this->data, $this->getHeaders())
$this->json('PUT', $this->base_url . $this->getId(), $this->data, $this->getHeaders())
->assertStatus(200)
->assertJsonStructure($this->json);
}
Expand All @@ -129,7 +129,7 @@ class #UNIT_NAME#Test extends TestCase
public function testItShouldRemoveSpecifiedResource()
{
$this->json['data'] = [];
$this->json('DELETE', $this->base_url . $this->getUuid(), [], $this->getHeaders())
$this->json('DELETE', $this->base_url . $this->getId(), [], $this->getHeaders())
->assertStatus(200)
->assertJsonStructure($this->json);
}
Expand Down
Loading

0 comments on commit 899b788

Please sign in to comment.