def update_pyp(self, request): pyp = Pyp.get_by_id(request.id) if not pyp: raise endpoints.NotFoundException( "The policy or program ID: " + str(request.id) + " doesn't exist") updated_pyp = Pyp.update(pyp, request) if not updated_pyp: raise endpoints.InternalServerErrorException('Something went wrong') return PypListResponse( pyps=[PypApiHelper().to_message(pyp)])
def delete_pyp(self, request): pyp = Pyp.get_by_id(request.id) if not pyp: raise endpoints.NotFoundException( "The policy or program ID: " + str(request.id) + " doesn't exist") pyp.key.delete() return message_types.VoidMessage()
def get_pyp(self, request): pyp = Pyp.get_by_id(request.id) if not pyp: raise endpoints.NotFoundException( "The policy or program ID: " + str(request.id) + " doesn't exist") return PypListResponse( pyps=[PypApiHelper().to_message(pyp)])
def create_pyp(self, request): if not (request.title and request.country): raise endpoints.BadRequestException('Title and country are required') pyp = Pyp.create(request) if not pyp: raise endpoints.InternalServerErrorException('Something went wrong') return PypListResponse( pyps=[PypApiHelper().to_message(pyp)])
def get_pyps(self, request): pyps = Pyp.get_all() return PypListResponse( pyps=[PypApiHelper().to_message(pyp) for pyp in pyps if pyps])