From 0d92eba4a9c40c3d20c15e44a8a1712c0307d75d Mon Sep 17 00:00:00 2001 From: Amandeep8848 Date: Thu, 26 Sep 2024 12:01:04 +0530 Subject: [PATCH] feat: insights listing and details api --- .../digital_8848/doctype/insights/__init__.py | 0 .../doctype/insights/api/insights_details.py | 39 +++++++++ .../doctype/insights/api/insights_listing.py | 36 +++++++++ .../digital_8848/doctype/insights/insights.js | 8 ++ .../doctype/insights/insights.json | 79 +++++++++++++++++++ .../digital_8848/doctype/insights/insights.py | 9 +++ .../doctype/insights/test_insights.py | 9 +++ 7 files changed, 180 insertions(+) create mode 100644 digital_8848/digital_8848/doctype/insights/__init__.py create mode 100644 digital_8848/digital_8848/doctype/insights/api/insights_details.py create mode 100644 digital_8848/digital_8848/doctype/insights/api/insights_listing.py create mode 100644 digital_8848/digital_8848/doctype/insights/insights.js create mode 100644 digital_8848/digital_8848/doctype/insights/insights.json create mode 100644 digital_8848/digital_8848/doctype/insights/insights.py create mode 100644 digital_8848/digital_8848/doctype/insights/test_insights.py diff --git a/digital_8848/digital_8848/doctype/insights/__init__.py b/digital_8848/digital_8848/doctype/insights/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/digital_8848/digital_8848/doctype/insights/api/insights_details.py b/digital_8848/digital_8848/doctype/insights/api/insights_details.py new file mode 100644 index 0000000..e225725 --- /dev/null +++ b/digital_8848/digital_8848/doctype/insights/api/insights_details.py @@ -0,0 +1,39 @@ +import frappe + +@frappe.whitelist(allow_guest=True) +def get_insights_details(**kwargs): + try: + response = [] + title = kwargs.get("title") + slug = kwargs.get("slug") + + if not title and not slug: + return error_response("Please provide a title or slug") + if title: + insights_doctype = frappe.get_doc("Insights",kwargs.get("title")) + if slug: + insights_doctype_title = frappe.db.get_value("Insights",{'slug': kwargs.get("slug")}) + if not insights_doctype_title: + return error_response("No insights found with the given slug") + insights_doctype = frappe.get_doc("Insights",insights_doctype_title) + + response.append({ + "title": insights_doctype.get("title"), + "url": insights_doctype.get("url"), + "type": insights_doctype.get("type"), + "slug": insights_doctype.get("slug"), + "short_description": insights_doctype.get("short_description"), + "image": insights_doctype.get("image") + }) + return success_response(data=response) + + except Exception as e: + return error_response(f"An error occurred: {str(e)}") + +def success_response(data=None, id=None): + response = {"status": "success"} + response["data"] = data + return response + +def error_response(err_msg): + return {"status": "error", "error": err_msg} \ No newline at end of file diff --git a/digital_8848/digital_8848/doctype/insights/api/insights_listing.py b/digital_8848/digital_8848/doctype/insights/api/insights_listing.py new file mode 100644 index 0000000..c2806d0 --- /dev/null +++ b/digital_8848/digital_8848/doctype/insights/api/insights_listing.py @@ -0,0 +1,36 @@ +import frappe + +@frappe.whitelist(allow_guest=True) +def get_insights_listing(**kwargs): + try: + response = [] + filters = {} + if kwargs.get("type"): + filters.update({"type": kwargs.get("type")}) + + insights_doctypes_list = frappe.get_all("Insights", filters=filters, pluck="name") + if insights_doctypes_list: + for doctype in insights_doctypes_list: + insights_doctype = frappe.get_doc("Insights", doctype) + insights_doctype_details = { + "title": insights_doctype.get("title") or None, + "image": insights_doctype.get("image") or None, + "short_description": insights_doctype.get("short_description") or None, + "slug": insights_doctype.get("slug") or None, + "url": insights_doctype.get("url") or None, + "type": insights_doctype.get("type") or None + } + response.append(insights_doctype_details) + return success_response(response) + else: + return error_response("No data found.") + except Exception as e: + return error_response(f"An error occurred: {str(e)}") + +def success_response(data=None, id=None): + response = {"status": "success"} + response["data"] = data + return response + +def error_response(err_msg): + return {"status": "error", "error": err_msg} \ No newline at end of file diff --git a/digital_8848/digital_8848/doctype/insights/insights.js b/digital_8848/digital_8848/doctype/insights/insights.js new file mode 100644 index 0000000..5ed4121 --- /dev/null +++ b/digital_8848/digital_8848/doctype/insights/insights.js @@ -0,0 +1,8 @@ +// Copyright (c) 2024, digital_8848 and contributors +// For license information, please see license.txt + +// frappe.ui.form.on("Insights", { +// refresh(frm) { + +// }, +// }); diff --git a/digital_8848/digital_8848/doctype/insights/insights.json b/digital_8848/digital_8848/doctype/insights/insights.json new file mode 100644 index 0000000..0ef0b87 --- /dev/null +++ b/digital_8848/digital_8848/doctype/insights/insights.json @@ -0,0 +1,79 @@ +{ + "actions": [], + "allow_rename": 1, + "autoname": "format:{title}", + "creation": "2024-09-26 11:19:32.756871", + "doctype": "DocType", + "engine": "InnoDB", + "field_order": [ + "title", + "type", + "short_description", + "column_break_njbk", + "url", + "slug", + "image" + ], + "fields": [ + { + "fieldname": "title", + "fieldtype": "Data", + "label": "Title" + }, + { + "fieldname": "type", + "fieldtype": "Select", + "label": "Type", + "options": "Manufacturing\nConstruction\nRetail\nOnline Retail" + }, + { + "fieldname": "short_description", + "fieldtype": "Small Text", + "label": "Short Description" + }, + { + "fieldname": "column_break_njbk", + "fieldtype": "Column Break" + }, + { + "fieldname": "url", + "fieldtype": "Data", + "label": "URL" + }, + { + "fieldname": "slug", + "fieldtype": "Data", + "label": "Slug" + }, + { + "fieldname": "image", + "fieldtype": "Attach Image", + "label": "Image" + } + ], + "index_web_pages_for_search": 1, + "links": [], + "modified": "2024-09-26 11:54:25.164154", + "modified_by": "Administrator", + "module": "digital_8848", + "name": "Insights", + "naming_rule": "Expression", + "owner": "Administrator", + "permissions": [ + { + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "System Manager", + "share": 1, + "write": 1 + } + ], + "sort_field": "modified", + "sort_order": "DESC", + "states": [] +} \ No newline at end of file diff --git a/digital_8848/digital_8848/doctype/insights/insights.py b/digital_8848/digital_8848/doctype/insights/insights.py new file mode 100644 index 0000000..d2b6054 --- /dev/null +++ b/digital_8848/digital_8848/doctype/insights/insights.py @@ -0,0 +1,9 @@ +# Copyright (c) 2024, digital_8848 and contributors +# For license information, please see license.txt + +# import frappe +from frappe.model.document import Document + + +class Insights(Document): + pass diff --git a/digital_8848/digital_8848/doctype/insights/test_insights.py b/digital_8848/digital_8848/doctype/insights/test_insights.py new file mode 100644 index 0000000..430e9f9 --- /dev/null +++ b/digital_8848/digital_8848/doctype/insights/test_insights.py @@ -0,0 +1,9 @@ +# Copyright (c) 2024, digital_8848 and Contributors +# See license.txt + +# import frappe +from frappe.tests.utils import FrappeTestCase + + +class TestInsights(FrappeTestCase): + pass