Beispiel #1
0
 public function __invoke(Request $req, Response $res, array $args = [])
 {
     $school = $req->getAttribute('school', false);
     if (!$school) {
         return $res->withStatus(403, 'No school');
     }
     $params = $req->getParams();
     $params['school_id'] = $school->id;
     $id = $params['id'];
     unset($params['id']);
     try {
         if ($id) {
             $software = $this->softwareService->updateSoftware($params, $id);
             $res = $res->withStatus(200);
         } else {
             $software = $this->softwareService->createSoftware($params);
             $res = $res->withStatus(201);
         }
         $res = $res->withJson($software);
     } catch (Exception $ex) {
         $res = $res->withStatus(500, $ex->getMessage());
     }
     return $res;
 }