diff --git a/app/AnimalShelter.py b/app/AnimalShelter.py index 62fd6fd..1f696f7 100644 --- a/app/AnimalShelter.py +++ b/app/AnimalShelter.py @@ -56,4 +56,37 @@ class AnimalShelter(object): data = self.collection.find(criteria) return data except Exception as e: - raise Exception(f"Error: {e}") \ No newline at end of file + raise Exception(f"Error: {e}") + + def update(self, *args, **kwargs): + criteria = kwargs.get('criteria', None) + update_one = kwargs.get('once', False) + update_type = kwargs.get('update_type', None) + data = kwargs.get('data', None) + + + if update_one: + try: + self.collection.update_one(criteria, {f'${update_type}': data}) + except Exception as e: + raise Exception(f"Error: {e}") + else: + try: + self.collection.update_many(criteria, {f'${update_type}': data}) + except Exception as e: + raise Exception(f'Error: {e}') + + def delete(self, *args, **kwargs): + criteria = kwargs.get('criteria', None) + delete_one = kwargs.get('once', False) + + if delete_one: + try: + self.collection.delete_one(criteria) + except Exception as e: + raise Exception(f'Error: {e}') + else: + try: + self.collection.delete_many(criteria) + except Exception as e: + raise Exception(f'Error: {e}') \ No newline at end of file diff --git a/app/main.py b/app/main.py index e3f648f..d190847 100644 --- a/app/main.py +++ b/app/main.py @@ -1,29 +1,10 @@ from AnimalShelter import AnimalShelter test = AnimalShelter() -test_criteria = {"breed": "Pit Bull Mix"} +test_criteria = {"breed": "Protogen"} test_data = test.read(criteria=test_criteria) for object in test_data: print(object) -test_data = { - 'rec_num': 10001, - 'age_upon_outcome': '3 years', - 'animal_id': 'FA69420', - 'animal_type': 'Furry', - 'breed': 'Protogen', - 'color': 'Purple', - 'date_of_birth': '1999-12-25', - 'datetime': '2019-10-11 10:03:00', - 'monthyear': '2019-10-11T10:03:00', - 'name': '*Brex', - 'outcome_subtype': 'Foster', - 'outcome_type': 'Adoption', - 'sex_upon_outcome': 'Male i think', - 'location_lat': 30.7118766251975, - 'location_long': -97.2999365773623, - 'age_upon_outcome_in_weeks': 558.059821428571 -} - -test.create(test_data) \ No newline at end of file +test.delete(criteria={"breed": "Protogen"}, once=True) \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml index d6c19ed..8ba965f 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,5 +1,6 @@ services: app: + command: sh -c "while true; do echo hello; sleep 2; done" build: context: . dockerfile: Dockerfile