-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into 328-be-refactor-stude…
…ntlanguageupdate-endpoint # Conflicts: # routes/api/v1.php
- Loading branch information
Showing
14 changed files
with
172 additions
and
347 deletions.
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
62 changes: 17 additions & 45 deletions
62
app/Http/Controllers/api/Student/UpdateStudentImageController.php
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 |
---|---|---|
@@ -1,63 +1,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Http\Controllers\api\Student; | ||
|
||
use Illuminate\Http\{ | ||
JsonResponse, | ||
Request | ||
}; | ||
use Illuminate\Support\Facades\{ | ||
Log | ||
}; | ||
|
||
use App\Models\Student; | ||
use Illuminate\Http\JsonResponse; | ||
use App\Http\Controllers\Controller; | ||
use App\Exceptions\StudentNotFoundException; | ||
use App\Service\Student\UpdateStudentImageService; | ||
use Illuminate\Support\Facades\Storage; | ||
use App\Http\Requests\UpdateImageStudentRequest; | ||
|
||
|
||
class UpdateStudentImageController extends Controller | ||
{ | ||
private UpdateStudentImageService $updateStudentImageService; | ||
private string $photo_infix = '.profile_photo.'; | ||
private string $photos_path = 'public/photos/'; | ||
|
||
public function __construct(UpdateStudentImageService $updateStudentImageService) | ||
public function __invoke(UpdateImageStudentRequest $request, Student $student): JsonResponse | ||
{ | ||
$this->updateStudentImageService = $updateStudentImageService; | ||
} | ||
|
||
public function __invoke(UpdateImageStudentRequest $request, string $studentID): JsonResponse | ||
{ | ||
|
||
try { | ||
$file = $request->file('photo'); | ||
|
||
$file = $request->file('photo'); | ||
$filename = $this->updateStudentImageService->createImageNameByStudentIDAndFileHash($studentID, $file->hashName()); | ||
$this->updateStudentImageService->storePhotoInStorageByFileName($file, $filename); | ||
$this->updateStudentImageService->updateStudentImagePathInDatabaseByStudentID($studentID, $filename); | ||
$filename = time() . '.' . $student->id . $this->photo_infix . $file->hashName(); | ||
|
||
if ($student->photo) { | ||
Storage::delete($this->photos_path . $student->photo); | ||
} | ||
|
||
return response()->json([ | ||
'profile' => "La foto del perfil de l'estudiant s'actualitzat correctament" | ||
], 200); | ||
$file->storeAs($this->photos_path, $filename); | ||
|
||
$student->photo = $filename; | ||
$student->save(); | ||
|
||
} catch (StudentNotFoundException $e) { | ||
|
||
Log::error('Exception:', [ | ||
'exception' => $e->getMessage(), | ||
'trace' => $e->getTraceAsString(), | ||
]); | ||
return response()->json($e->getMessage(), 404); | ||
|
||
} catch (\Exception $e) { | ||
|
||
Log::error('Exception:', [ | ||
'exception' => $e->getMessage(), | ||
'trace' => $e->getTraceAsString(), | ||
]); | ||
return response()->json('La foto del perfil de l\'estudiant no s\'ha pogut actualitzar, per favor intenteu-ho de nou', 500); | ||
|
||
} | ||
} | ||
return response()->json(['message' => 'La imatge s\'ha actualitzat']); | ||
} | ||
} |
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
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,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Policies; | ||
|
||
use App\Models\Project; | ||
use App\Models\User; | ||
use Illuminate\Auth\Access\HandlesAuthorization; | ||
use Illuminate\Auth\Access\Response; | ||
|
||
class ProjectPolicy | ||
{ | ||
use HandlesAuthorization; | ||
|
||
public function update(User $user, Project $project): Response | ||
{ | ||
if ($user->student->resume->projects->contains($project)) { | ||
return Response::allow(); | ||
} | ||
return Response::deny('This action is unauthorized.', 403); | ||
} | ||
} |
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
Oops, something went wrong.