From 3eade4d6d3a2f0f852d6d32daf642e150485f40e Mon Sep 17 00:00:00 2001 From: harisato Date: Fri, 28 Jul 2023 14:50:39 +0700 Subject: [PATCH] feat(hasura): update api --- .../punkga-pg/tables/public_manga.yaml | 7 + hasura/metadata/query_collections.yaml | 303 +++++++++--------- .../down.sql | 11 + .../up.sql | 9 + .../down.sql | 11 + .../up.sql | 9 + 6 files changed, 200 insertions(+), 150 deletions(-) create mode 100644 hasura/migrations/punkga-pg/1690529346372_add function nearest upcoming date in manga/down.sql create mode 100644 hasura/migrations/punkga-pg/1690529346372_add function nearest upcoming date in manga/up.sql create mode 100644 hasura/migrations/punkga-pg/1690529833409_add function nearest upcoming date in manga/down.sql create mode 100644 hasura/migrations/punkga-pg/1690529833409_add function nearest upcoming date in manga/up.sql diff --git a/hasura/metadata/databases/punkga-pg/tables/public_manga.yaml b/hasura/metadata/databases/punkga-pg/tables/public_manga.yaml index b20fbb73..4c287313 100644 --- a/hasura/metadata/databases/punkga-pg/tables/public_manga.yaml +++ b/hasura/metadata/databases/punkga-pg/tables/public_manga.yaml @@ -76,6 +76,11 @@ computed_fields: function: name: latest_published schema: public + - name: nearest_upcoming + definition: + function: + name: nearest_upcoming + schema: public select_permissions: - role: anonymous permission: @@ -90,6 +95,7 @@ select_permissions: - updated_at computed_fields: - latest_published + - nearest_upcoming filter: {} allow_aggregations: true - role: user @@ -105,5 +111,6 @@ select_permissions: - publish_date computed_fields: - latest_published + - nearest_upcoming filter: {} allow_aggregations: true diff --git a/hasura/metadata/query_collections.yaml b/hasura/metadata/query_collections.yaml index 6321e814..4cdfa56a 100644 --- a/hasura/metadata/query_collections.yaml +++ b/hasura/metadata/query_collections.yaml @@ -385,52 +385,6 @@ bio } } - - name: Public - Get subscribe list - query: | - query GetSubscribeList ($user_id: String = "") { - subscribers(order_by: {created_at:desc}, where: {_and:{user_id:{_eq:$user_id},subscribers_manga:{status:{_neq:"Removed"}}}}) { - subscribers_manga { - id - banner - status - manga_languages { - is_main_language - language_id - title - } - manga_creators { - creator { - id - name - isActive - } - } - chapters(order_by: {pushlish_date:desc_nulls_last}, limit: 1, where: {status:{_eq:"Published"}}) { - chapter_number - id - pushlish_date - } - chapters_aggregate { - aggregate { - sum { - likes - views - } - } - } - manga_tags { - tag { - id - tag_languages { - language_id - value - } - } - } - } - user_id - } - } - name: Admin - Get chapter detail query: | query GetChapterDetail ($manga_id: Int = 18, $chapter_number: Int = 1) { @@ -539,39 +493,6 @@ } } } - - name: Public - Get trending manga - query: | - query GetTrendingManga { - manga(order_by: {manga_total_views:{views:desc_nulls_last}}, limit: 4, where: {status:{_neq:"Removed"}}) { - id - chapters(limit: 1, order_by: {updated_at:desc}, where: {status:{_eq:"Published"}}) { - id - chapter_number - updated_at - } - manga_total_likes { - likes - } - manga_total_views { - views - } - manga_languages { - title - language_id - is_main_language - description - } - banner - poster - manga_creators { - creator { - name - id - isActive - } - } - } - } - name: Admin - Query List Manga query: | query QueryListManga { @@ -602,50 +523,6 @@ } } } - - name: Public - Get manga list by list id - query: | - query GetListMangaById ($id: [Int!]) { - manga(where: {_and:{id:{_in:$id},status:{_neq:"Removed"}}}) { - id - banner - poster - status - manga_languages { - is_main_language - language_id - title - } - manga_creators { - creator { - id - name - isActive - } - } - chapters(order_by: {pushlish_date:desc_nulls_last}, limit: 1, where: {status:{_eq:"Published"}}) { - chapter_number - id - pushlish_date - } - chapters_aggregate { - aggregate { - sum { - likes - views - } - } - } - manga_tags(limit: 5) { - tag { - id - tag_languages { - language_id - value - } - } - } - } - } - name: Public - Get manga detail query: | query GetMangaReadingDetail ($id: Int = 1, $user_id: String = "") { @@ -760,6 +637,133 @@ } } } + - name: Public - Get chapter detail + query: | + query GetChapterReadingDetail ($manga_id: Int = 18, $chapter_number: Int = 1, $user_id: String = "") { + chapters(where: {_and:{chapter_number:{_eq:$chapter_number},manga:{_and:{id:{_eq:$manga_id},_or:[{status:{_ilike:"On-going"}},{status:{_eq:"Finished"}}]}}}}) { + id + chapter_number + chapter_name + chapter_type + thumbnail_url + status + pushlish_date + chapter_languages(where: {chapter:{status:{_eq:"Published"}}}) { + language_id + detail + } + comments: social_activities_aggregate { + aggregate { + count + } + } + views + chapters_likes_aggregate { + aggregate { + count + } + } + chapters_likes(where: {user_id:{_eq:$user_id}}) { + id + created_at + user_id + chapter_id + } + } + } + - name: Public - Get manga list by list id + query: | + query GetListMangaById ($id: [Int!]) { + manga(where: {_and:{id:{_in:$id},status:{_neq:"Removed"}}}) { + id + banner + poster + status + nearest_upcoming + manga_languages { + is_main_language + language_id + title + } + manga_creators { + creator { + id + name + isActive + } + } + chapters(order_by: {chapter_number:desc_nulls_last}, limit: 1, where: {status:{_eq:"Published"}}) { + chapter_number + id + pushlish_date + } + chapters_aggregate { + aggregate { + sum { + likes + views + } + } + } + manga_tags(limit: 5) { + tag { + id + tag_languages { + language_id + value + } + } + } + } + } + - name: Public - Get subscribe list + query: | + query GetSubscribeList ($user_id: String = "") { + subscribers(order_by: {created_at:desc}, where: {_and:{user_id:{_eq:$user_id},subscribers_manga:{status:{_neq:"Removed"}}}}) { + subscribers_manga { + id + banner + poster + status + nearest_upcoming + manga_languages { + is_main_language + language_id + title + } + manga_creators { + creator { + id + name + isActive + } + } + chapters(order_by: {chapter_number:desc_nulls_last}, limit: 1, where: {status:{_eq:"Published"}}) { + chapter_number + id + pushlish_date + } + chapters_aggregate { + aggregate { + sum { + likes + views + } + } + } + manga_tags { + tag { + id + tag_languages { + language_id + value + } + } + } + } + user_id + } + } - name: Public - Query latest update manga query: | query GetLatestUpdatedManga { @@ -780,7 +784,7 @@ } } status - chapters(limit: 1, order_by: {pushlish_date:desc}, where: {status:{_eq:"Published"}}) { + chapters(limit: 1, order_by: {chapter_number:desc}, where: {status:{_eq:"Published"}}) { id chapter_number pushlish_date @@ -807,37 +811,36 @@ poster } } - - name: Public - Get chapter detail + - name: Public - Get trending manga query: | - query GetChapterReadingDetail ($manga_id: Int = 18, $chapter_number: Int = 1, $user_id: String = "") { - chapters(where: {_and:{chapter_number:{_eq:$chapter_number},manga:{_and:{id:{_eq:$manga_id},_or:[{status:{_ilike:"On-going"}},{status:{_eq:"Finished"}}]}}}}) { + query GetTrendingManga { + manga(order_by: {manga_total_views:{views:desc_nulls_last}}, limit: 4, where: {status:{_neq:"Removed"}}) { id - chapter_number - chapter_name - chapter_type - thumbnail_url - status - pushlish_date - chapter_languages(where: {chapter:{status:{_eq:"Published"}}}) { - language_id - detail + chapters(limit: 1, order_by: {chapter_number:desc}, where: {status:{_eq:"Published"}}) { + id + chapter_number + updated_at } - comments: social_activities_aggregate { - aggregate { - count - } + manga_total_likes { + likes } - views - chapters_likes_aggregate { - aggregate { - count - } + manga_total_views { + views } - chapters_likes(where: {user_id:{_eq:$user_id}}) { - id - created_at - user_id - chapter_id + manga_languages { + title + language_id + is_main_language + description + } + banner + poster + manga_creators { + creator { + name + id + isActive + } } } } diff --git a/hasura/migrations/punkga-pg/1690529346372_add function nearest upcoming date in manga/down.sql b/hasura/migrations/punkga-pg/1690529346372_add function nearest upcoming date in manga/down.sql new file mode 100644 index 00000000..e20c7066 --- /dev/null +++ b/hasura/migrations/punkga-pg/1690529346372_add function nearest upcoming date in manga/down.sql @@ -0,0 +1,11 @@ +-- Could not auto-generate a down migration. +-- Please write an appropriate down migration for the SQL below: +-- CREATE OR REPLACE FUNCTION nearest_upcoming(manga_row manga) RETURNS +-- timestamp with time zone +-- AS $$ +-- SELECT pushlish_date +-- FROM chapters +-- WHERE chapters.manga_id = manga_row.id AND chapters.status = 'Upcoming' +-- ORDER BY pushlish_date ASC NULLS LAST +-- LIMIT 1 +-- $$ LANGUAGE sql STABLE; diff --git a/hasura/migrations/punkga-pg/1690529346372_add function nearest upcoming date in manga/up.sql b/hasura/migrations/punkga-pg/1690529346372_add function nearest upcoming date in manga/up.sql new file mode 100644 index 00000000..0db978df --- /dev/null +++ b/hasura/migrations/punkga-pg/1690529346372_add function nearest upcoming date in manga/up.sql @@ -0,0 +1,9 @@ +CREATE OR REPLACE FUNCTION nearest_upcoming(manga_row manga) RETURNS +timestamp with time zone +AS $$ + SELECT pushlish_date + FROM chapters + WHERE chapters.manga_id = manga_row.id AND chapters.status = 'Upcoming' + ORDER BY pushlish_date ASC NULLS LAST + LIMIT 1 +$$ LANGUAGE sql STABLE; diff --git a/hasura/migrations/punkga-pg/1690529833409_add function nearest upcoming date in manga/down.sql b/hasura/migrations/punkga-pg/1690529833409_add function nearest upcoming date in manga/down.sql new file mode 100644 index 00000000..1afb2fe8 --- /dev/null +++ b/hasura/migrations/punkga-pg/1690529833409_add function nearest upcoming date in manga/down.sql @@ -0,0 +1,11 @@ +-- Could not auto-generate a down migration. +-- Please write an appropriate down migration for the SQL below: +-- CREATE OR REPLACE FUNCTION nearest_upcoming(manga_row manga) RETURNS +-- timestamp with time zone +-- AS $$ +-- SELECT pushlish_date +-- FROM chapters +-- WHERE chapters.manga_id = manga_row.id AND chapters.status = 'Upcoming' AND chapters.pushlish_date > now() +-- ORDER BY pushlish_date ASC NULLS LAST +-- LIMIT 1 +-- $$ LANGUAGE sql STABLE; diff --git a/hasura/migrations/punkga-pg/1690529833409_add function nearest upcoming date in manga/up.sql b/hasura/migrations/punkga-pg/1690529833409_add function nearest upcoming date in manga/up.sql new file mode 100644 index 00000000..db7949dc --- /dev/null +++ b/hasura/migrations/punkga-pg/1690529833409_add function nearest upcoming date in manga/up.sql @@ -0,0 +1,9 @@ +CREATE OR REPLACE FUNCTION nearest_upcoming(manga_row manga) RETURNS +timestamp with time zone +AS $$ + SELECT pushlish_date + FROM chapters + WHERE chapters.manga_id = manga_row.id AND chapters.status = 'Upcoming' AND chapters.pushlish_date > now() + ORDER BY pushlish_date ASC NULLS LAST + LIMIT 1 +$$ LANGUAGE sql STABLE;