Skip to content

Commit

Permalink
Merge pull request #16 from pazDontExist/mental-space-backend-7
Browse files Browse the repository at this point in the history
Closing Issue #7 - source code translation
  • Loading branch information
well-it-wasnt-me authored Dec 4, 2023
2 parents 24c6123 + 1754c59 commit ff78198
Show file tree
Hide file tree
Showing 81 changed files with 790 additions and 700 deletions.
450 changes: 286 additions & 164 deletions config/routes.php

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion resources/text/en_US/LC_MESSAGES/messages_en_US.po
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,7 @@ msgid ""
msgstr "Error while sending mail. if you wrote it right contact Mental Space"

#: src/Domain/Consulti/Repository/ConsultiRepository.php:126
msgid "Richiesta consulto inviata correttamente"
msgid "Richiesta consult inviata correttamente"
msgstr "Medical Consultation request sent successfull"

#: src/Domain/Patients/Repository/PatientsRepository.php:103
Expand Down
4 changes: 2 additions & 2 deletions src/Action/Auth/DocLoginSubmitAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ public function __invoke(ServerRequestInterface $request, ResponseInterface $res
$username = (string)($data['username'] ?? '');
$password = (string)($data['password'] ?? '');
$role = (string)($data['role'] ?? '');
// Pseudo example
// Check user credentials. You may use an application/domain service and the database here. $user = null;

$userData = $this->userAuth->authenticate($username, $password, $role);

// Clear all flash messages
$flash = $this->session->getFlash();
$flash->clear();
Expand Down
17 changes: 1 addition & 16 deletions src/Action/Auth/UserLoginSubmitAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ public function __invoke(ServerRequestInterface $request, ResponseInterface $res
$username = (string)($data['username'] ?? '');
$password = (string)($data['password'] ?? '');
$role = (string)($data['role'] ?? '');
// Pseudo example
// Check user credentials. You may use an application/domain service and the database here. $user = null;

$userData = $this->userAuth->authenticate_paz($username, $password, $role);
// Clear all flash messages
$flash = $this->session->getFlash();
Expand All @@ -82,21 +81,7 @@ public function __invoke(ServerRequestInterface $request, ResponseInterface $res
$flash->add('success', 'Login successfully');

set_language($userData['locale']);
/*
* $tokenBuilder = (new Builder(new JoseEncoder(), ChainedFormatter::default()));
$algorithm = new Sha256();
$signingKey = getenv('JWT_SECRET');

$now = new \DateTimeImmutable();
$token = $tokenBuilder
->issuedBy('https://app.mentalspace.com')
->permittedFor('http://localhost:8100')
->identifiedBy($userData['user_id'])
->expiresAt($now->modify('+15 DAY'))
->withClaim('uid',$userData['user_id'])
->withClaim('email', $userData['email'])
->getToken($algorithm, $signingKey);
*/
$token = $this->jwtAuth->createJwt(
[
'uid' => $userData['user_id'],
Expand Down
2 changes: 1 addition & 1 deletion src/Action/Cities/ListCitiesAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function __construct(CitesList $citiesList, Responder $responder)
*/
public function __invoke(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
{
// Optional: Pass parameters from the request to the findUsers method

$gh = $this->citiesList->listCities();

return $this->responder->withJson($response, $gh);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@

namespace App\Action\Consulti;

use App\Domain\Consulti\Repository\ConsultiRepository;
use App\Domain\Consulti\Repository\ConsultRepository;
use App\Responder\Responder;
use Fig\Http\Message\StatusCodeInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;

final class GeneraLinkConsultoAction
final class GenerateConsultLinkAction
{

private Responder $responder;
private ConsultiRepository $consultiRepository;
private ConsultRepository $consultiRepository;

function __construct(Responder $responder, ConsultiRepository $consultiRepository)
function __construct(Responder $responder, ConsultRepository $consultiRepository)
{
$this->responder = $responder;
$this->consultiRepository = $consultiRepository;
Expand All @@ -38,7 +38,7 @@ public function __invoke(

if (!filter_var($data['email'], FILTER_VALIDATE_EMAIL)) {
return $this->responder
->withJson($response, ['status' => 'error', 'message' => __('Indirizzo E-Mail non corretto')])
->withJson($response, ['status' => 'error', 'message' => __('E-Mail Address is not correct')])
->withStatus(StatusCodeInterface::STATUS_BAD_REQUEST);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@

namespace App\Action\Consulti;

use App\Domain\Consulti\Repository\ConsultiRepository;
use App\Domain\Consulti\Repository\ConsultRepository;
use App\Responder\Responder;
use Fig\Http\Message\StatusCodeInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;

final class ListLinkConsultoAction
final class ListConsultLinkAction
{

private Responder $responder;
private ConsultiRepository $consultiRepository;
private ConsultRepository $consultiRepository;

function __construct(Responder $responder, ConsultiRepository $consultiRepository)
function __construct(Responder $responder, ConsultRepository $consultiRepository)
{
$this->responder = $responder;
$this->consultiRepository = $consultiRepository;
Expand Down
6 changes: 3 additions & 3 deletions src/Action/Consulti/PinCodeActionCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace App\Action\Consulti;

use App\Domain\Consulti\Repository\ConsultiRepository;
use App\Domain\Consulti\Repository\ConsultRepository;
use App\Responder\Responder;
use Fig\Http\Message\StatusCodeInterface;
use Psr\Http\Message\ResponseInterface;
Expand All @@ -15,9 +15,9 @@ final class PinCodeActionCheck
{

private Responder $responder;
private ConsultiRepository $consultiRepository;
private ConsultRepository $consultiRepository;

function __construct(Responder $responder, ConsultiRepository $consultiRepository)
function __construct(Responder $responder, ConsultRepository $consultiRepository)
{
$this->responder = $responder;
$this->consultiRepository = $consultiRepository;
Expand Down
2 changes: 1 addition & 1 deletion src/Action/Diary/DeleteDiaryAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function __invoke(
}

return $this->responder
->withJson($response, ['status' => 'success', 'message' => __("Eliminato con successo")])
->withJson($response, ['status' => 'success', 'message' => __("Deleted")])
->withStatus(StatusCodeInterface::STATUS_OK);
}
}
4 changes: 2 additions & 2 deletions src/Action/Diary/UploadDiaryAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ public function __invoke(
$entry = $this->repository->addEntry($user_id, $data);
if ($entry) {
return $this->responder
->withJson($response, ['status' => 'success', 'message' => __('Inserito con Successo')])
->withJson($response, ['status' => 'success', 'message' => __('Success')])
->withStatus(StatusCodeInterface::STATUS_OK);
}


return $this->responder
->withJson($response, ['status' => 'error', 'message' => __('Errore')])
->withJson($response, ['status' => 'error', 'message' => __('Error')])
->withStatus(StatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR);
}
}
2 changes: 1 addition & 1 deletion src/Action/Doctors/DocDetailAppAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function __invoke(
->withStatus(StatusCodeInterface::STATUS_BAD_REQUEST);
}

$docData = $this->doctorRepository->AppdoctorDetail($userId);
$docData = $this->doctorRepository->AppDoctorDetail($userId);

if (empty($docData)) {
return $this->responder
Expand Down
11 changes: 6 additions & 5 deletions src/Action/Doctors/InviteDoctorAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use App\Domain\Patients\Repository\PatientsRepository;
use App\Domain\Users\Repository\UserRepository;
use App\Responder\Responder;
use Exception;
use Fig\Http\Message\StatusCodeInterface;
use PHPMailer\PHPMailer\PHPMailer;
use Psr\Http\Message\ResponseInterface;
Expand Down Expand Up @@ -74,14 +75,14 @@ public function __invoke(

//Content
$mail->isHTML(true); //Set email format to HTML
$mail->Subject = 'Invito a partecipare a Mental Space';
$mail->Subject = __('Invite to enter in Mental Space');
$mail_body = file_get_contents(__DIR__ . '/../../../data/mail_template/doctor_invitation');
$search = ['{{PAZ_NOME}}', '{{PAZ_COGNOME}}', '{{PAZ_EMAIL}}', '{{PAZ_USER_ID}}' ];
$replace = [$userData['name'], $userData['surname'], $userData['email'], $userData['user_id']];
$mail_body = str_replace($search, $replace, $mail_body);
$mail->Body = $mail_body;
$mail->send();
} catch (\Exception $e) {
} catch (Exception $e) {
return $this->responder
->withJson($response, ['status' => 'error', 'messsage' => $e->getMessage()])
->withStatus(StatusCodeInterface::STATUS_OK);
Expand Down Expand Up @@ -110,14 +111,14 @@ public function __invoke(

//Content
$mail->isHTML(true); //Set email format to HTML
$mail->Subject = 'Un Nuovo Assistito per te!';
$mail->Subject = __('A new Patient for you !');
$mail_body = file_get_contents(__DIR__ . '/../../../data/mail_template/patient_assigned');
$search = ["{{PAZ_NOME}}", '{{PAZ_COGNOME}}', '{{DOC_NOME}}', '{{DOC_COGNOME}}'];
$replace = [$userData['name'], $userData['surname']. $docData['doc_name'], $docData['doc_surname']];
$mail_body = str_replace($search, $replace, $mail_body);
$mail->Body = $mail_body;
$mail->send();
} catch (\Exception $e) {
} catch (Exception $e) {
return $this->responder
->withJson($response, ['status' => 'error', 'messsage' => $e->getMessage()])
->withStatus(StatusCodeInterface::STATUS_OK);
Expand All @@ -128,7 +129,7 @@ public function __invoke(
->withStatus(StatusCodeInterface::STATUS_OK);
} else {
return $this->responder
->withJson($response, ['status' => 'error', 'message' => 'Errore durante assegnazione medico'])
->withJson($response, ['status' => 'error', 'message' => __('Error while assigning doctor')])
->withStatus(StatusCodeInterface::STATUS_BAD_REQUEST);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Action/Dsm/ListDsmAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ final class ListDsmAction
/**
* The constructor.
*
* @param CitiesList $citiesList The user index list viewer
* @param DsmList $citiesList The dsm list viewer
* @param Responder $responder The responder
*/
public function __construct(DsmList $dsmList, Responder $responder)
Expand Down
4 changes: 2 additions & 2 deletions src/Action/Files/DocFileDeleteAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ public function __invoke(

if (!is_file($file_path)) {
return $this->responder
->withJson($response, ['status' => 'success', 'message' => __("File non trovato")])
->withJson($response, ['status' => 'success', 'message' => __("File not found")])
->withStatus(StatusCodeInterface::STATUS_OK);
}

unlink($file_path);

return $this->responder
->withJson($response, ['status' => 'error', 'message' => __("File Cancellato con sucesso")])
->withJson($response, ['status' => 'error', 'message' => __("File Deleted")])
->withStatus(StatusCodeInterface::STATUS_OK);
}

Expand Down
5 changes: 3 additions & 2 deletions src/Action/Files/DocFileDownloadAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\UploadedFileInterface;
use Slim\Psr7\Stream;

final class DocFileDownloadAction
{
Expand Down Expand Up @@ -42,7 +43,7 @@ public function __invoke(

if (!is_file($filePath)) {
return $this->responder
->withJson($response, ['status' => 'success', 'message'=>__('File non trovato')])
->withJson($response, ['status' => 'success', 'message' => __('File not found')])
->withStatus(StatusCodeInterface::STATUS_OK);
}

Expand All @@ -52,6 +53,6 @@ public function __invoke(
->withAddedHeader('Cache-Control', 'no-store, no-cache, must-revalidate, max-age=0')
->withHeader('Cache-Control', 'post-check=0, pre-check=0')
->withHeader('Pragma', 'no-cache')
->withBody((new \Slim\Psr7\Stream(fopen($filePath, 'rb'))));
->withBody((new Stream(fopen($filePath, 'rb'))));
}
}
6 changes: 3 additions & 3 deletions src/Action/Files/DocFileListAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ public function __invoke(
->withStatus(StatusCodeInterface::STATUS_OK);
}

$listaFiles = scandir($directory);
$listaFiles = array_diff($listaFiles, ['.', '..']);
$filesList = scandir($directory);
$filesList = array_diff($filesList, ['.', '..']);

return $this->responder
->withJson($response, ['status' => 'success', 'files' => $listaFiles])
->withJson($response, ['status' => 'success', 'files' => $filesList])
->withStatus(StatusCodeInterface::STATUS_OK);
}

Expand Down
7 changes: 4 additions & 3 deletions src/Action/Files/DocFileUploadAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function __invoke(

if (!$uploadedFiles) {
return $this->responder
->withJson($response, ['status' => 'error', 'message' => __("Hai dimenticato di inviare file")])
->withJson($response, ['status' => 'error', 'message' => __("Forgot to send the file ?")])
->withStatus(StatusCodeInterface::STATUS_BAD_REQUEST);
}

Expand All @@ -55,15 +55,16 @@ public function __invoke(
if ($uploadedFile->getError() === UPLOAD_ERR_OK) {
$filename = $this->moveUploadedFile($directory, $uploadedFile);
return $this->responder
->withJson($response, ['status' => 'success', 'message' => __("Caricato con successo")])
->withJson($response, ['status' => 'success', 'message' => __("Uploaded")])
->withStatus(StatusCodeInterface::STATUS_OK);
}

return $this->responder
->withJson($response, ['status' => 'error', 'message' => __("Qualcosa è andato storto")])
->withJson($response, ['status' => 'error', 'message' => __("Something went wrong")])
->withStatus(StatusCodeInterface::STATUS_BAD_REQUEST);
}

// @todo move this function in src/Support/functions.php and eliminate the duplicates
private function moveUploadedFile(string $directory, UploadedFileInterface $uploadedFile)
{
$extension = pathinfo($uploadedFile->getClientFilename(), PATHINFO_EXTENSION);
Expand Down
5 changes: 3 additions & 2 deletions src/Action/Files/FileDownloadAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\UploadedFileInterface;
use Slim\Psr7\Stream;

final class FileDownloadAction
{
Expand Down Expand Up @@ -42,7 +43,7 @@ public function __invoke(

if (!is_file($filePath)) {
return $this->responder
->withJson($response, ['status' => 'success', 'message'=>__('File non trovato')])
->withJson($response, ['status' => 'success', 'message' => __('File not found')])
->withStatus(StatusCodeInterface::STATUS_OK);
}

Expand All @@ -52,6 +53,6 @@ public function __invoke(
->withAddedHeader('Cache-Control', 'no-store, no-cache, must-revalidate, max-age=0')
->withHeader('Cache-Control', 'post-check=0, pre-check=0')
->withHeader('Pragma', 'no-cache')
->withBody((new \Slim\Psr7\Stream(fopen($filePath, 'rb'))));
->withBody((new Stream(fopen($filePath, 'rb'))));
}
}
6 changes: 3 additions & 3 deletions src/Action/Files/FileUploadAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function __invoke(

if (!$uploadedFiles) {
return $this->responder
->withJson($response, ['status' => 'error', 'message' => __("Hai dimenticato di inviare file")])
->withJson($response, ['status' => 'error', 'message' => __("Forgot to attach files ?")])
->withStatus(StatusCodeInterface::STATUS_BAD_REQUEST);
}

Expand All @@ -53,12 +53,12 @@ public function __invoke(
if ($uploadedFile->getError() === UPLOAD_ERR_OK) {
$filename = $this->moveUploadedFile($directory, $uploadedFile);
return $this->responder
->withJson($response, ['status' => 'success', 'message' => __("Caricato con successo")])
->withJson($response, ['status' => 'success', 'message' => __("Uploaded")])
->withStatus(StatusCodeInterface::STATUS_OK);
}

return $this->responder
->withJson($response, ['status' => 'error', 'message' => __("Qualcosa è andato storto")])
->withJson($response, ['status' => 'error', 'message' => __("Something went wrong")])
->withStatus(StatusCodeInterface::STATUS_BAD_REQUEST);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
/**
* Action.
*/
final class AddPassiAction
final class AddStepsAction
{
private HealthRepository $health;

Expand Down Expand Up @@ -42,7 +42,7 @@ public function __construct(HealthRepository $health, Responder $responder)
public function __invoke(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
{
$data = $request->getParsedBody();
$gh = $this->health->aggiungiPassi($request->getAttribute('uid'), $data['passi']);
$gh = $this->health->aggiungiPassi($request->getAttribute('uid'), $data['steps']);

if ($gh) {
$result = ['status' => 'success'];
Expand Down
2 changes: 1 addition & 1 deletion src/Action/Messages/ListContactsAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function __invoke(ServerRequestInterface $request, ResponseInterface $res
* This could also be done within a specific Responder class.
*
* @param ResponseInterface $response The response
* @param array $users The users
* @param array $sbs Dont remember
*
* @return ResponseInterface The response
*/
Expand Down
Loading

0 comments on commit ff78198

Please sign in to comment.