Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Theodorus Doni authored and Theodorus Doni committed Aug 9, 2023
1 parent 9e68caf commit 897741c
Show file tree
Hide file tree
Showing 158 changed files with 75,183 additions and 840 deletions.
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
}
12 changes: 12 additions & 0 deletions app/Enums/ConferenceFilterEnum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace App\Enums;

enum ConferenceFilterEnum: string {
case ALL = 'all';
case FUTURE = 'future';
case FAVORITE = 'favorites';
case DISMISSED = 'dismissed';
case OPENCFC = 'open_cfp';
case UNCLOSEDCFP = 'unclosed_cfp';
}
10 changes: 10 additions & 0 deletions app/Enums/ConferenceSortEnum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace App\Enums;

enum ConferenceSortEnum: string {
case ALPHA = 'alpha';
case DATE = 'date';
case OPENINGNEXT = 'opening_next';
case CLOSSINGNEXT = 'closing_next';
}
16 changes: 16 additions & 0 deletions app/Factory/Conferences/Filter/AllConferenceFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace App\Factory;

class AllConferenceFilter extends ConferenceFilter implements ConferenceApiFilter
{
public function filter()
{
return $this->model->undismissed()->approved();
}

public function filterApi()
{
return $this->model;
}
}
8 changes: 8 additions & 0 deletions app/Factory/Conferences/Filter/ConferenceApiFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace App\Factory;

interface ConferenceApiFilter
{
public function filterApi();
}
17 changes: 17 additions & 0 deletions app/Factory/Conferences/Filter/ConferenceFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace App\Factory;

use App\Models\Conference;

abstract class ConferenceFilter
{
protected $model;

public function __construct(Conference $model)
{
$this->model = $model;
}

public abstract function filter();
}
39 changes: 39 additions & 0 deletions app/Factory/Conferences/Filter/ConferenceFilterFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace App\Factory;

use App\Models\Conference;

class ConferenceFilterFactory
{
private $model;

public function __construct(Conference $model)
{
$this->model = $model;
}

public function getFilter($filterKey) : ConferenceFilter
{
return match($filterKey)
{
'favorites' => new FavoriteConferenceFilter($this->model),
'dismissed' => new DismissedConferenceFilter($this->model),
'open_cfp' => new OpenCfpConferenceFilter($this->model),
'unclosed_cfp' => new UnclosedCfpConferenceFilter($this->model),
'all' => new AllConferenceFilter($this->model),
default => new FutureConferenceFilter($this->model)
};
}

public function getFilterApi($filterKey) : ConferenceApiFilter
{
return match($filterKey)
{
'all' => new AllConferenceFilter($this->model),
'future' => new FutureConferenceFilter($this->model),
'open_cfp' => new OpenCfpConferenceFilter($this->model),
default => new UnclosedCfpConferenceFilter($this->model)
};
}
}
14 changes: 14 additions & 0 deletions app/Factory/Conferences/Filter/DismissedConferenceFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace App\Factory;

use Illuminate\Support\Facades\Auth;

class DismissedConferenceFilter extends ConferenceFilter
{
public function filter()
{
$user = Auth::user();
return $user->dismissedConferences()->approved();
}
}
14 changes: 14 additions & 0 deletions app/Factory/Conferences/Filter/FavoriteConferenceFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace App\Factory;

use Illuminate\Support\Facades\Auth;

class FavoriteConferenceFilter extends ConferenceFilter
{
public function filter()
{
$user = Auth::user();
return $user->favoritedConferences()->approved();
}
}
16 changes: 16 additions & 0 deletions app/Factory/Conferences/Filter/FutureConferenceFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace App\Factory;

class FutureConferenceFilter extends ConferenceFilter implements ConferenceApiFilter
{
public function filter()
{
return $this->model->undismissed()->future()->approved();
}

public function filterApi()
{
return $this->model->future();
}
}
16 changes: 16 additions & 0 deletions app/Factory/Conferences/Filter/OpenCfpConferenceFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace App\Factory;

class OpenCfpConferenceFilter extends ConferenceFilter implements ConferenceApiFilter
{
public function filter()
{
return $this->model->undismissed()->openCfp()->approved();
}

public function filterApi()
{
return $this->model->openCfp();
}
}
16 changes: 16 additions & 0 deletions app/Factory/Conferences/Filter/UnclosedCfpConferenceFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace App\Factory;

class UnclosedCfpConferenceFilter extends ConferenceFilter implements ConferenceApiFilter
{
public function filter()
{
return $this->model->undismissed()->unclosedCfp()->approved();
}

public function filterApi()
{
return $this->model->unclosedCfp();
}
}
11 changes: 11 additions & 0 deletions app/Factory/Talk/Filter/AcceptedTalkFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace App\Factory;

class AcceptedTalkFilter extends TalkFilter
{
public function filter()
{
return $this->getUserTalks()->accepted()->get();
}
}
11 changes: 11 additions & 0 deletions app/Factory/Talk/Filter/SubmittedTalkFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace App\Factory;

class SubmittedTalkFilter extends TalkFilter
{
public function filter()
{
return $this->getUserTalks()->submitted()->get();
}
}
14 changes: 14 additions & 0 deletions app/Factory/Talk/Filter/TalkFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace App\Factory;

abstract class TalkFilter
{
protected function getUserTalks()
{
$user = Auth::user();
return $user->talks();
}

public abstract function filter();
}
16 changes: 16 additions & 0 deletions app/Factory/Talk/Filter/TalkFilterFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace App\Factory;

class TalkFilterFactory
{
public function getFilter($filterKey) : TalkFilter
{
return match($filterKey)
{
'submitted' => new SubmittedTalkFilter(),
'accepted' => new AcceptedTalkFilter(),
default => new UserTalkFilter()
};
}
}
11 changes: 11 additions & 0 deletions app/Factory/Talk/Filter/UserTalkFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace App\Factory;

class UserTalkFilter extends TalkFilter
{
public function filter()
{
return $this->getUserTalks()->get();
}
}
47 changes: 47 additions & 0 deletions app/Handler/FileService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace App\Handler;

use App\Models\User;
use Intervention\Image\Facades\Image;
use Illuminate\Support\Facades\Storage;

class FileService
{
public function updateUserProfilePicture($profilePictureName, $inputPictureFile)
{
$generateProfilePicture = $this->createProfilePictureFile($inputPictureFile);

Storage::delete([
User::PROFILE_PICTURE_THUMB_PATH . $profilePictureName,
User::PROFILE_PICTURE_HIRES_PATH . $profilePictureName,
]);

Storage::put(User::PROFILE_PICTURE_THUMB_PATH .
$inputPictureFile->hashName(), $generateProfilePicture['thumbImage']->stream());
Storage::put(User::PROFILE_PICTURE_HIRES_PATH .
$inputPictureFile->hashName(), $generateProfilePicture['hiresImage']->stream());
}

private function createProfilePictureFile($fileImage)
{
$thumbImageSize = 250;
$hiresImageSize = 1250;

$thumbImage = Image::make($fileImage->getRealPath())
->fit($thumbImageSize, $thumbImageSize);

$hiresImage = Image::make($fileImage->getRealPath())
->fit($hiresImageSize, $hiresImageSize, function ($constraint) { $constraint->upsize(); });

return [
'hiresImage' => $hiresImage,
'thumbImage' => $thumbImage,
];
}

public function createUserDataJsonFile($name, $data)
{
Storage::disk('local')->put($name, json_encode($data));
}
}
Loading

0 comments on commit 897741c

Please sign in to comment.