def get(self, accountId): queryDeveloperApp = ApplicationDeveloper.query.filter_by( accountid=accountId).all() if not queryDeveloperApp: return res.resourceMissing( "No apps for developer with account {} found.".format( accountId)) developerapps, error = applicationdevelopers_schema.dump( queryDeveloperApp) if error: return res.internalServiceError(error) allapps = [] for developerapp in developerapps: queryApplication = Application.query.filter( Application.id == developerapp["appid"]).filter( or_( Application.active == True, and_(Application.active == False, Application.runningversion == 0))).first() if queryApplication: queryAppVersion = ApplicationVersion.query.filter( ApplicationVersion.app == queryApplication.id).first() developerapp["appDetails"] = application_schema.dump( queryApplication).data if queryAppVersion: developerapp["appDetails"][ "appversionDetails"] = applicationversion_schema.dump( queryAppVersion).data allapps.append(developerapp) return res.getSuccess(data=allapps)
def get(self, appId): queryApp = Application.query.filter_by(id=appId).first() # Checks application exists if not queryApp: return res.resourceMissing("No application found") return res.getSuccess(data=application_schema.dump(queryApp).data)
def delete(self, appId): queryApp = Application.query.filter_by(id=appId).first() # Checks application exists in database if not queryApp: return res.resourceMissing("No application found.") queryApp.active = False db.session.commit() return res.deleteSuccess( "{} succesfully removed from Makiti App Store".format( queryApp.appname), application_schema.dump(queryApp).data)
def get(self, appversionId): queryAppVersion = ApplicationVersion.query.filter_by( id=appversionId).first() if not queryAppVersion: return res.resourceMissing( "No version record {} exists.".format(appversionId)) appVersion, error = applicationversion_schema.dump(queryAppVersion) if error: return res.internalServiceError(error) queryApp = Application.query.filter_by(id=queryAppVersion.app).first() if not queryApp: return res.resourceMissing("App {} does not exist.".format( queryAppVersion.app)) appVersion["appDetails"] = application_schema.dump(queryApp).data return res.getSuccess(data=appVersion)
def get(self, accountId): appRequestServ = requests.get(app.config['APPREQUEST_SERVICE'] + "customer/{}".format(accountId)).json() print(json.dumps(appRequestServ)) if "success" not in appRequestServ["status"]: return res.internalServiceError("Sorry :(") allRequests = appRequestServ["data"] applications = [] for req in allRequests: queryAppVersion = ApplicationVersion.query.filter_by( id=req["appversion"]).first() queryApp = Application.query.filter_by( id=queryAppVersion.app).first() thisapp = application_schema.dump(queryApp).data thisapp["appversionDetails"] = applicationversion_schema.dump( queryAppVersion).data applications.append(thisapp) return res.getSuccess(data=applications)
def post(self): data = request.get_json() print(request.files) print(data) if not data or not data.get("accountId") or not data.get( "author") or not data.get("appName"): return res.badRequestError("Missing data to process request") # Checks if app name already exists query = Application.query.filter_by( appname=data.get('appName')).first() if query is not None: return res.resourceExistsError("App name {} already taken".format( data.get('appName'))) # Validates and saves app data given appDetails = { "appname": data.get('appName'), "author": data.get("author"), "description": data.get('appDescription') } newApp, error = application_schema.load(appDetails) if error: return res.badRequestError(error) db.session.add(newApp) db.session.commit() # Create app directory ServUtil.createAppDir( os.path.join(app.config["UPLOAD_FOLDER"], newApp.appname)) # Add permission to developer over created application linked, msg = ServUtil.addDevelopertoApp( db, { "appid": newApp.id, "accountid": data.get("accountId") }) if not linked: return res.internalServiceError(msg) return res.postSuccess( "Succesfully created application {}.".format(newApp.appname), application_schema.dump(newApp).data)
def put(self, appId): data = request.get_json() if not data: return res.badRequestError("No data provided to update.") queryApp = Application.query.filter_by(id=appId).first() # Checks application exists in database if not queryApp: return res.resourceMissing("No application found.") # Saves app description (if provided) if data.get('description'): queryApp.description = data.get('description') db.session.commit() return res.getSuccess( "{} successfully updated.".format(queryApp.appname), application_schema.dump(queryApp).data)