Skip to content

Commit

Permalink
Merge pull request #24 from 8848digital/insights_api
Browse files Browse the repository at this point in the history
feat: insights listing and details api
  • Loading branch information
aartimanjare authored Sep 26, 2024
2 parents 2151071 + 0d92eba commit e1f4fed
Show file tree
Hide file tree
Showing 7 changed files with 180 additions and 0 deletions.
Empty file.
39 changes: 39 additions & 0 deletions digital_8848/digital_8848/doctype/insights/api/insights_details.py
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 digital_8848/digital_8848/doctype/insights/api/insights_listing.py
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}
8 changes: 8 additions & 0 deletions digital_8848/digital_8848/doctype/insights/insights.js
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) {

// },
// });
79 changes: 79 additions & 0 deletions digital_8848/digital_8848/doctype/insights/insights.json
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": []
}
9 changes: 9 additions & 0 deletions digital_8848/digital_8848/doctype/insights/insights.py
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
9 changes: 9 additions & 0 deletions digital_8848/digital_8848/doctype/insights/test_insights.py
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

0 comments on commit e1f4fed

Please sign in to comment.