Skip to content

Commit

Permalink
[ADD] pms_api_rest: add rss_post service, datamodel and add feed_rss …
Browse files Browse the repository at this point in the history
…module in pms_api_rest depends
  • Loading branch information
saralb9 authored and DarioLodeiros committed Oct 17, 2023
1 parent 0440003 commit 7708b04
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 0 deletions.
1 change: 1 addition & 0 deletions pms_api_rest/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"base_location",
"l10n_es_aeat",
"sql_export_excel",
"feed_rss",
],
"external_dependencies": {
"python": ["jwt", "simplejson", "marshmallow", "jose"],
Expand Down
2 changes: 2 additions & 0 deletions pms_api_rest/datamodels/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,5 @@
from . import pms_reservation_message
from . import pms_avail
from . import pms_dashboard
from . import feed_post

15 changes: 15 additions & 0 deletions pms_api_rest/datamodels/feed_post.py
Original file line number Diff line number Diff line change
@@ -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)

1 change: 1 addition & 0 deletions pms_api_rest/services/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,4 @@
from . import pms_avail_service
from . import pms_user_service
from . import pms_dashboard_service
from . import feed_post_service
39 changes: 39 additions & 0 deletions pms_api_rest/services/feed_post_service.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 7708b04

Please sign in to comment.