From 7708b0490b8650551bbc507a48604d2fe7420134 Mon Sep 17 00:00:00 2001 From: Sara Lago Date: Tue, 17 Oct 2023 11:14:33 +0200 Subject: [PATCH] [ADD] pms_api_rest: add rss_post service, datamodel and add feed_rss module in pms_api_rest depends --- pms_api_rest/__manifest__.py | 1 + pms_api_rest/datamodels/__init__.py | 2 ++ pms_api_rest/datamodels/feed_post.py | 15 +++++++++ pms_api_rest/services/__init__.py | 1 + pms_api_rest/services/feed_post_service.py | 39 ++++++++++++++++++++++ 5 files changed, 58 insertions(+) create mode 100644 pms_api_rest/datamodels/feed_post.py create mode 100644 pms_api_rest/services/feed_post_service.py diff --git a/pms_api_rest/__manifest__.py b/pms_api_rest/__manifest__.py index 1f338e16c8..a6d0469a46 100644 --- a/pms_api_rest/__manifest__.py +++ b/pms_api_rest/__manifest__.py @@ -15,6 +15,7 @@ "base_location", "l10n_es_aeat", "sql_export_excel", + "feed_rss", ], "external_dependencies": { "python": ["jwt", "simplejson", "marshmallow", "jose"], diff --git a/pms_api_rest/datamodels/__init__.py b/pms_api_rest/datamodels/__init__.py index 2108ac656f..7c4f399dbb 100644 --- a/pms_api_rest/datamodels/__init__.py +++ b/pms_api_rest/datamodels/__init__.py @@ -61,3 +61,5 @@ from . import pms_reservation_message from . import pms_avail from . import pms_dashboard +from . import feed_post + diff --git a/pms_api_rest/datamodels/feed_post.py b/pms_api_rest/datamodels/feed_post.py new file mode 100644 index 0000000000..a44e02a0d0 --- /dev/null +++ b/pms_api_rest/datamodels/feed_post.py @@ -0,0 +1,15 @@ +from marshmallow import fields + +from odoo.addons.datamodel.core import Datamodel + + +class FeedPost(Datamodel): + _name ="feed.post.info" + postId = fields.String(required=True, allow_none=False) + title = fields.String(required=True, allow_none=False) + link = fields.String(required=True, allow_none=False) + description = fields.String(required=True, allow_none=False) + publishDate = fields.String(required=True, allow_none=False) + author = fields.String(required=True, allow_none=False) + imageUrl = fields.String(required=True, allow_none=False) + diff --git a/pms_api_rest/services/__init__.py b/pms_api_rest/services/__init__.py index 4d43a7359d..f280265d15 100644 --- a/pms_api_rest/services/__init__.py +++ b/pms_api_rest/services/__init__.py @@ -43,3 +43,4 @@ from . import pms_avail_service from . import pms_user_service from . import pms_dashboard_service +from . import feed_post_service diff --git a/pms_api_rest/services/feed_post_service.py b/pms_api_rest/services/feed_post_service.py new file mode 100644 index 0000000000..3fd605ca57 --- /dev/null +++ b/pms_api_rest/services/feed_post_service.py @@ -0,0 +1,39 @@ +from odoo.addons.base_rest import restapi +from odoo.addons.base_rest_datamodel.restapi import Datamodel +from odoo.addons.component.core import Component + + +class PmsFeedRss(Component): + _inherit = "base.rest.service" + _name = "pms.feed.rss.service" + _usage = "feed-posts" + _collection = "pms.services" + + @restapi.method( + [ + ( + [ + "/", + ], + "GET", + ) + ], + output_param=Datamodel("feed.post.info", is_list=True), + auth="jwt_api_pms", + ) + def get_feed_posts(self): + result_rss = [] + PmsFeedRss = self.env.datamodels["feed.post.info"] + for rss in self.env["rss.post"].search([], limit=5, order='publish_date desc'): + result_rss.append( + PmsFeedRss( + postId=rss.post_id, + title=rss.title, + link=rss.link, + description=rss.description, + publishDate=str(rss.publish_date), + author=rss.author if rss.author else "", + imageUrl=rss.image_url if rss.image_url else "", + ) + ) + return result_rss