6 커밋 2e34a53200 ... a03e443e76

작성자 SHA1 메시지 날짜
  zntt a03e443e76 Merge branch 'fix/diaria-kay-correções-backend' of Softpar/sfp_api_laravel_diarista into development 1 주 전
  Gustavo Zanatta 1ba50e9ce5 feat: listagem propostas enviadas pelo prestador 1 주 전
  Gustavo Zanatta 087920c3c8 ajustes avaliacao: max 5 files, so permite anexar foto em avaliaca negativa, nao tava exibindo foto do avaliado, pré-seleciona favorito se ja era antes 1 주 전
  Gustavo Zanatta 3d8ce14031 fix avatar na avaliacao 1 주 전
  Gustavo Zanatta 5fd5ca664c fix atribuicao de finished na schedule 1 주 전
  zntt acefced319 Merge branch 'fix/diaria-kay-correções-backend' of Softpar/sfp_api_laravel_diarista into development 1 주 전

+ 18 - 0
app/Http/Requests/ReviewRequest.php

@@ -57,6 +57,24 @@ class ReviewRequest extends FormRequest
         return $rules;
     }
 
+    public function withValidator($validator): void
+    {
+        $validator->after(function ($validator) {
+            $photos = $this->file('photos');
+
+            if (empty($photos)) {
+                return;
+            }
+
+            if ((float) $this->input('stars') > 2) {
+                $validator->errors()->add(
+                    'photos',
+                    __('validation.custom.review.photos_only_negative'),
+                );
+            }
+        });
+    }
+
     public function messages(): array
     {
         return [

+ 16 - 0
app/Http/Resources/CustomScheduleResource.php

@@ -2,8 +2,10 @@
 
 namespace App\Http\Resources;
 
+use App\Models\ScheduleProposal;
 use Illuminate\Http\Request;
 use Illuminate\Http\Resources\Json\JsonResource;
+use Illuminate\Support\Facades\Auth;
 use Illuminate\Support\Facades\Storage;
 
 class CustomScheduleResource extends JsonResource
@@ -18,6 +20,7 @@ class CustomScheduleResource extends JsonResource
         return [
             'id'              => $this->id,
             'schedule_id'     => $this->schedule_id,
+            'proposal_sent'   => $this->proposalSentByAuthProvider(),
             'address_type'    => $this->address_type,
             'service_type_id' => $this->service_type_id,
 
@@ -81,4 +84,17 @@ class CustomScheduleResource extends JsonResource
             }),
         ];
     }
+
+    private function proposalSentByAuthProvider(): bool
+    {
+        $providerId = Auth::user()?->provider?->id;
+
+        if (! $providerId) {
+            return false;
+        }
+
+        return ScheduleProposal::where('schedule_id', $this->schedule_id)
+            ->where('provider_id', $providerId)
+            ->exists();
+    }
 }

+ 5 - 4
app/Http/Resources/ReviewDetailResource.php

@@ -42,10 +42,11 @@ class ReviewDetailResource extends JsonResource
                 'code'          => $schedule->code,
 
                 'client' => $schedule->client ? [
-                    'id'    => $schedule->client->id,
-                    'name'  => $schedule->client->user?->name,
-                    'email' => $schedule->client->user?->email,
-                    'phone' => $schedule->client->user?->phone,
+                    'id'            => $schedule->client->id,
+                    'name'          => $schedule->client->user?->name,
+                    'email'         => $schedule->client->user?->email,
+                    'phone'         => $schedule->client->user?->phone,
+                    'profile_photo' => $schedule->client->profile_photo ?? null,
                 ] : null,
 
                 'provider' => $schedule->provider ? [

+ 3 - 3
app/Observers/ScheduleObserver.php

@@ -19,9 +19,9 @@ class ScheduleObserver
 
         $endedAt = Carbon::parse($schedule->date->format('Y-m-d').' '.$schedule->end_time);
 
-        // if ($endedAt->isFuture()) {
-        //    return;
-        // }
+        if ($endedAt->isFuture()) {
+           return;
+        }
 
         $schedule->forceFill(['status' => 'finished'])->saveQuietly();
 

+ 12 - 2
app/Services/CustomScheduleService.php

@@ -329,7 +329,15 @@ class CustomScheduleService
             )
             ->get();
 
-        $availableOpportunities = $opportunities->filter(function ($opportunity) use ($providerId) {
+        $proposedScheduleIds = ScheduleProposal::where('provider_id', $providerId)
+            ->pluck('schedule_id')
+            ->flip();
+
+        $availableOpportunities = $opportunities->filter(function ($opportunity) use ($providerId, $proposedScheduleIds) {
+            if ($proposedScheduleIds->has($opportunity->id)) {
+                return true;
+            }
+
             try {
                 return $this->checkProviderAvailability($providerId, $opportunity);
             } catch (\Exception $e) {
@@ -337,7 +345,7 @@ class CustomScheduleService
             }
         });
 
-        $availableOpportunities->each(function ($opportunity) use ($providerAddress) {
+        $availableOpportunities->each(function ($opportunity) use ($providerAddress, $proposedScheduleIds) {
             $opportunity->distance_km = $this->zipCodeCoordinatesService->calculateDistance(
                 $providerAddress?->latitude !== null ? (float) $providerAddress->latitude : null,
                 $providerAddress?->longitude !== null ? (float) $providerAddress->longitude : null,
@@ -352,6 +360,8 @@ class CustomScheduleService
             $opportunity->customer_photo = $photoPath
                 ? Storage::temporaryUrl($photoPath, now()->addMinutes(60))
                 : null;
+
+            $opportunity->proposal_sent = $proposedScheduleIds->has($opportunity->id);
         });
 
         return $availableOpportunities->values();

+ 1 - 0
lang/en/validation.php

@@ -232,6 +232,7 @@ return [
         'review' => [
             'already_reviewed' => 'This schedule has already been reviewed by this user.',
             'invalid_origin'   => 'The origin field must be "providers" or "clients".',
+            'photos_only_negative' => 'Photos can only be attached to reviews of up to 2 stars.',
         ],
         'review_improvement' => [
             'already_exists' => 'This improvement type is already linked to this review.',

+ 1 - 0
lang/es/validation.php

@@ -233,6 +233,7 @@ return [
         'review' => [
             'already_reviewed' => 'Esta agenda ya fue evaluada por este usuario.',
             'invalid_origin'   => 'El campo origen debe ser "providers" o "clients".',
+            'photos_only_negative' => 'Solo se pueden adjuntar fotos en evaluaciones de hasta 2 estrellas.',
         ],
         'review_improvement' => [
             'already_exists' => 'Este tipo de mejora ya está vinculado a esta evaluación.',

+ 1 - 0
lang/pt/validation.php

@@ -233,6 +233,7 @@ return [
         'review' => [
             'already_reviewed' => 'Esta agenda já foi avaliada por este usuário.',
             'invalid_origin'   => 'O campo origem deve ser "providers" ou "clients".',
+            'photos_only_negative' => 'Só é possível anexar fotos em avaliações de até 2 estrelas.',
         ],
         'review_improvement' => [
             'already_exists' => 'Este tipo de melhoria já está vinculado a esta avaliação.',