Skip to content

Commit

Permalink
Merge branch 'feat/phase-2' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
harisato committed Oct 11, 2023
2 parents e097f3c + 97c3300 commit 5ef5b8f
Show file tree
Hide file tree
Showing 21 changed files with 320 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
table:
name: bookshelf
schema: public
object_relationships:
- name: manga
using:
foreign_key_constraint_on: manga_id
insert_permissions:
- role: user
permission:
Expand Down
11 changes: 11 additions & 0 deletions hasura/metadata/databases/punkga-pg/tables/public_campaign.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
table:
name: campaign
schema: public
array_relationships:
- name: campaign_quests
using:
foreign_key_constraint_on:
column: campaign_id
table:
name: quests
schema: public
7 changes: 0 additions & 7 deletions hasura/metadata/databases/punkga-pg/tables/public_manga.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,6 @@ object_relationships:
name: manga_total_views
schema: public
array_relationships:
- name: bookshelves
using:
foreign_key_constraint_on:
column: manga_id
table:
name: bookshelf
schema: public
- name: chapters
using:
foreign_key_constraint_on:
Expand Down
7 changes: 7 additions & 0 deletions hasura/metadata/databases/punkga-pg/tables/public_quests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
table:
name: quests
schema: public
object_relationships:
- name: quests_campaign
using:
foreign_key_constraint_on: campaign_id
3 changes: 2 additions & 1 deletion hasura/metadata/databases/punkga-pg/tables/tables.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
- "!include public_authorizer_sessions.yaml"
- "!include public_authorizer_users.yaml"
- "!include public_authorizer_verification_requests.yaml"
- "!include public_bookshelf.yaml"
- "!include public_campaign.yaml"
- "!include public_chapter_languages.yaml"
- "!include public_chapter_total_likes.yaml"
- "!include public_chapters.yaml"
Expand All @@ -15,6 +15,7 @@
- "!include public_manga_tag.yaml"
- "!include public_manga_total_likes.yaml"
- "!include public_manga_total_views.yaml"
- "!include public_quests.yaml"
- "!include public_social_activities.yaml"
- "!include public_subscribers.yaml"
- "!include public_tag_languages.yaml"
Expand Down
137 changes: 137 additions & 0 deletions hasura/metadata/query_collections.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -829,3 +829,140 @@
user_id
}
}
- name: Admin - Query all campaign
query: |
query campaign {
campaign {
created_at
end_date
id
name
start_date
updated_at
campaign_quests_aggregate(where: {status:{_eq:"Publish"}}) {
aggregate {
count
}
}
}
}
- name: Admin - Query campaign detail
query: |
query campaign_by_pk ($id: Int!) {
campaign_by_pk(id: $id) {
created_at
updated_at
id
name
start_date
end_date
campaign_quests {
created_at
updated_at
id
name
type
condition
reward
status
}
}
}
- name: Admin - Delete campaign
query: |
mutation delete_campaign_by_pk ($id: Int!) {
delete_quests(where: {campaign_id:{_eq:$id}}) {
affected_rows
}
delete_campaign_by_pk(id: $id) {
id
}
}
- name: Admin - Create Campaign
query: |
mutation insert_campaign_one ($name: String = "", $start_date: timestamptz = "", $end_date: timestamptz = "") {
insert_campaign(objects: {name:$name,start_date:$start_date,end_date:$end_date}) {
returning {
id
name
start_date
end_date
}
}
}
- name: Admin - Update campaign
query: |
mutation update_campaign ($id: Int!, $name: String = "", $start_date: timestamptz = "", $end_date: timestamptz = "") {
update_campaign(where: {id:{_eq:$id}}, _set: {name:$name,start_date:$start_date,end_date:$end_date}) {
returning {
id
name
start_date
end_date
updated_at
}
affected_rows
}
}
- name: Admin - Create Quest
query: |
mutation insert_quests ($name: String = "", $type: String = "", $condition: jsonb = "", $requirement: jsonb = "", $reward: jsonb = "", $status: String = "", $campaign_id: Int = 10) {
insert_quests(objects: {name:$name,type:$type,condition:$condition,requirement:$requirement,reward:$reward,status:$status,campaign_id:$campaign_id}) {
affected_rows
returning {
id
name
campaign_id
status
}
}
}
- name: Admin - Get quest by id
query: |
query quests_by_pk ($id: Int!) {
quests_by_pk(id: $id) {
campaign_id
condition
created_at
id
name
requirement
reward
status
type
updated_at
quests_campaign {
name
created_at
}
}
}
- name: Admin - Update quest
query: |
mutation update_quests ($name: String = "", $type: String = "", $condition: jsonb = "", $requirement: jsonb = "", $reward: jsonb = "", $status: String = "", $id: Int!) {
update_quests(where: {id:{_eq:$id}}, _set: {name:$name,type:$type,condition:$condition,requirement:$requirement,reward:$reward,status:$status}) {
affected_rows
returning {
id
name
status
updated_at
}
}
}
- name: Admin - Delete quest
query: |
mutation delete_quests_by_pk ($id: Int!) {
delete_quests_by_pk(id: $id) {
campaign_id
condition
created_at
id
name
requirement
reward
status
type
updated_at
}
}
81 changes: 81 additions & 0 deletions hasura/metadata/rest_endpoints.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,48 @@
- comment: ""
definition:
query:
collection_name: allowed-queries
query_name: Admin - Query all campaign
methods:
- GET
name: Admin - Query all campaign
url: admin/campaign
- comment: ""
definition:
query:
collection_name: allowed-queries
query_name: Admin - Create Campaign
methods:
- POST
name: Admin - Create Campaign
url: admin/campaign
- comment: ""
definition:
query:
collection_name: allowed-queries
query_name: Admin - Query campaign detail
methods:
- GET
name: Admin - Query campaign detail
url: admin/campaign/:id
- comment: ""
definition:
query:
collection_name: allowed-queries
query_name: Admin - Delete campaign
methods:
- DELETE
name: Admin - Delete campaign
url: admin/campaign/:id
- comment: ""
definition:
query:
collection_name: allowed-queries
query_name: Admin - Update campaign
methods:
- PUT
name: Admin - Update campaign
url: admin/campaign/:id
- comment: ""
definition:
query:
Expand Down Expand Up @@ -79,6 +124,42 @@
- GET
name: Admin - Get chapter detail
url: admin/manga/:manga_id/chapters/:chapter_number
- comment: ""
definition:
query:
collection_name: allowed-queries
query_name: Admin - Create Quest
methods:
- POST
name: Admin - Create Quest
url: admin/quests
- comment: ""
definition:
query:
collection_name: allowed-queries
query_name: Admin - Get quest by id
methods:
- GET
name: Admin - Get quest by id
url: admin/quests/:id
- comment: ""
definition:
query:
collection_name: allowed-queries
query_name: Admin - Update quest
methods:
- PUT
name: Admin - Update quest
url: admin/quests/:id
- comment: ""
definition:
query:
collection_name: allowed-queries
query_name: Admin - Delete quest
methods:
- DELETE
name: Admin - Delete quest
url: admin/quests/:id
- comment: ""
definition:
query:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP TABLE "public"."quests";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE TABLE "public"."quests" ("id" serial NOT NULL, "name" text NOT NULL, "type" text NOT NULL, "condition" jsonb NOT NULL, "requirement" jsonb NOT NULL, "reward" jsonb NOT NULL, "status" text NOT NULL, PRIMARY KEY ("id") );
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP TABLE "public"."campaign";
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
CREATE TABLE "public"."campaign" ("id" serial NOT NULL, "name" text NOT NULL, "start_date" timestamptz NOT NULL, "end_date" timestamptz NOT NULL, "created_at" timestamptz NOT NULL DEFAULT now(), "updated_at" timestamptz NOT NULL DEFAULT now(), PRIMARY KEY ("id") );
CREATE OR REPLACE FUNCTION "public"."set_current_timestamp_updated_at"()
RETURNS TRIGGER AS $$
DECLARE
_new record;
BEGIN
_new := NEW;
_new."updated_at" = NOW();
RETURN _new;
END;
$$ LANGUAGE plpgsql;
CREATE TRIGGER "set_public_campaign_updated_at"
BEFORE UPDATE ON "public"."campaign"
FOR EACH ROW
EXECUTE PROCEDURE "public"."set_current_timestamp_updated_at"();
COMMENT ON TRIGGER "set_public_campaign_updated_at" ON "public"."campaign"
IS 'trigger to set value of column "updated_at" to current timestamp on row update';
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-- Could not auto-generate a down migration.
-- Please write an appropriate down migration for the SQL below:
-- DROP table "public"."bookshelf";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP table "public"."bookshelf";
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- Could not auto-generate a down migration.
-- Please write an appropriate down migration for the SQL below:
-- alter table "public"."quests" add column "campaign_id" integer
-- not null;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
alter table "public"."quests" add column "campaign_id" integer
not null;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table "public"."quests" drop constraint "quests_campaign_id_fkey";
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
alter table "public"."quests"
add constraint "quests_campaign_id_fkey"
foreign key ("campaign_id")
references "public"."campaign"
("id") on update restrict on delete restrict;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- Could not auto-generate a down migration.
-- Please write an appropriate down migration for the SQL below:
-- alter table "public"."quests" add column "created_at" timestamptz
-- null default now();
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
alter table "public"."quests" add column "created_at" timestamptz
null default now();
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
-- Could not auto-generate a down migration.
-- Please write an appropriate down migration for the SQL below:
-- alter table "public"."quests" add column "updated_at" timestamptz
-- null default now();
--
-- CREATE OR REPLACE FUNCTION "public"."set_current_timestamp_updated_at"()
-- RETURNS TRIGGER AS $$
-- DECLARE
-- _new record;
-- BEGIN
-- _new := NEW;
-- _new."updated_at" = NOW();
-- RETURN _new;
-- END;
-- $$ LANGUAGE plpgsql;
-- CREATE TRIGGER "set_public_quests_updated_at"
-- BEFORE UPDATE ON "public"."quests"
-- FOR EACH ROW
-- EXECUTE PROCEDURE "public"."set_current_timestamp_updated_at"();
-- COMMENT ON TRIGGER "set_public_quests_updated_at" ON "public"."quests"
-- IS 'trigger to set value of column "updated_at" to current timestamp on row update';
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
alter table "public"."quests" add column "updated_at" timestamptz
null default now();

CREATE OR REPLACE FUNCTION "public"."set_current_timestamp_updated_at"()
RETURNS TRIGGER AS $$
DECLARE
_new record;
BEGIN
_new := NEW;
_new."updated_at" = NOW();
RETURN _new;
END;
$$ LANGUAGE plpgsql;
CREATE TRIGGER "set_public_quests_updated_at"
BEFORE UPDATE ON "public"."quests"
FOR EACH ROW
EXECUTE PROCEDURE "public"."set_current_timestamp_updated_at"();
COMMENT ON TRIGGER "set_public_quests_updated_at" ON "public"."quests"
IS 'trigger to set value of column "updated_at" to current timestamp on row update';

0 comments on commit 5ef5b8f

Please sign in to comment.