FIX: Cleaned up the Services, Models, Controllers
This commit is contained in:
parent
6bef75e520
commit
35a3953378
93
src/_ide_helper_models.php
Normal file
93
src/_ide_helper_models.php
Normal file
|
@ -0,0 +1,93 @@
|
|||
<?php
|
||||
|
||||
// @formatter:off
|
||||
/**
|
||||
* A helper file for your Eloquent Models
|
||||
* Copy the phpDocs from this file to the correct Model,
|
||||
* And remove them from this file, to prevent double declarations.
|
||||
*
|
||||
* @author Barry vd. Heuvel <barryvdh@gmail.com>
|
||||
*/
|
||||
|
||||
|
||||
namespace App\Models{
|
||||
/**
|
||||
* App\Models\Links
|
||||
*
|
||||
* @property int $id
|
||||
* @property string $platform
|
||||
* @property string $link
|
||||
* @property string $linktext
|
||||
* @property int $brandcolors
|
||||
* @property \Illuminate\Support\Carbon|null $created_at
|
||||
* @property \Illuminate\Support\Carbon|null $updated_at
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Links newModelQuery()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Links newQuery()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Links query()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Links whereBrandcolors($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Links whereCreatedAt($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Links whereId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Links whereLink($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Links whereLinktext($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Links wherePlatform($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Links whereUpdatedAt($value)
|
||||
* @mixin \Eloquent
|
||||
*/
|
||||
class Links extends \Eloquent {}
|
||||
}
|
||||
|
||||
namespace App\Models{
|
||||
/**
|
||||
* App\Models\User
|
||||
*
|
||||
* @property int $id
|
||||
* @property string $name
|
||||
* @property string $email
|
||||
* @property \Illuminate\Support\Carbon|null $email_verified_at
|
||||
* @property string $password
|
||||
* @property string|null $remember_token
|
||||
* @property \Illuminate\Support\Carbon|null $created_at
|
||||
* @property \Illuminate\Support\Carbon|null $updated_at
|
||||
* @property-read \Illuminate\Notifications\DatabaseNotificationCollection|\Illuminate\Notifications\DatabaseNotification[] $notifications
|
||||
* @property-read int|null $notifications_count
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection|\Laravel\Sanctum\PersonalAccessToken[] $tokens
|
||||
* @property-read int|null $tokens_count
|
||||
* @method static \Database\Factories\UserFactory factory(...$parameters)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|User newModelQuery()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|User newQuery()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|User query()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|User whereCreatedAt($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|User whereEmail($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|User whereEmailVerifiedAt($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|User whereId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|User whereName($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|User wherePassword($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|User whereRememberToken($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|User whereUpdatedAt($value)
|
||||
* @mixin \Eloquent
|
||||
*/
|
||||
class User extends \Eloquent {}
|
||||
}
|
||||
|
||||
namespace App\Models{
|
||||
/**
|
||||
* App\Models\Userdata
|
||||
*
|
||||
* @property int $id
|
||||
* @property string $username
|
||||
* @property string $theme
|
||||
* @property \Illuminate\Support\Carbon|null $created_at
|
||||
* @property \Illuminate\Support\Carbon|null $updated_at
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Userdata newModelQuery()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Userdata newQuery()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Userdata query()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Userdata whereCreatedAt($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Userdata whereId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Userdata whereTheme($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Userdata whereUpdatedAt($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Userdata whereUsername($value)
|
||||
* @mixin \Eloquent
|
||||
*/
|
||||
class Userdata extends \Eloquent {}
|
||||
}
|
||||
|
|
@ -2,18 +2,18 @@
|
|||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Http\Controllers\LoadDBController;
|
||||
use App\Http\Controllers\PreloadDBController;
|
||||
use Illuminate\Console\Command;
|
||||
use League\Flysystem\Config;
|
||||
|
||||
class loadAll extends Command
|
||||
class PreloadDBAll extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'loadDB:all';
|
||||
protected $signature = 'preloadDB:all';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
|
@ -39,10 +39,14 @@ class loadAll extends Command
|
|||
*/
|
||||
public function handle()
|
||||
{
|
||||
/*@todo
|
||||
error if keys are not in json
|
||||
*/
|
||||
$preloadDBController = new PreloadDBController();
|
||||
if (file_exists(env('JSON_FILE_PATH'))) {
|
||||
$config = json_decode(file_get_contents(env('JSON_FILE_PATH')), true);
|
||||
$loadDBController = new LoadDBController();
|
||||
$loadDBController->loadUserdata($config['username'], $config['theme']);
|
||||
$preloadDBController->setInitialUserData($config['username'], $config['theme']);
|
||||
$preloadDBController->setInitialLinks($config['links']);
|
||||
return Command::SUCCESS;
|
||||
} else {
|
||||
print('Error: JSON File does not exist at given location'."\n");
|
|
@ -1,22 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Services\LoadDBService;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class LoadDBController extends Controller
|
||||
{
|
||||
private $loadDBService;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->loadDBService = new LoadDBService();
|
||||
}
|
||||
|
||||
public function loadUserdata($username, $theme): void
|
||||
{
|
||||
$this->loadDBService->setusername($username);
|
||||
$this->loadDBService->settheme($theme);
|
||||
}
|
||||
}
|
56
src/app/Http/Controllers/PreloadDBController.php
Normal file
56
src/app/Http/Controllers/PreloadDBController.php
Normal file
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Services\Links\LinksService;
|
||||
use App\Services\LoadDBService;
|
||||
use App\Services\Userdatas\UserdatasService;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class PreloadDBController extends Controller
|
||||
{
|
||||
private $userdatasService;
|
||||
private $linksService;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->userdatasService = new UserdatasService();
|
||||
$this->linksService = new LinksService();
|
||||
}
|
||||
|
||||
public function setInitialUserData(string $username, string $theme)
|
||||
{
|
||||
$userdatas = $this->userdatasService->getAllUserdatas();
|
||||
$userdataslenght = count($userdatas);
|
||||
if ($userdataslenght > 0)
|
||||
{
|
||||
for ($userdata = 0; $userdata < $userdataslenght; $userdata++)
|
||||
{
|
||||
$this->userdatasService->deleteUserdataByID($userdatas[$userdata]['id']);
|
||||
}
|
||||
}
|
||||
$this->userdatasService->setNewUserdata($username, $theme);
|
||||
}
|
||||
|
||||
public function setInitialLinks(array $newlinks)
|
||||
{
|
||||
$links = $this->linksService->getAllLinks();
|
||||
$linkslenght = count($links);
|
||||
if ($linkslenght > 0)
|
||||
{
|
||||
for ($link = 0; $link < $linkslenght; $link++)
|
||||
{
|
||||
$this->linksService->deleteLinkById($links[$link]['id']);
|
||||
}
|
||||
}
|
||||
for ($link = 0; $link < count($newlinks); $link++)
|
||||
{
|
||||
$this->linksService->setNewLink(
|
||||
$newlinks[$link]['platform'],
|
||||
$newlinks[$link]['link'],
|
||||
$newlinks[$link]['linktext'],
|
||||
$newlinks[$link]['brandcolors']
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,25 +2,31 @@
|
|||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Services\Links\LinksService;
|
||||
use App\Services\LoadDBService;
|
||||
use App\Services\SocialTreePageService;
|
||||
use App\Services\Userdatas\UserdatasService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class SocialTreePageController extends Controller
|
||||
{
|
||||
private $socialTreePageService;
|
||||
private $linksService;
|
||||
private $userdatasService;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->socialTreePageService = new SocialTreePageService();
|
||||
$this->linksService = new LinksService();
|
||||
$this->userdatasService = new UserdatasService();
|
||||
}
|
||||
|
||||
public function index(): view
|
||||
{
|
||||
$links = $this->socialTreePageService->getLinks();
|
||||
$config = $this->socialTreePageService->getConfig()[0];
|
||||
$username = $config['username'];
|
||||
$theme = $config['theme'];
|
||||
$links = $this->linksService->getAllLinks();
|
||||
$userdata = $this->userdatasService->getFirstUserdata();
|
||||
$username = $userdata['username'];
|
||||
$theme = $userdata['theme'];
|
||||
return view('app',[
|
||||
'title' => $username . 's LinkTree',
|
||||
'username' => $username,
|
||||
|
|
49
src/app/Models/Links.php
Normal file
49
src/app/Models/Links.php
Normal file
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* App\Models\Links
|
||||
*
|
||||
* @property int $id
|
||||
* @property string $platform
|
||||
* @property string $link
|
||||
* @property string $linktext
|
||||
* @property int $brandcolors
|
||||
* @property \Illuminate\Support\Carbon|null $created_at
|
||||
* @property \Illuminate\Support\Carbon|null $updated_at
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Links newModelQuery()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Links newQuery()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Links query()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Links whereBrandcolors($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Links whereCreatedAt($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Links whereId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Links whereLink($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Links whereLinktext($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Links wherePlatform($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Links whereUpdatedAt($value)
|
||||
* @mixin \Eloquent
|
||||
*/
|
||||
class Links extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'links';
|
||||
|
||||
/**
|
||||
* The model's default values for attributes.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $attributes = [
|
||||
'platform' => 'null',
|
||||
'link' => 'null'
|
||||
];
|
||||
}
|
|
@ -8,6 +8,35 @@ use Illuminate\Foundation\Auth\User as Authenticatable;
|
|||
use Illuminate\Notifications\Notifiable;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
|
||||
/**
|
||||
* App\Models\User
|
||||
*
|
||||
* @property int $id
|
||||
* @property string $name
|
||||
* @property string $email
|
||||
* @property \Illuminate\Support\Carbon|null $email_verified_at
|
||||
* @property string $password
|
||||
* @property string|null $remember_token
|
||||
* @property \Illuminate\Support\Carbon|null $created_at
|
||||
* @property \Illuminate\Support\Carbon|null $updated_at
|
||||
* @property-read \Illuminate\Notifications\DatabaseNotificationCollection|\Illuminate\Notifications\DatabaseNotification[] $notifications
|
||||
* @property-read int|null $notifications_count
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection|\Laravel\Sanctum\PersonalAccessToken[] $tokens
|
||||
* @property-read int|null $tokens_count
|
||||
* @method static \Database\Factories\UserFactory factory(...$parameters)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|User newModelQuery()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|User newQuery()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|User query()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|User whereCreatedAt($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|User whereEmail($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|User whereEmailVerifiedAt($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|User whereId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|User whereName($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|User wherePassword($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|User whereRememberToken($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|User whereUpdatedAt($value)
|
||||
* @mixin \Eloquent
|
||||
*/
|
||||
class User extends Authenticatable
|
||||
{
|
||||
use HasApiTokens, HasFactory, Notifiable;
|
||||
|
|
34
src/app/Models/Userdata.php
Normal file
34
src/app/Models/Userdata.php
Normal file
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* App\Models\Userdata
|
||||
*
|
||||
* @property int $id
|
||||
* @property string $username
|
||||
* @property string $theme
|
||||
* @property \Illuminate\Support\Carbon|null $created_at
|
||||
* @property \Illuminate\Support\Carbon|null $updated_at
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Userdata newModelQuery()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Userdata newQuery()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Userdata query()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Userdata whereCreatedAt($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Userdata whereId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Userdata whereTheme($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Userdata whereUpdatedAt($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Userdata whereUsername($value)
|
||||
* @mixin \Eloquent
|
||||
*/
|
||||
class Userdata extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
protected $table = 'userdatas';
|
||||
protected $attributes = [
|
||||
'username'=> 'null',
|
||||
'theme'=> 'orange'
|
||||
];
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class links extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'links';
|
||||
|
||||
/**
|
||||
* The model's default values for attributes.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $attributes = [
|
||||
'plattform' => 'null',
|
||||
'link' => 'null'
|
||||
];
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class userdata extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
protected $table = 'userdatas';
|
||||
protected $attributes = [
|
||||
'username'=> 'null',
|
||||
'theme'=> 'orange'
|
||||
];
|
||||
}
|
23
src/app/Services/Links/LinksDataMutator.php
Normal file
23
src/app/Services/Links/LinksDataMutator.php
Normal file
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
namespace App\Services\Links;
|
||||
|
||||
use App\Models\Links;
|
||||
|
||||
class LinksDataMutator
|
||||
{
|
||||
public function deleteLinkById(int $id)
|
||||
{
|
||||
return Links::where('id', $id)->delete();
|
||||
}
|
||||
|
||||
public function setNewLink(string $platform, string $link, string $linktext, string $brandcolors)
|
||||
{
|
||||
$newlink = new Links();
|
||||
$newlink->platform = $platform;
|
||||
$newlink->link = $link;
|
||||
$newlink->linktext = $linktext;
|
||||
$newlink->brandcolors = $brandcolors;
|
||||
$newlink->save();
|
||||
}
|
||||
}
|
13
src/app/Services/Links/LinksDataProvider.php
Normal file
13
src/app/Services/Links/LinksDataProvider.php
Normal file
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
namespace App\Services\Links;
|
||||
|
||||
use App\Models\Links;
|
||||
|
||||
class LinksDataProvider
|
||||
{
|
||||
public function getAllLinks(): array
|
||||
{
|
||||
return links::all()->toArray();
|
||||
}
|
||||
}
|
31
src/app/Services/Links/LinksService.php
Normal file
31
src/app/Services/Links/LinksService.php
Normal file
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
namespace App\Services\Links;
|
||||
|
||||
class LinksService
|
||||
{
|
||||
private $linksDataProvider;
|
||||
private $linksDataMutator;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->linksDataProvider = new LinksDataProvider();
|
||||
$this->linksDataMutator = new LinksDataMutator();
|
||||
}
|
||||
|
||||
public function getAllLinks(): array
|
||||
{
|
||||
return $this->linksDataProvider->getAllLinks();
|
||||
}
|
||||
|
||||
public function deleteLinkById(int $id)
|
||||
{
|
||||
return $this->linksDataMutator->deleteLinkById($id);
|
||||
}
|
||||
|
||||
public function setNewLink(string $platform, string $link, string $linktext, string $brandcolors)
|
||||
{
|
||||
$this->linksDataMutator->setNewLink($platform, $link, $linktext, $brandcolors);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,46 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Models\userdata;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class LoadDBDataMutator
|
||||
{
|
||||
public function setusername($username): void
|
||||
{
|
||||
$ud = new userdata;
|
||||
$ud->username = $username;
|
||||
$ud->save();
|
||||
}
|
||||
|
||||
public function getAll(): array
|
||||
{
|
||||
return userdata::all()->toArray();
|
||||
}
|
||||
|
||||
public function deleteByID($id): void
|
||||
{
|
||||
userdata::where('id', $id)->delete();
|
||||
}
|
||||
|
||||
public function editUsernameByID($id, $username): void
|
||||
{
|
||||
userdata::where('id', $id)->update([
|
||||
'username' => $username,
|
||||
]);
|
||||
}
|
||||
public function settheme(string $theme): void
|
||||
{
|
||||
$ud = new userdata;
|
||||
$ud->theme = $theme;
|
||||
$ud->save();
|
||||
}
|
||||
public function editThemeByID(int $id, string $theme): void
|
||||
{
|
||||
userdata::where('id', $id)->update([
|
||||
'theme' => $theme,
|
||||
]);
|
||||
}
|
||||
}
|
|
@ -1,52 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
class LoadDBService
|
||||
{
|
||||
private $loadDBDataMutator;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->loadDBDataMutator = new LoadDBDataMutator();
|
||||
}
|
||||
|
||||
public function setusername($username): void
|
||||
{
|
||||
$this->reduceEntriesToOne($this->loadDBDataMutator->getAll());
|
||||
$userdata = $this->loadDBDataMutator->getAll();
|
||||
if (count($userdata) == 1)
|
||||
{
|
||||
$this->loadDBDataMutator->editUsernameByID($userdata[0]['id'], $username);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->loadDBDataMutator->setusername($username);
|
||||
}
|
||||
}
|
||||
public function settheme($theme): void
|
||||
{
|
||||
$this->reduceEntriesToOne($this->loadDBDataMutator->getAll());
|
||||
$userdata = $this->loadDBDataMutator->getAll();
|
||||
if (count($userdata) == 1)
|
||||
{
|
||||
$this->loadDBDataMutator->editThemeByID($userdata[0]['id'], $theme);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->loadDBDataMutator->settheme($theme);
|
||||
}
|
||||
}
|
||||
|
||||
private function reduceEntriesToOne($userdata): void
|
||||
{
|
||||
if (count($userdata)> 1)
|
||||
{
|
||||
for ($entries = 1; $entries < count($userdata); $entries++)
|
||||
{
|
||||
$this->loadDBDataMutator->deleteByID($userdata[$entries]['id']);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\links;
|
||||
use App\Models\userdata;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class SocialTreePageDataProvider
|
||||
{
|
||||
|
||||
public function getLinks(): array
|
||||
{
|
||||
return links::all()->toArray();
|
||||
}
|
||||
|
||||
public function getConfig(): array
|
||||
{
|
||||
return userdata::all()->toArray();
|
||||
}
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
class SocialTreePageService
|
||||
{
|
||||
private $socialTreePageDataProvider;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->socialTreePageDataProvider = new SocialTreePageDataProvider();
|
||||
}
|
||||
|
||||
public function getLinks(): array
|
||||
{
|
||||
return $this->socialTreePageDataProvider->getLinks();
|
||||
}
|
||||
|
||||
public function getConfig(): array
|
||||
{
|
||||
return $this->socialTreePageDataProvider->getConfig();
|
||||
}
|
||||
|
||||
}
|
21
src/app/Services/Userdatas/UserdataDataMutator.php
Normal file
21
src/app/Services/Userdatas/UserdataDataMutator.php
Normal file
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
namespace App\Services\Userdatas;
|
||||
|
||||
use App\Models\Userdata;
|
||||
|
||||
class UserdataDataMutator
|
||||
{
|
||||
public function setNewUserdata(string $username, string $theme): bool
|
||||
{
|
||||
$userdata = new Userdata();
|
||||
$userdata->username = $username;
|
||||
$userdata->theme = $theme;
|
||||
return $userdata->save();
|
||||
}
|
||||
|
||||
public function deleteUserdataByID(int $id)
|
||||
{
|
||||
return Userdata::where('id', $id)->delete();
|
||||
}
|
||||
}
|
14
src/app/Services/Userdatas/UserdatasDataProvider.php
Normal file
14
src/app/Services/Userdatas/UserdatasDataProvider.php
Normal file
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
namespace App\Services\Userdatas;
|
||||
|
||||
use App\Models\Userdata;
|
||||
|
||||
class UserdatasDataProvider
|
||||
{
|
||||
public function getAllUserdatas(): array
|
||||
{
|
||||
return Userdata::all()->toArray();
|
||||
}
|
||||
|
||||
}
|
41
src/app/Services/Userdatas/UserdatasService.php
Normal file
41
src/app/Services/Userdatas/UserdatasService.php
Normal file
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
namespace App\Services\Userdatas;
|
||||
|
||||
class UserdatasService
|
||||
{
|
||||
private $userdatasDataProvider;
|
||||
private $userdatasDataMutator;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->userdatasDataProvider = new UserdatasDataProvider();
|
||||
$this->userdatasDataMutator = new UserdataDataMutator();
|
||||
}
|
||||
|
||||
public function getFirstUserdata()
|
||||
{
|
||||
return $this->userdatasDataProvider->getAllUserdatas()[0];
|
||||
}
|
||||
|
||||
public function getUserdatasLenght(): int
|
||||
{
|
||||
return count($this->userdatasDataProvider->getAllUserdatas());
|
||||
}
|
||||
|
||||
public function setNewUserdata(string $username, string $theme)
|
||||
{
|
||||
return $this->userdatasDataMutator->setNewUserdata($username, $theme);
|
||||
}
|
||||
|
||||
public function deleteUserdataByID(int $id)
|
||||
{
|
||||
$this->userdatasDataMutator->deleteUserdataByID($id);
|
||||
}
|
||||
|
||||
public function getAllUserdatas():array
|
||||
{
|
||||
return $this->userdatasDataProvider->getAllUserdatas();
|
||||
}
|
||||
|
||||
}
|
8
src/app/Services/Users/LoadUsersService.php
Normal file
8
src/app/Services/Users/LoadUsersService.php
Normal file
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace App\Services\Users;
|
||||
|
||||
class LoadUsersService
|
||||
{
|
||||
|
||||
}
|
|
@ -14,6 +14,7 @@
|
|||
"ext-json": "*"
|
||||
},
|
||||
"require-dev": {
|
||||
"barryvdh/laravel-ide-helper": "^2.10",
|
||||
"facade/ignition": "^2.5",
|
||||
"fakerphp/faker": "^1.9.1",
|
||||
"laravel/sail": "^1.0.1",
|
||||
|
|
1449
src/composer.lock
generated
1449
src/composer.lock
generated
File diff suppressed because it is too large
Load diff
Reference in a new issue