-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from 8848digital/insights_api
feat: insights listing and details api
- Loading branch information
Showing
7 changed files
with
180 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
39 changes: 39 additions & 0 deletions
39
digital_8848/digital_8848/doctype/insights/api/insights_details.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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} |
36 changes: 36 additions & 0 deletions
36
digital_8848/digital_8848/doctype/insights/api/insights_listing.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) { | ||
|
||
// }, | ||
// }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |