Open aliasad059 opened 5 months ago
8f8fb55d5a
)[!TIP] I'll email you at aliasad059@gmail.com when I complete this pull request!
Here are the GitHub Actions logs prior to making any changes:
3557558
Checking services/post_ads/src/main.py for syntax errors... ✅ services/post_ads/src/main.py has no syntax errors!
1/1 ✓Checking services/post_ads/src/main.py for syntax errors... ✅ services/post_ads/src/main.py has no syntax errors!
Sandbox passed on the latest main
, so sandbox checks will be enabled for this issue.
I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.
services/post_ads/src/main.py
✓ https://github.com/aliasad059/advertisement-on-clouds-service/commit/2ce90555bd31b226032f4cff02579fd977b3df31 Edit
Modify services/post_ads/src/main.py with contents:
• Add a new endpoint definition below the existing `/get_request_status` endpoint.
• Define the new endpoint as a DELETE method with the path `/delete_post`.
• The endpoint should accept a parameter `post_id` which will be used to identify the post to delete.
• Call a new method `delete_post` from `post_ads_service` and pass the `post_id` to it.
• Return a response indicating the success or failure of the deletion operation.
--- +++ @@ -30,6 +30,19 @@ return response +@app.delete("/delete_post") +async def delete_post(post_id: str): + result = post_ads_service.delete_post(post_id) + return result + + + def delete_post(self, post_id): + # delete the post from the database and the associated image from s3 + self.psql_client.delete_from_table('ads', f"id = {post_id}") + self.s3_client.delete_file(post_id) + return {"message": "Post deleted successfully"} + + @app.post("/get_request_status") async def get_request_status( request_id : str = Form(...)
services/post_ads/src/main.py
✓ Edit
Check services/post_ads/src/main.py with contents:
Ran GitHub Actions for 2ce90555bd31b226032f4cff02579fd977b3df31:
services/post_ads/src/post_ads_service.py
✓ https://github.com/aliasad059/advertisement-on-clouds-service/commit/9bd1eb37bc4138b6b670673583674073dedec658 Edit
Modify services/post_ads/src/post_ads_service.py with contents:
• Add a new method `delete_post` that takes `post_id` as a parameter.
• Implement the logic to delete the post from the database or storage service. This may involve calling methods from `psql_client.py` or `s3_client.py` depending on where the posts are stored.
• Ensure that the method handles any exceptions and returns a response indicating whether the deletion was successful.
--- +++ @@ -8,6 +8,14 @@ self.s3_client = S3Connector(**s3_config) self.rabbitmq_client = RabbitMQSender(**rabbitmq_config) pass + + def delete_post(self, post_id): + try: + self.psql_client.delete_from_table('ads', f"id = {post_id}") + self.s3_client.delete_file(post_id) + return {"message": "Post deleted successfully"} + except Exception as e: + return {"error": str(e)} def post_ads(self, image, description, email): # save description and email to db
services/post_ads/src/post_ads_service.py
✓ Edit
Check services/post_ads/src/post_ads_service.py with contents:
Ran GitHub Actions for 9bd1eb37bc4138b6b670673583674073dedec658:
services/post_ads/src/utils/DBaaS/psql_client.py
✓ https://github.com/aliasad059/advertisement-on-clouds-service/commit/af642f3bd1f06350a34c597264b6540bd9ffde3e Edit
Modify services/post_ads/src/utils/DBaaS/psql_client.py with contents:
• If the posts are stored in a PostgreSQL database, add a new method to delete a post by its `post_id`.
• Ensure that the method properly deletes the post from the database and handles any exceptions.
--- +++ @@ -50,11 +50,11 @@ def delete_from_table(self, table_name, condition): - """ - deletes rows from the table - """ - query = f"DELETE FROM {table_name} WHERE {condition}" - self.execute_query(query) + try: + query = f"DELETE FROM {table_name} WHERE {condition}" + self.execute_query(query) + except psycopg2.Error as e: + return {"error": str(e)} def update_table(self, table_name, column, value, condition):
services/post_ads/src/utils/DBaaS/psql_client.py
✓ Edit
Check services/post_ads/src/utils/DBaaS/psql_client.py with contents:
Ran GitHub Actions for af642f3bd1f06350a34c597264b6540bd9ffde3e:
services/post_ads/src/utils/DBaaS/s3_client.py
✓ https://github.com/aliasad059/advertisement-on-clouds-service/commit/060ccfa1cdf7b759bcbdf11ce81a039c8fb51c5e Edit
Modify services/post_ads/src/utils/DBaaS/s3_client.py with contents:
• If the posts are stored in an S3 bucket, add a new method to delete a post by its `post_id`.
• Ensure that the method properly deletes the post from the S3 bucket and handles any exceptions.
--- +++ @@ -61,10 +61,7 @@ """ try: object = self.bucket.Object(object_name) - response = object.delete( - VersionId='string', - ) + response = object.delete() + return {"message": "File deleted successfully"} except ClientError as e: - print(e) - return None - return response+ return {"error": str(e)}
services/post_ads/src/utils/DBaaS/s3_client.py
✓ Edit
Check services/post_ads/src/utils/DBaaS/s3_client.py with contents:
Ran GitHub Actions for 060ccfa1cdf7b759bcbdf11ce81a039c8fb51c5e:
I have finished reviewing the code for completeness. I did not find errors for sweep/add_another_endpoint_for_servicespost_ad
.
💡 To recreate the pull request edit the issue title or description. To tweak the pull request, leave a comment on the pull request.Something wrong? Let us know.
This is an automated message generated by Sweep AI.
Checklist
- [X] Modify `services/post_ads/src/main.py` ✓ https://github.com/aliasad059/advertisement-on-clouds-service/commit/2ce90555bd31b226032f4cff02579fd977b3df31 [Edit](https://github.com/aliasad059/advertisement-on-clouds-service/edit/sweep/add_another_endpoint_for_servicespost_ad/services/post_ads/src/main.py#L37-L37) - [X] Running GitHub Actions for `services/post_ads/src/main.py` ✓ [Edit](https://github.com/aliasad059/advertisement-on-clouds-service/edit/sweep/add_another_endpoint_for_servicespost_ad/services/post_ads/src/main.py#L37-L37) - [X] Modify `services/post_ads/src/post_ads_service.py` ✓ https://github.com/aliasad059/advertisement-on-clouds-service/commit/9bd1eb37bc4138b6b670673583674073dedec658 [Edit](https://github.com/aliasad059/advertisement-on-clouds-service/edit/sweep/add_another_endpoint_for_servicespost_ad/services/post_ads/src/post_ads_service.py#L1-L1) - [X] Running GitHub Actions for `services/post_ads/src/post_ads_service.py` ✓ [Edit](https://github.com/aliasad059/advertisement-on-clouds-service/edit/sweep/add_another_endpoint_for_servicespost_ad/services/post_ads/src/post_ads_service.py#L1-L1) - [X] Modify `services/post_ads/src/utils/DBaaS/psql_client.py` ✓ https://github.com/aliasad059/advertisement-on-clouds-service/commit/af642f3bd1f06350a34c597264b6540bd9ffde3e [Edit](https://github.com/aliasad059/advertisement-on-clouds-service/edit/sweep/add_another_endpoint_for_servicespost_ad/services/post_ads/src/utils/DBaaS/psql_client.py#L1-L1) - [X] Running GitHub Actions for `services/post_ads/src/utils/DBaaS/psql_client.py` ✓ [Edit](https://github.com/aliasad059/advertisement-on-clouds-service/edit/sweep/add_another_endpoint_for_servicespost_ad/services/post_ads/src/utils/DBaaS/psql_client.py#L1-L1) - [X] Modify `services/post_ads/src/utils/DBaaS/s3_client.py` ✓ https://github.com/aliasad059/advertisement-on-clouds-service/commit/060ccfa1cdf7b759bcbdf11ce81a039c8fb51c5e [Edit](https://github.com/aliasad059/advertisement-on-clouds-service/edit/sweep/add_another_endpoint_for_servicespost_ad/services/post_ads/src/utils/DBaaS/s3_client.py#L1-L1) - [X] Running GitHub Actions for `services/post_ads/src/utils/DBaaS/s3_client.py` ✓ [Edit](https://github.com/aliasad059/advertisement-on-clouds-service/edit/sweep/add_another_endpoint_for_servicespost_ad/services/post_ads/src/utils/DBaaS/s3_client.py#L1-L1)