Beispiel #1
0
 public function __invoke(Request $req, Response $res)
 {
     $school = $req->getAttribute('school', false);
     if (!$school->id) {
         return $res->withStatus(403, 'No school');
     }
     $id = $req->getParam('id', false);
     if (!$id) {
         $res = $res->withStatus(404);
         return $res;
     }
     $software = $this->softwareService->getSoftwareById($id);
     if ($software['school_id'] != $school->id) {
         $res = $res->withStatus(403, 'Schools not match');
         return $res;
     }
     try {
         $this->softwareService->removeSoftware($id);
         $res = $res->withStatus(204);
     } catch (Exception $ex) {
         $res = $res->withStatus(500, $ex->getMessage());
     }
     return $res;
 }
Beispiel #2
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;
 }