Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Voters API #25

Open
wants to merge 7 commits into
base: master
from
Open

Voters API #25

wants to merge 7 commits into from

Conversation

@mittalyashu
Copy link
Member

mittalyashu commented Feb 7, 2020

No description provided.

@mittalyashu mittalyashu added this to the v0.0.1 milestone Feb 7, 2020
@mittalyashu mittalyashu self-assigned this Feb 7, 2020
Move the controller for adding one upvote on post creation to `post/create` API.
@mittalyashu mittalyashu removed this from the v0.0.1 milestone Feb 7, 2020
@mittalyashu

This comment has been minimized.

Copy link
Member Author

mittalyashu commented Feb 7, 2020

Due to some issue while working on the voters API. I will delay the release of this PR until next release.

@mittalyashu

This comment has been minimized.

Copy link
Member Author

mittalyashu commented Feb 7, 2020

I was trying to create a function in postgresql database.

Function

CREATE OR REPLACE FUNCTION update_vote_count()
RETURNS trigger AS
'
BEGIN
  UPDATE post SET vote = (SELECT COUNT(*) FROM vote WHERE post_id = NEW.post_id) WHERE post_id = NEW.post_id;
  RETURN NEW;
END
'
LANGUAGE PLPGSQL;

Trigger

 CREATE TRIGGER trigger_vote_count
AFTER UPDATE ON vote
EXECUTE PROCEDURE update_vote_count();

Somehow it is not working.

When I try to run this query individually it works perfectly.

UPDATE post SET vote = (SELECT COUNT(*) FROM vote WHERE post_id = `${post_id}`) WHERE post_id = `${post_id}`;
mittalyashu added 2 commits Feb 7, 2020
voters column store INT value of the total number of vote post has.
Adds an upvote to the post.

This API used by member other than the author of the post.
@mittalyashu mittalyashu added this to the v0.1.0 milestone Feb 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

1 participant
You can’t perform that action at this time.