refactor(controllers): extract validation of created data into separate method
This commit is contained in:
		
							parent
							
								
									7b96b8dfb4
								
							
						
					
					
						commit
						97d23b3998
					
				@ -99,20 +99,8 @@ final class TaskEstimation
 | 
				
			|||||||
            return response()->json(['errors' => ['startDate' => ['validation.date_ymdhi']]], 400);
 | 
					            return response()->json(['errors' => ['startDate' => ['validation.date_ymdhi']]], 400);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if ($startWorkday->isAfter($endWorkday)) {
 | 
					        if (($result = $this->validateParsedData($startDate, $startWorkday, $endWorkday)) !== null) {
 | 
				
			||||||
            return response()->json(['errors' => ['startWorkday' => ['validation.start_workday_must_be_before_end_workday']]], 400);
 | 
					            return $result;
 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if ($startWorkday->isEqualTo($endWorkday)) {
 | 
					 | 
				
			||||||
            return response()->json(['errors' => ['startWorkday' => ['validation.start_workday_must_not_be_equal_to_end_workday']]], 400);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if ($startWorkday->isAfter(LocalTime::fromNativeDateTime($startDate))) {
 | 
					 | 
				
			||||||
            return response()->json(['errors' => ['startDate' => ['validation.start_workday_must_be_before_start_date']]], 400);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if ($endWorkday->isBefore(LocalTime::fromNativeDateTime($startDate))) {
 | 
					 | 
				
			||||||
            return response()->json(['errors' => ['endWorkday' => ['validation.end_workday_must_be_after_start_date']]], 400);
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $workMinutes = $this->durationConvertor->convertIntoWorkDuration($duration, $startWorkday, $endWorkday, $startDate);
 | 
					        $workMinutes = $this->durationConvertor->convertIntoWorkDuration($duration, $startWorkday, $endWorkday, $startDate);
 | 
				
			||||||
@ -133,4 +121,26 @@ final class TaskEstimation
 | 
				
			|||||||
            'estimation_date' => $dueDate->format('Y-m-d H:i:s'),
 | 
					            'estimation_date' => $dueDate->format('Y-m-d H:i:s'),
 | 
				
			||||||
        ]);
 | 
					        ]);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private function validateParsedData(\DateTimeInterface $startDate, LocalTime $startWorkday, LocalTime $endWorkday): JsonResponse|null
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        if ($startWorkday->isAfter($endWorkday)) {
 | 
				
			||||||
 | 
					            return response()->json(['errors' => ['startWorkday' => ['validation.start_workday_must_be_before_end_workday']]], 400);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if ($startWorkday->isEqualTo($endWorkday)) {
 | 
				
			||||||
 | 
					            return response()->json(['errors' => ['startWorkday' => ['validation.start_workday_must_not_be_equal_to_end_workday']]], 400);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if ($startWorkday->isAfter(LocalTime::fromNativeDateTime($startDate))) {
 | 
				
			||||||
 | 
					            return response()->json(['errors' => ['startDate' => ['validation.start_workday_must_be_before_start_date']]], 400);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if ($endWorkday->isBefore(LocalTime::fromNativeDateTime($startDate))) {
 | 
				
			||||||
 | 
					            return response()->json(['errors' => ['endWorkday' => ['validation.end_workday_must_be_after_start_date']]], 400);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return null;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user