Skip to content

Commit 0fc5292

Browse files
committed
Rename posts to tasks
1 parent 383b173 commit 0fc5292

28 files changed

Lines changed: 519 additions & 367 deletions

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ One of the best ways to write a feature is in user story format:
3232
3333
For example, let's say we wanted to write some Slack integration for new comments posted to a Code Corps project. That user story might look something like:
3434

35-
> As a project maintainer, I want to see new comments on my project post in my Slack channel so that everyone can see and react to some of the latest changes in the project.
35+
> As a project maintainer, I want to see new comments on my project task in my Slack channel so that everyone can see and react to some of the latest changes in the project.
3636
3737
You may want to go deeper into detail. Posting screenshots of designs or expected test cases and scenarios are even more helpful. Place yourself in the shoes of the person who's going to accomplish the task – even if that person is you. What steps should I be taking next to finish this task?
3838

blueprint/api.apib

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,11 @@ Exchange email and password for `token`.
148148

149149
+ Attributes (Comments Response)
150150

151-
## List comments for a specified post [GET /posts/{number}/comments]
151+
## List comments for a specified task [GET /tasks/{number}/comments]
152152

153153
+ Parameters
154154

155-
+ number: 1 (number, required) - Post number, uniquely identifying a post
155+
+ number: 1 (number, required) - Task number, uniquely identifying a task
156156

157157
+ Request
158158

@@ -436,11 +436,11 @@ Write privileges are for admin users only, read can be accessable by any user.
436436

437437
+ Attributes (Unprocessable Entity Response)
438438

439-
# Group Posts
439+
# Group Tasks
440440

441-
## Posts [/posts]
441+
## Tasks [/tasks]
442442

443-
### Create a post [POST]
443+
### Create a task [POST]
444444

445445
+ Request
446446

@@ -451,13 +451,13 @@ Write privileges are for admin users only, read can be accessable by any user.
451451

452452
+ Response 201 (application/json)
453453

454-
+ Attributes (Post Response)
454+
+ Attributes (Task Response)
455455

456456
+ Response 422 (application/json)
457457

458458
+ Attributes (Unprocessable Entity Response)
459459

460-
### List all posts [GET]
460+
### List all tasks [GET]
461461

462462
+ Request
463463

@@ -468,15 +468,15 @@ Write privileges are for admin users only, read can be accessable by any user.
468468

469469
+ Response 200 (application/json)
470470

471-
+ Attributes (Posts Response)
471+
+ Attributes (Tasks Response)
472472

473-
## Post [/posts/{id}]
473+
## Task [/tasks/{id}]
474474

475-
### Retrieve a post [GET /posts/{id}]
475+
### Retrieve a task [GET /tasks/{id}]
476476

477477
+ Parameters
478478

479-
+ id (number) - Id of a post.
479+
+ id (number) - Id of a task.
480480

481481
+ Request
482482

@@ -487,17 +487,17 @@ Write privileges are for admin users only, read can be accessable by any user.
487487

488488
+ Response 200 (application/json)
489489

490-
+ Attributes (Post Response)
490+
+ Attributes (Task Response)
491491

492492
+ Response 404 (application/json)
493493

494494
+ Attributes (Record Not Found Response)
495495

496-
### Update a post [PATCH /posts/{id}]
496+
### Update a task [PATCH /tasks/{id}]
497497

498498
+ Parameters
499499

500-
+ id (number) - Id of a post.
500+
+ id (number) - Id of a task.
501501

502502
+ Request
503503

@@ -508,7 +508,7 @@ Write privileges are for admin users only, read can be accessable by any user.
508508

509509
+ Response 201 (application/json)
510510

511-
+ Attributes (Post Response)
511+
+ Attributes (Task Response)
512512

513513
+ Response 204 (application/json)
514514

@@ -1358,8 +1358,8 @@ This resource identifies a relationship between a User and a Skill. For example,
13581358
+ include Comment Resource Identifier
13591359
+ attributes(Comment Attributes)
13601360
+ relationships
1361-
+ posts
1362-
+ data(Post Resource Identifier)
1361+
+ tasks
1362+
+ data(Task Resource Identifier)
13631363
+ links (object)
13641364
+ users
13651365
+ data(User Resource Identifier)
@@ -1387,8 +1387,8 @@ This resource identifies a relationship between a User and a Skill. For example,
13871387
+ attributes
13881388
+ markdown: `Markdown formatted string` (string)
13891389
+ relationships
1390-
+ posts
1391-
+ data(Post Resource Identifier)
1390+
+ tasks
1391+
+ data(Task Resource Identifier)
13921392

13931393
## Comment Update Request (object)
13941394
+ include Comment Resource Identifier
@@ -1581,21 +1581,21 @@ This resource identifies a relationship between a User and a Skill. For example,
15811581
+ include Organization Membership Resource Identifier
15821582
+ attributes(Organization Membership Attributes)
15831583

1584-
## Post Resource Identifier
1584+
## Task Resource Identifier
15851585
+ id: `1` (string)
1586-
+ type: `post` (string)
1586+
+ type: `task` (string)
15871587

1588-
## Post Response (object)
1588+
## Task Response (object)
15891589
+ id: 1 (string)
15901590
+ status: `open` (string)
1591-
+ post_type: `task` (string)
1592-
+ title: `This is the title of a post` (string)
1593-
+ body: `This is the body of of a post filled with lots of awesome details` (string)
1591+
+ task_type: `task` (string)
1592+
+ title: `This is the title of a task` (string)
1593+
+ body: `This is the body of of a task filled with lots of awesome details` (string)
15941594
+ user_id: 1 (string)
15951595

1596-
## Posts Response (object)
1597-
+ posts
1598-
+ data(array[Post Response], required)
1596+
## Tasks Response (object)
1597+
+ tasks
1598+
+ data(array[Task Response], required)
15991599

16001600
## Preview (object)
16011601
+ body: `<p>A <strong>strong</strong> preview</p>` (string)

lib/code_corps/analytics/segment.ex

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
defmodule CodeCorps.Analytics.Segment do
22
alias CodeCorps.Comment
33
alias CodeCorps.OrganizationMembership
4-
alias CodeCorps.Post
4+
alias CodeCorps.Task
55
alias CodeCorps.User
66
alias CodeCorps.UserCategory
77
alias CodeCorps.UserRole
@@ -29,14 +29,14 @@ defmodule CodeCorps.Analytics.Segment do
2929
def track(conn, :created, organization_membership = %OrganizationMembership{}) do
3030
conn |> do_track("Created Organization Membership", properties(organization_membership))
3131
end
32-
def track(conn, :created, post = %Post{}) do
33-
conn |> do_track("Created Post", properties(post))
32+
def track(conn, :created, task = %Task{}) do
33+
conn |> do_track("Created Task", properties(task))
3434
end
3535
def track(conn, :edited, comment = %Comment{}) do
3636
conn |> do_track("Edited Comment", properties(comment))
3737
end
38-
def track(conn, :edited, post = %Post{}) do
39-
conn |> do_track("Edited Post", properties(post))
38+
def track(conn, :edited, task = %Task{}) do
39+
conn |> do_track("Edited Task", properties(task))
4040
end
4141
def track(conn, :removed, user_category = %UserCategory{}) do
4242
conn |> do_track("Removed User Category", properties(user_category))
@@ -79,10 +79,10 @@ defmodule CodeCorps.Analytics.Segment do
7979
defp properties(comment = %Comment{}) do
8080
%{
8181
comment_id: comment.id,
82-
post: comment.post.title,
83-
post_id: comment.post.id,
84-
post_type: comment.post.post_type,
85-
project_id: comment.post.project_id
82+
task: comment.task.title,
83+
task_id: comment.task.id,
84+
task_type: comment.task.task_type,
85+
project_id: comment.task.project_id
8686
}
8787
end
8888
defp properties(organization_membership = %OrganizationMembership{}) do
@@ -91,12 +91,12 @@ defmodule CodeCorps.Analytics.Segment do
9191
organization_id: organization_membership.organization.id
9292
}
9393
end
94-
defp properties(post = %Post{}) do
94+
defp properties(task = %Task{}) do
9595
%{
96-
post: post.title,
97-
post_id: post.id,
98-
post_type: post.post_type,
99-
project_id: post.project_id
96+
task: task.title,
97+
task_id: task.id,
98+
task_type: task.task_type,
99+
project_id: task.project_id
100100
}
101101
end
102102
defp properties(user_category = %UserCategory{}) do

lib/code_corps/validators/slug_validator.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ defmodule CodeCorps.Validators.SlugValidator do
3030
integration integrations invite invitations ios issue issues jobs learn
3131
likes lists log-in log-out login logout mention mentions new news
3232
notification notifications oauth oauth_clients organization organizations
33-
ping popular post_image post_images post_like post_likes post post
33+
ping popular task-image task-images task-like task-likes task
3434
press pricing privacy
3535
project projects repositories role roles rules search security session
3636
sessions settings shop showcases sidekiq sign-in sign-out signin signout
3737
signup sitemap slug slugs spotlight stars status tag tags
3838
tasks team teams terms training trends trust tour twitter
39-
user_role user_roles user_skill user_skills user users watching year
39+
user-role user-roles user-skill user-skills user users watching year
4040
)
4141

4242
changeset
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
defmodule CodeCorps.Repo.Migrations.ChangePostsToTasks do
2+
use Ecto.Migration
3+
4+
def up do
5+
execute(
6+
"""
7+
DROP TRIGGER IF EXISTS post_created ON posts;
8+
"""
9+
)
10+
11+
execute(
12+
"""
13+
DROP FUNCTION IF EXISTS assign_number();
14+
"""
15+
)
16+
17+
execute "ALTER TABLE comments DROP CONSTRAINT comments_post_id_fkey"
18+
19+
execute "ALTER TABLE posts DROP CONSTRAINT IF EXISTS posts_pkey"
20+
21+
execute "DROP INDEX IF EXISTS posts_pkey"
22+
23+
drop_if_exists index(:posts, [:project_id])
24+
drop_if_exists index(:posts, [:user_id])
25+
drop_if_exists index(:posts, [:number, :project_id], unique: true)
26+
27+
drop_if_exists index(:comments, [:post_id])
28+
29+
rename table(:posts), to: table(:tasks)
30+
31+
execute "CREATE UNIQUE INDEX tasks_pkey ON tasks USING btree (id)"
32+
33+
execute "ALTER SEQUENCE posts_id_seq RENAME TO tasks_id_seq"
34+
35+
rename table(:comments), :post_id, to: :task_id
36+
37+
create index(:comments, [:task_id])
38+
39+
alter table(:comments) do
40+
modify :task_id, references(:tasks, on_delete: :delete_all)
41+
end
42+
43+
rename table(:tasks), :post_type, to: :task_type
44+
45+
execute "ALTER TABLE tasks RENAME CONSTRAINT posts_project_id_fkey TO tasks_project_id_fkey"
46+
execute "ALTER TABLE tasks RENAME CONSTRAINT posts_user_id_fkey TO tasks_user_id_fkey"
47+
48+
create index(:tasks, [:project_id])
49+
create index(:tasks, [:user_id])
50+
create index(:tasks, [:number, :project_id], unique: true)
51+
52+
# We need to assign the number to a task based on its project_id
53+
execute(
54+
"""
55+
CREATE OR REPLACE FUNCTION assign_number()
56+
RETURNS trigger AS
57+
$BODY$
58+
DECLARE
59+
max_number integer;
60+
BEGIN
61+
SELECT coalesce(MAX(number), 0) INTO max_number FROM tasks WHERE project_id = NEW.project_id;
62+
NEW.number := max_number + 1;
63+
RETURN NEW;
64+
END;
65+
$BODY$ LANGUAGE plpgsql;
66+
"""
67+
)
68+
69+
execute(
70+
"""
71+
CREATE TRIGGER task_created
72+
BEFORE INSERT ON tasks
73+
FOR EACH ROW
74+
EXECUTE PROCEDURE assign_number();
75+
"""
76+
)
77+
end
78+
79+
def down do
80+
execute(
81+
"""
82+
DROP TRIGGER IF EXISTS task_created ON tasks;
83+
"""
84+
)
85+
86+
execute(
87+
"""
88+
DROP FUNCTION IF EXISTS assign_number();
89+
"""
90+
)
91+
92+
execute "ALTER TABLE comments DROP CONSTRAINT comments_task_id_fkey"
93+
94+
execute "DROP INDEX tasks_pkey"
95+
96+
drop_if_exists index(:tasks, [:id])
97+
drop_if_exists index(:tasks, [:project_id])
98+
drop_if_exists index(:tasks, [:user_id])
99+
drop_if_exists index(:tasks, [:number, :project_id], unique: true)
100+
101+
drop_if_exists index(:comments, [:task_id])
102+
103+
rename table(:tasks), to: table(:posts)
104+
105+
execute "CREATE UNIQUE INDEX posts_pkey ON posts USING btree (id)"
106+
107+
execute "ALTER SEQUENCE tasks_id_seq RENAME TO posts_id_seq"
108+
109+
rename table(:comments), :task_id, to: :post_id
110+
111+
create index(:comments, [:post_id])
112+
113+
alter table(:comments) do
114+
modify :post_id, references(:posts, on_delete: :delete_all)
115+
end
116+
117+
rename table(:posts), :task_type, to: :post_type
118+
119+
execute "ALTER TABLE posts RENAME CONSTRAINT tasks_project_id_fkey TO posts_project_id_fkey"
120+
execute "ALTER TABLE posts RENAME CONSTRAINT tasks_user_id_fkey TO posts_user_id_fkey"
121+
122+
create index(:posts, [:project_id])
123+
create index(:posts, [:user_id])
124+
create index(:posts, [:number, :project_id], unique: true)
125+
126+
# We need to assign the number to a post based on its project_id
127+
execute(
128+
"""
129+
CREATE OR REPLACE FUNCTION assign_number()
130+
RETURNS trigger AS
131+
$BODY$
132+
DECLARE
133+
max_number integer;
134+
BEGIN
135+
SELECT coalesce(MAX(number), 0) INTO max_number FROM posts WHERE project_id = NEW.project_id;
136+
NEW.number := max_number + 1;
137+
RETURN NEW;
138+
END;
139+
$BODY$ LANGUAGE plpgsql;
140+
"""
141+
)
142+
143+
execute(
144+
"""
145+
CREATE TRIGGER post_created
146+
BEFORE INSERT ON posts
147+
FOR EACH ROW
148+
EXECUTE PROCEDURE assign_number();
149+
"""
150+
)
151+
end
152+
end

0 commit comments

Comments
 (0)