-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Controller routes #89
Open
Kelisnor
wants to merge
31
commits into
master
Choose a base branch
from
ControllerRoutes
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
6f2c1b5
add simple models and migrations for course and assignment
8cf4beb
Merge branch 'master' of https://github.com/ready-app/ready
58109d3
Merge branch 'master' of https://github.com/ready-app/ready
c07c74c
add more things for models and migrations for course and assignment
545b382
fix a casting problem
0c65323
Merge branch 'master' of https://github.com/ready-app/ready
48a58bc
using = true to attempt generating created_at and update_at
0b4cdd3
Merge branch 'master' of https://github.com/ready-app/ready
1a1e1c1
delete manully creating of 'created_at' attribute for Assignment migr…
17c7944
adding relationships between Assignment and Course class, setting up …
0608652
delete unnecessary attribute in Assignment model
3ba87e5
Merge branch 'master' of https://github.com/ready-app/ready
91c0c8f
Merge branch 'AssignmentModelAndMigration'
b7d5f04
foreign key changes
90ebb8c
basic controller for Course
71c660b
adding some policies and gates
01bdcba
single change to routes
e73eccb
add assignment controller
32d1648
Merge branch 'master' into ControllerRoutes
cee750c
rewirte the update and destroy function so that it could only be chag…
c021397
delete the original CourseWork Controller
b89da19
minor changes to controllers
a56539b
delete unused functions
4e05200
rewrite functions with is_admin attribute
e3d8823
minor changes
e80233b
changes in policies
b94a8df
minor changes to delete unused functions
5028d01
change to the relations between Models
1307f0a
add validations
2203483
change to resource controller
c47f35d
minor changes
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use Illuminate\Http\Request; | ||
|
||
class AssignmentController extends Controller | ||
{ | ||
/** | ||
* Display a listing of the resource. | ||
* | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function index() | ||
{ | ||
// | ||
} | ||
|
||
|
||
public function create(Request $request){ | ||
if(Assignment::create($request->validated())){ | ||
return redirect()->route('assignment.index')->with('success', 'Assignment is successfully created'); | ||
} | ||
return redirect()->route('assignment.index')->with('error', 'Failed to create assignment'); | ||
} | ||
|
||
|
||
public function show(Assignment $assignment) | ||
{ | ||
return redirect()->route('assignment.index'); | ||
} | ||
|
||
|
||
|
||
public function update(Request $request,Assignment $assignment){ | ||
|
||
if($assigment->update($request->validated())){ | ||
return redirect()->route('assignment.index')->with('success', 'Assignment is successfully updated'); | ||
} | ||
return redirect()->route('assignment.index')->with('error', 'Failed to update assignment'); | ||
} | ||
|
||
|
||
|
||
public function destroy(Assignment $assignment){ | ||
$assignment -> delete(); | ||
|
||
return redirect()->route('assignment.index'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use Illuminate\Http\Request; | ||
|
||
class CourseController extends Controller | ||
{ | ||
|
||
/** | ||
* Display a listing of the resource. | ||
* | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function index() { | ||
// | ||
} | ||
|
||
public function create(Request $request) { | ||
if(Course::create($request->validated())){ | ||
return redirect()->route('course.index')->with('success', 'Course is successfully created'); | ||
} | ||
return redirect()->route('course.index')->with('error', 'Failed to create course'); | ||
} | ||
|
||
|
||
|
||
public function update(Request $request,Course $course) { | ||
if($course->update($request->validated())){ | ||
return redirect()->route('course.index')->with('success', 'Course is successfully updated'); | ||
} | ||
return redirect()->route('course.index')->with('error', 'Failed to update course'); | ||
} | ||
|
||
|
||
public function destroy(Course $course){ | ||
$course -> delete(); | ||
return redirect()->route('course.index'); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace App\Http\Requests; | ||
|
||
use Illuminate\Foundation\Http\FormRequest; | ||
|
||
class AssignmentRequest extends FormRequest | ||
{ | ||
/** | ||
* Determine if the user is authorized to make this request. | ||
* | ||
* @return bool | ||
*/ | ||
public function authorize() | ||
{ | ||
return true; | ||
} | ||
|
||
/** | ||
* Get the validation rules that apply to the request. | ||
* | ||
* @return array<string, mixed> | ||
*/ | ||
public function rules() | ||
{ | ||
return [ | ||
'name' => 'required|max:255', | ||
'due_at' => 'required', | ||
]; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace App\Http\Requests; | ||
|
||
use Illuminate\Foundation\Http\FormRequest; | ||
|
||
class CourseRequest extends FormRequest | ||
{ | ||
/** | ||
* Determine if the user is authorized to make this request. | ||
* | ||
* @return bool | ||
*/ | ||
public function authorize() | ||
{ | ||
return true; | ||
} | ||
|
||
/** | ||
* Get the validation rules that apply to the request. | ||
* | ||
* @return array<string, mixed> | ||
*/ | ||
public function rules() | ||
{ | ||
return [ | ||
'name' => 'required|max:255', | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
|
||
namespace App\Policies; | ||
|
||
use App\Models\Assignment; | ||
use App\Models\User; | ||
use App\Models\Course; | ||
use Illuminate\Auth\Access\HandlesAuthorization; | ||
use Illuminate\Auth\Access\Response; | ||
|
||
class AssignmentPolicy | ||
{ | ||
use HandlesAuthorization; | ||
|
||
|
||
/** | ||
* Determine whether the user can view any models. | ||
* | ||
* @param \App\Models\User $user | ||
* @return \Illuminate\Auth\Access\Response|bool | ||
*/ | ||
public function viewAny(User $user) | ||
{ | ||
return $user->is_admin | ||
? Response::allow() | ||
: Response::deny(); | ||
} | ||
|
||
/** | ||
* Determine whether the user can view the model. | ||
* | ||
* @param \App\Models\User $user | ||
* @param \App\Models\Assignment $assignment | ||
* @return \Illuminate\Auth\Access\Response|bool | ||
*/ | ||
public function view(User $user, Course $course, Assignment $assignment) | ||
{ | ||
return (($user->courses()->where('course_id', $course->id)->exist()) | ||
&&($user->assignments()->where('assignment_id',$assigment->id)->exist())) | ||
? Response::allow() | ||
: Response::deny(); | ||
} | ||
|
||
/** | ||
* Determine whether the user can create models. | ||
* | ||
* @param \App\Models\User $user | ||
* @return \Illuminate\Auth\Access\Response|bool | ||
*/ | ||
public function create() | ||
{ | ||
return true; | ||
} | ||
|
||
/** | ||
* Determine whether the user can update the model. | ||
* | ||
* @param \App\Models\User $user | ||
* @param \App\Models\Assignment $assignment | ||
* @return \Illuminate\Auth\Access\Response|bool | ||
*/ | ||
public function update(User $user, Course $course, Assignment $assignment) | ||
{ | ||
return (($user->courses()->where('course_id', $course->id)->exist()) | ||
&&($user->assignments()->where('assignment_id',$assigment->id)->exist())) | ||
? Response::allow() | ||
: Response::deny(); | ||
} | ||
|
||
/** | ||
* Determine whether the user can delete the model. | ||
* | ||
* @param \App\Models\User $user | ||
* @param \App\Models\Assignment $assignment | ||
* @return \Illuminate\Auth\Access\Response|bool | ||
*/ | ||
public function delete(User $user, Course $course, Assignment $assignment) | ||
{ | ||
return (($user->courses()->where('course_id', $course->id)->exist()) | ||
&&($user->assignments()->where('assignment_id',$assigment->id)->exist())) | ||
? Response::allow() | ||
: Response::deny(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?php | ||
|
||
namespace App\Policies; | ||
|
||
use App\Models\Course; | ||
use App\Models\User; | ||
use Illuminate\Auth\Access\HandlesAuthorization; | ||
|
||
class CoursePolicy | ||
{ | ||
use HandlesAuthorization; | ||
|
||
/** | ||
* Determine whether the user can view any models. | ||
* | ||
* @param \App\Models\User $user | ||
* @return \Illuminate\Auth\Access\Response|bool | ||
*/ | ||
public function viewAny(User $user) | ||
{ | ||
return $user->is_admin | ||
? Response::allow() | ||
: Response::deny(); | ||
} | ||
|
||
/** | ||
* Determine whether the user can view the model. | ||
* | ||
* @param \App\Models\User $user | ||
* @param \App\Models\Course $course | ||
* @return \Illuminate\Auth\Access\Response|bool | ||
*/ | ||
public function view(User $user, Course $course) | ||
{ | ||
return ($user->courses()->where('course_id', $course->id)->exist()) | ||
? Response::allow() | ||
: Response::deny(); | ||
} | ||
|
||
/** | ||
* Determine whether the user can create models. | ||
* | ||
* @param \App\Models\User $user | ||
* @return \Illuminate\Auth\Access\Response|bool | ||
*/ | ||
public function create(User $user) | ||
{ | ||
return $user->is_admin | ||
? Response::allow() | ||
: Response::deny(); | ||
} | ||
|
||
/** | ||
* Determine whether the user can update the model. | ||
* | ||
* @param \App\Models\User $user | ||
* @param \App\Models\Course $course | ||
* @return \Illuminate\Auth\Access\Response|bool | ||
*/ | ||
public function update(User $user, Course $course) | ||
{ | ||
return ($user->courses()->where('course_id', $course->id)->exist()) | ||
? Response::allow() | ||
: Response::deny(); | ||
} | ||
|
||
/** | ||
* Determine whether the user can delete the model. | ||
* | ||
* @param \App\Models\User $user | ||
* @param \App\Models\Course $course | ||
* @return \Illuminate\Auth\Access\Response|bool | ||
*/ | ||
public function delete(User $user, Course $course) | ||
{ | ||
return ($user->courses()->where('course_id', $course->id)->exist()) | ||
? Response::allow() | ||
: Response::deny(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All the comments I gave to AssignmentController apply here too