Skip to content

Commit

Permalink
[EASI-4635] Initial discussions API schema and migration (#2887)
Browse files Browse the repository at this point in the history
* initial discussions api schema and migration

* rename migration

* add new table to truncate lists

* formatting

* update postman, remove payload types, add constraint
  • Loading branch information
mynar7 authored Nov 15, 2024
1 parent 92c3f05 commit dcd703e
Show file tree
Hide file tree
Showing 10 changed files with 1,953 additions and 93 deletions.
109 changes: 106 additions & 3 deletions EASI.postman_collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -1000,7 +1000,7 @@
"listen": "test",
"script": {
"exec": [
"pm.collectionVariables.set(\"SystemIntakeGRBReviewerID\", pm.response.json().data.createSystemIntakeGRBReviewer.id)"
"pm.collectionVariables.set(\"SystemIntakeGRBReviewerID\", pm.response.json().data.createSystemIntakeGRBReviewers.reviewers[0].id)"
],
"type": "text/javascript",
"packages": {}
Expand All @@ -1013,8 +1013,8 @@
"body": {
"mode": "graphql",
"graphql": {
"query": "mutation createS($input: CreateSystemIntakeGRBReviewerInput!) {\n createSystemIntakeGRBReviewer(input: $input) {\n id\n userAccount {\n id\n }\n grbRole\n votingRole\n systemIntakeID\n createdBy\n createdAt\n modifiedBy\n modifiedAt\n }\n}",
"variables": "{\r\n \"input\": {\r\n \"euaUserId\": \"ABCD\",\r\n \"systemIntakeID\": \"8edb237e-ad48-49b2-91cf-8534362bc6cf\",\r\n \"votingRole\": \"NON_VOTING\",\r\n \"grbRole\": \"CMCS_REP\"\r\n }\r\n}"
"query": "mutation createSystemIntakeGRBReviewer($input: CreateSystemIntakeGRBReviewersInput!) {\n createSystemIntakeGRBReviewers(input: $input) {\n reviewers {\n id\n userAccount {\n id\n }\n grbRole\n votingRole\n systemIntakeID\n createdBy\n createdAt\n modifiedBy\n modifiedAt\n }\n \n }\n}",
"variables": "{\r\n \"input\": {\r\n \"systemIntakeID\": \"8edb237e-ad48-49b2-91cf-8534362bc6cf\",\r\n \"reviewers\": {\r\n \"euaUserId\": \"ABCD\",\r\n \"votingRole\": \"NON_VOTING\",\r\n \"grbRole\": \"CMCS_REP\"\r\n }\r\n }\r\n}"
}
},
"url": {
Expand Down Expand Up @@ -1124,6 +1124,105 @@
}
},
"response": []
},
{
"name": "Get GRB Discussions",
"event": [
{
"listen": "test",
"script": {
"exec": [
""
],
"type": "text/javascript",
"packages": {}
}
}
],
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "graphql",
"graphql": {
"query": "query getSystemIntakeGRBReviewers($systemIntakeID: UUID!) {\n systemIntake(id: $systemIntakeID) {\n id\n grbDiscussions {\n initialPost {\n content\n createdByUserAccount {\n givenName\n familyName\n }\n }\n replies {\n content\n createdByUserAccount {\n givenName\n familyName\n }\n }\n }\n }\n}",
"variables": "{\r\n \"systemIntakeID\": \"{{systemIntakeID}}\"\r\n}"
}
},
"url": {
"raw": "{{url}}",
"host": [
"{{url}}"
]
}
},
"response": []
},
{
"name": "Create GRB Discussion",
"event": [
{
"listen": "test",
"script": {
"exec": [
""
],
"type": "text/javascript",
"packages": {}
}
}
],
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "graphql",
"graphql": {
"query": "mutation createSystemIntakeGRBDiscussion($input: createSystemIntakeGRBDiscussionPostInput!) {\n createSystemIntakeGRBDiscussionPost(input: $input) {\n id\n content\n grbRole\n votingRole\n systemIntakeID\n createdByUserAccount {\n id\n username\n }\n }\n}",
"variables": "{\r\n \"input\": {\r\n \"systemIntakeID\": \"8edb237e-ad48-49b2-91cf-8534362bc6cf\",\r\n \"content\": \"<p>banana apple carburetor</p>\"\r\n }\r\n}"
}
},
"url": {
"raw": "{{url}}",
"host": [
"{{url}}"
]
}
},
"response": []
},
{
"name": "Add GRB Discussion Reply",
"event": [
{
"listen": "test",
"script": {
"exec": [
""
],
"type": "text/javascript",
"packages": {}
}
}
],
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "graphql",
"graphql": {
"query": "mutation createSystemIntakeGRBDiscussionReply($input: createSystemIntakeGRBDiscussionReplyInput!) {\n createSystemIntakeGRBDiscussionReply(input: $input) {\n id\n content\n grbRole\n votingRole\n systemIntakeID\n createdByUserAccount {\n id\n username\n }\n }\n}",
"variables": "{\r\n \"input\": {\r\n \"initialPostID\": \"00000000-0000-0000-0000-000000000000\",\r\n \"content\": \"<p>monkey kiwi phonebook</p>\"\r\n }\r\n}"
}
},
"url": {
"raw": "{{url}}",
"host": [
"{{url}}"
]
}
},
"response": []
}
]
},
Expand Down Expand Up @@ -4073,6 +4172,10 @@
{
"key": "CedarAtoIds",
"value": ""
},
{
"key": "SystemIntakeGRBReviewerID",
"value": ""
}
]
}
47 changes: 47 additions & 0 deletions migrations/V195__Add_grb_review_discussions_table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
CREATE TABLE IF NOT EXISTS system_intake_internal_grb_review_discussion_posts (
id UUID PRIMARY KEY NOT NULL,
content TEXT NOT NULL,
voting_role grb_reviewer_voting_role_type,
grb_role grb_reviewer_role_type,
system_intake_id UUID NOT NULL
REFERENCES system_intakes(id)
ON DELETE CASCADE
ON UPDATE CASCADE,
reply_to_id UUID
REFERENCES system_intake_internal_grb_review_discussion_posts (id)
ON DELETE CASCADE
ON UPDATE CASCADE,
created_by UUID NOT NULL REFERENCES user_account(id),
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
modified_by UUID REFERENCES user_account(id),
modified_at TIMESTAMP WITH TIME ZONE,
CONSTRAINT is_admin_or_reviewer CHECK (
(voting_role IS NULL AND grb_role IS NULL) OR
(voting_role IS NOT NULL AND grb_role IS NOT NULL)
)
);

CREATE OR REPLACE FUNCTION prevent_nested_replies_fn() RETURNS TRIGGER AS $$
DECLARE
parent_reply_to_id UUID;
BEGIN
-- If reply_to_id is not NULL, check if it points to a top-level post
IF NEW.reply_to_id IS NOT NULL THEN
-- Fetch the reply_to_id of the parent post
SELECT reply_to_id INTO parent_reply_to_id
FROM system_intake_internal_grb_review_discussion_posts
WHERE id = NEW.reply_to_id;

-- If parent_reply_to_id is NOT NULL, the parent post is a reply, so raise an error
IF parent_reply_to_id IS NOT NULL THEN
RAISE EXCEPTION 'Replies can only be made to top-level posts';
END IF;
END IF;

RETURN NEW;
END;
$$ LANGUAGE plpgsql;

CREATE TRIGGER prevent_nested_replies_trigger
BEFORE INSERT OR UPDATE ON system_intake_internal_grb_review_discussion_posts
FOR EACH ROW EXECUTE FUNCTION prevent_nested_replies_fn();
Loading

0 comments on commit dcd703e

Please sign in to comment.