Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/Maestro-ESEO/Web-App into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Ortiix85 committed Jan 18, 2024
2 parents f55fda4 + 98907c6 commit d65274d
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 185 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
php-version: '7.4.33'
extensions: mbstring, sqlite3

- name: Install dependencies
Expand Down
3 changes: 1 addition & 2 deletions app/Http/Controllers/ProjectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
use App\Models\Task;
use App\Models\UserProject;
use App\Utils\AuthUtil;
use Illuminate\Contracts\View\View;

class ProjectController extends Controller {

public function show($id): View {
public function show($id) {
$user = AuthUtil::getAuthUser();
$project = Project::all()->find($id);

Expand Down
72 changes: 8 additions & 64 deletions app/Http/Controllers/TaskController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,57 +10,11 @@
use App\Utils\AuthUtil;
use App\Models\UserProject;

class TaskController extends Controller
{
class TaskController extends Controller {

public function store(Request $request): JsonResponse
{
$credentials = $request->validate([
'name' => 'string|required',
'description' => 'string|nullable',
'deadline' => 'date|nullable',
'priority' => 'int|required',
'project_id' => 'int|required'
]);

$task = new Task();
$task->name = $credentials['name'];
$task->description = $request->description ?? null;
$task->deadline = $request->deadline ?? null;
// The status of a new task is "To Do"
$task->status = 0;
$task->priority = $request->priority;
$task->project_id = $request->project_id;
// User admin of the project ?
$is_admin = app(ProjectController::class)->isAdmin(Project::find($request->project_id)->id, AuthUtil::getAuthUser()->id);
if ($is_admin != true) {
return response()->json([
'status' => 404,
'message' => 'Not authorized',
]);
}
$task->save();
return response()->json([
'status' => 200,
'message' => 'Task created successfully',
'data' => $task,
]);
}

public function index(): JsonResponse
{
$tasks = Task::all();
return response()->json([
'status' => 200,
'message' => 'Tasks found successfully',
'data' => $tasks,
]);
}

public function show($id)
{
public function show($id) {
$user = AuthUtil::getAuthUser();
$task = Task::all()->find($id);
$task = Task::find($id);
$project = Project::all()->find($task->project_id);

if (!$task or !$project or !UserProject::where("project_id", $project->id)->where("user_id", $user->id)->get()->count()) {
Expand All @@ -78,23 +32,13 @@ public function show($id)
}

public function getComments($id){
$comments = Comment::where("task_id", $id)->orderByDesc("created_at")->get();

return $comments;
return Comment::where("task_id", $id)->orderByDesc("created_at")->get();
}


public function delete(Request $request)
{
$request->validate([
'id' => 'required',
]);
$task = Task::findorfail($request->id);
$task->delete();
return response()->json([
'status' => 200,
'message' => 'Task deleted successfully',
]);
public function updateStatus($id, $status) {
$task = Task::find($id);
$task->status = $status;
$task->save();
}

public function update(Request $request, $id): string
Expand Down
3 changes: 3 additions & 0 deletions resources/views/app/task.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
use App\Http\Controllers\TaskController;
$deadline = strtotime($task->deadline);
$comments = app(TaskController::class)->getComments($task->id);
@endphp


<div class="w-full h-full flex flex-col justify-start py-14 px-16 gap-4">
<div class="w-full flex justify-start items-center">
<div class="flex flex-col justify-start items-start gap-2">
Expand Down
Empty file added tests/Feature/.gitkeep
Empty file.
21 changes: 0 additions & 21 deletions tests/Feature/ExampleTest.php

This file was deleted.

79 changes: 0 additions & 79 deletions tests/Feature/TaskControllerTest.php

This file was deleted.

18 changes: 0 additions & 18 deletions tests/Unit/ExampleTest.php

This file was deleted.

0 comments on commit d65274d

Please sign in to comment.