Browse Source

validator

Luciano Andrade 7 years ago
parent
commit
2d3352e670
1 changed files with 10 additions and 4 deletions
  1. 10 4
      src/FTTHBundle/Controller/ONURESTController.php

+ 10 - 4
src/FTTHBundle/Controller/ONURESTController.php

@@ -155,11 +155,17 @@ class ONURESTController extends RESTController
 	    $newState = $wf->apply($entity, $transition);
 	    $newState = $wf->apply($entity, $transition);
 
 
 	    $em = $this->container->get("doctrine.orm.entity_manager");
 	    $em = $this->container->get("doctrine.orm.entity_manager");
-	    $em->persist($entity);
-	    $em->flush();
-
-	    return $entity;
+	    $validator = $this->container->get('validator');
+	    $errors = $validator->validate($entity);
+	    if (count($errors) > 0) {
+		    $errorsString = (string) $errors;
+		    return FOSView::create($errorsString, Codes::HTTP_INTERNAL_SERVER_ERROR);
+	    }else{
+		    $em->persist($entity);
+		    $em->flush();
 
 
+		    return $entity;
+	    }
         } catch (\Exception $e) {
         } catch (\Exception $e) {
             return FOSView::create($e->getMessage(), Codes::HTTP_INTERNAL_SERVER_ERROR);
             return FOSView::create($e->getMessage(), Codes::HTTP_INTERNAL_SERVER_ERROR);
         }
         }