From 009c7621ce28710264042539b264e30e74ca46ae Mon Sep 17 00:00:00 2001 From: tuz666 Date: Fri, 4 Mar 2022 23:25:27 +0100 Subject: [PATCH] added /show/schedule_by: this returns shows by day with the latest already premiered episode updated swagger docs --- arcsi/api/show.py | 28 ++++++++++++++++++++-------- arcsi/static/component.json | 23 ++++++++++++++++++++++- arcsi/static/doc.json | 34 +++++++++++++++++++++++++++++++++- 3 files changed, 75 insertions(+), 10 deletions(-) diff --git a/arcsi/api/show.py b/arcsi/api/show.py index ecba5483..923a2d86 100644 --- a/arcsi/api/show.py +++ b/arcsi/api/show.py @@ -70,14 +70,14 @@ def make_show(self, data, **kwargs): show_schema = ShowDetailsSchema() show_archive_schema = ShowDetailsSchema(only=("id", "active", "name", "description", "cover_image_url", "day", "start", "end", "frequency", "language", - "archive_lahmastore_base_url", "items")) + "playlist_name", "archive_lahmastore_base_url", "items")) show_partial_schema = ShowDetailsSchema(partial=True) shows_schema = ShowDetailsSchema(many=True) shows_schedule_schema = ShowDetailsSchema(many=True, exclude=("items",)) -shows_schedule2_schema = ShowDetailsSchema(many=True, +shows_schedule_by_schema = ShowDetailsSchema(many=True, only=("id", "active", "name", "description", "cover_image_url", "day", "start", "end", "frequency", "language", - "archive_lahmastore_base_url", "items")) + "playlist_name", "archive_lahmastore_base_url", "items")) shows_archive_schema = ShowDetailsSchema(many=True, only=("id", "active", "name", "description", "cover_image_url", "playlist_name", "archive_lahmastore_base_url")) @@ -94,15 +94,27 @@ def list_shows(): @arcsi.route("/show/schedule", methods=["GET"]) def list_shows_for_schedule(): - return shows_schedule_schema.dumps(get_shows()) + do = DoArchive() + shows = Show.query.filter(Show.active == True).all() + for show in shows: + if show.cover_image_url: + show.cover_image_url = do.download( + show.archive_lahmastore_base_url, show.cover_image_url + ) + return shows_schedule_schema.dumps(shows) -@arcsi.route("/show/schedule2", methods=["GET"]) -def list_shows_for_schedule2(): +@arcsi.route("/show/schedule_by", methods=["GET"]) +def list_shows_for_schedule_by(): do = DoArchive() - shows = Show.query.all() - shows_json = shows_schedule2_schema.dump(shows) + day = request.args.get('day', 1, type=int) + shows = Show.query.filter(Show.day == day and Show.active == True).all() + shows_json = shows_schedule_by_schema.dump(shows) # iterate through shows for show_json in shows_json: + if show_json["cover_image_url"]: + show_json["cover_image_url"] = do.download( + show_json["archive_lahmastore_base_url"], show_json["cover_image_url"] + ) if show_json["items"]: latest_item_found = False # iterate through show's items diff --git a/arcsi/static/component.json b/arcsi/static/component.json index 18309b3d..ae2efcab 100644 --- a/arcsi/static/component.json +++ b/arcsi/static/component.json @@ -37,6 +37,10 @@ "name": { "type": "string", "example": "show-name" + }, + "archive_lahmastore_base_url": { + "type": "string", + "example": "show-archive_lahmastore_base_url" } } }, @@ -50,6 +54,10 @@ "type": "string", "example": "item-name" }, + "name_slug": { + "type": "string", + "example": "item-name" + }, "description": { "type": "string", "example": "item-description" @@ -337,6 +345,10 @@ "end": { "type": "string" }, + "id": { + "type": "integer", + "format": "int32" + }, "day": { "type": "integer", "format": "int32" @@ -348,7 +360,7 @@ "items": { "type": "object", "additionalProperties": { - "$ref": "#/components/schemas/ItemBasicRequest" + "$ref": "#/components/schemas/item" } } } @@ -484,6 +496,9 @@ "name": { "type": "string" }, + "name_slug": { + "type": "string" + }, "description": { "type": "string" }, @@ -538,6 +553,9 @@ "name": { "type": "string" }, + "name_slug": { + "type": "string" + }, "description": { "type": "string" }, @@ -583,6 +601,9 @@ "name": { "type": "string" }, + "name_slug": { + "type": "string" + }, "description": { "type": "string" }, diff --git a/arcsi/static/doc.json b/arcsi/static/doc.json index 72a5f212..692022a8 100644 --- a/arcsi/static/doc.json +++ b/arcsi/static/doc.json @@ -250,6 +250,38 @@ } } }, + "/show/schedule_by?day={day}": { + "get": { + "tags": [ + "Show Requests for frontend" + ], + "summary": "Return Shows for Ananasz Home and Schedule Page", + "parameters": [ + { + "in": "path", + "name": "day", + "required": true, + "description": "day, default: 1", + "type": "number" + } + ], + "produces": [ + "text/html" + ], + "responses": { + "200": { + "description": "OK", + "content": { + "text/html": { + "schema": { + "$ref": "component.json#/components/schemas/ShowScheduleResponseBodies" + } + } + } + } + } + } + }, "/show/{show_slug}/page": { "get": { "tags": [ @@ -483,7 +515,7 @@ "in": "path", "name": "episode_slug", "required": true, - "description": "Item.play_file_name + '.mp3'", + "description": "normalize(Item.name) --> name_slug", "type": "string" } ],