Skip to content

Commit

Permalink
Add userId to saveScreen (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
mako321 authored Dec 13, 2024
1 parent 1aaa3b7 commit bcfab2f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
8 changes: 7 additions & 1 deletion src/Dto/ConsultationSaveScreenDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ class ConsultationSaveScreenDto extends BaseDto
{
protected int $consultationId;
protected int $userTerminId;
protected string $userEmail;
protected string $executedAt;
protected array $files;
protected ?string $userEmail = null;
protected ?int $userId = null;

public function getConsultationId(): int
{
Expand All @@ -32,6 +33,11 @@ public function getExecutedAt(): string
return $this->executedAt;
}

public function getUserId(): ?int
{
return $this->userId;
}

public function setFiles(array $files): void
{
$this->files = $files;
Expand Down
6 changes: 6 additions & 0 deletions src/Http/Controllers/Swagger/ConsultationAPISwagger.php
Original file line number Diff line number Diff line change
Expand Up @@ -638,9 +638,15 @@ public function schedule(ScheduleConsultationAPIRequest $scheduleConsultationAPI
* ),
* @OA\Property(
* property="user_email",
* description="required_without:user_id",
* type="string"
* ),
* @OA\Property(
* property="user_id",
* description="required_without:user_email",
* type="integer"
* ),
* @OA\Property(
* property="timestamp",
* type="string",
* example="2024-10-04 12:02:12"
Expand Down
3 changes: 2 additions & 1 deletion src/Http/Requests/ConsultationScreenSaveRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ public function rules(): array
return [
'consultation_id' => ['required', 'integer'],
'user_termin_id' => ['required', 'integer'],
'user_email' => ['required', 'email'],
'user_email' => ['required_without:user_id', 'email'],
'user_id' => ['required_without:user_email', 'integer'],
'executed_at' => ['required'],
'files' => ['array', 'min:1'],
'files.*.file' => ['required'],
Expand Down
10 changes: 8 additions & 2 deletions src/Services/ConsultationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -594,10 +594,16 @@ private function getReminderData(string $reminderStatus): Collection

public function saveScreen(ConsultationSaveScreenDto $dto): void
{
$user = User::query()->where('email', '=', $dto->getUserEmail())->firstOrFail();
$userId = $dto->getUserId()
?? User::query()
->select(['id'])
->where('email', '=', $dto->getUserEmail())
->firstOrFail()
->getKey();

$term = Carbon::make($dto->getExecutedAt());
// consultation_id/term_start_timestamp/user_id/timestamp.jpg
$folder = ConstantEnum::DIRECTORY . "/{$dto->getConsultationId()}/{$term->getTimestamp()}/{$user->getKey()}";
$folder = ConstantEnum::DIRECTORY . "/{$dto->getConsultationId()}/{$term->getTimestamp()}/{$userId}";

foreach ($dto->getFiles() as $file) {
$screen = $file['file'];
Expand Down

0 comments on commit bcfab2f

Please sign in to comment.