Skip to content

Commit

Permalink
TDD updated
Browse files Browse the repository at this point in the history
  • Loading branch information
arashactive committed May 24, 2023
1 parent 774fe92 commit 9fda069
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public function destroy($term_id, $session_id)
*/
public function order($from, $move)
{

$this->authorize('term.update');
$this->service->order($from, $move);
return $this->service->redirectBack();
Expand Down
21 changes: 13 additions & 8 deletions app/Http/Controllers/Front/CourseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,28 @@
namespace App\Http\Controllers\Front;

use App\Http\Controllers\Controller;
use App\Models\Course;
use App\Models\Plan;
use App\Services\Front\CourseServices;
use App\Services\Front\HomeServices;

class CourseController extends Controller
{
protected $homeService;
protected $courseService;

public function __construct(HomeServices $homeService, CourseServices $courseService)
{
$this->homeService = $homeService;
$this->courseService = $courseService;
}

/**
* Display a listing of the Courses.
*
* @return \Illuminate\Contracts\View\View|\Illuminate\Contracts\View\Factory
*/
public function courses(HomeServices $courseServices)
public function courses()
{
$homeCompactReturn = $courseServices->homeIndex();
$homeCompactReturn = $this->homeService->homeIndex();
return view('contents.front.courses.index', $homeCompactReturn);
}

Expand All @@ -30,9 +35,9 @@ public function courses(HomeServices $courseServices)
* @param int $id
* @return \Illuminate\Contracts\View\View|\Illuminate\Contracts\View\Factory
*/
public function course($id, CourseServices $courseServices)
public function course($id)
{
$courseCompactData = $courseServices->getCourseInfo($id);
$courseCompactData = $this->courseService->getCourseInfo($id);

return view('contents.front.courses.course', $courseCompactData);
}
Expand All @@ -44,10 +49,10 @@ public function course($id, CourseServices $courseServices)
*
* @return \Illuminate\Contracts\View\View|\Illuminate\Contracts\View\Factory
*/
public function plans(CourseServices $courseServices)
public function plans()
{

$plans = $courseServices->getPlanPageInfo();
$plans = $this->courseService->getPlanPageInfo();
return view(
'contents.front.plans.index',
$plans
Expand Down
4 changes: 3 additions & 1 deletion app/Http/Controllers/SessionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
use App\Http\Requests\SessionRequest;
use App\Models\Session;
use App\Models\Sessionable;

use App\Traits\Sequence;

class SessionController extends Controller
{
use Sequence;

/**
* Display a listing of the resource.
*
Expand Down
1 change: 0 additions & 1 deletion app/Repositories/Contracts/PlanInterfaceRepository.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

namespace App\Repositories\Contracts;

interface PlanInterfaceRepository
Expand Down
11 changes: 6 additions & 5 deletions app/Services/Front/CourseServices.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@
namespace App\Services\Front;

use App\Repositories\Contracts\CourseInterfaceRepository;
use App\Repositories\Contracts\PlanInterfaceRepository;
use App\Repositories\Models\PlanRepository;

class CourseServices
{
private $courseRepository;
private $planRepository;
protected $courseRepository;
protected $planRepository;

public function __construct(
CourseInterfaceRepository $courseRepository,
PlanInterfaceRepository $planRepository
PlanRepository $planRepository
) {
$this->planRepository = $planRepository;

$this->courseRepository = $courseRepository;
$this->planRepository = $planRepository;
}


Expand Down
23 changes: 23 additions & 0 deletions app/Traits/Sequence.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php


namespace App\Traits;

trait Sequence
{

/** @phpstan-ignore-next-line */
public function changeOrder($from, $to): bool
{

$fromOrder = $from->order;
$from->order = $to->order;
$to->order = $fromOrder;

$from->save();
$to->save();


return true;
}
}
9 changes: 5 additions & 4 deletions tests/Feature/TDD/sessionAddTermTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ protected function setUp(): void
*/
public function test_add_session_to_term()
{
$this->withoutExceptionHandling();
$this->signIn();
$this->create([], 'term.store');
$this->create([], 'session.store');
Expand All @@ -35,12 +36,12 @@ public function test_add_session_to_term()
$session = Session::first();

$response = $this->get(route('addSessionToTerm',[
'term_id' => $term->id,
'session_id' => $session->id
'term' => $term->id,
'session' => $session->id
]));

$response->assertRedirect();

$response->assertRedirect(route('term.show', $term->id));
$this->followRedirects($response)->assertSee('session sync with this term');
}


Expand Down

0 comments on commit 9fda069

Please sign in to comment.