Update updateRequestScore endpoint and clean up naming

This commit is contained in:
Dessa Simpson 2020-10-18 17:24:24 -07:00
parent 54a7145630
commit 36d3871bdc
6 changed files with 19 additions and 12 deletions

View file

@ -1,7 +1,7 @@
CREATE TABLE scores (
url varchar,
baseScore int NOT NULL DEFAULT 0,
score int NOT NULL DEFAULT 0,
scoreModifier int NOT NULL DEFAULT 0,
PRIMARY KEY (url),
FOREIGN KEY (url) REFERENCES requests(url)
);

View file

@ -32,7 +32,7 @@ case of no votes), and users.is{follower,subscriber} must be COALESCEd to FALSE
as in the case of no votes, user.* will be NULL.
*/
CREATE OR REPLACE VIEW vote_score_all_vw AS
CREATE OR REPLACE VIEW vote_score_vw AS
WITH votepoints AS (SELECT normaluservotepoints, followervotepoints, subscribervotepoints FROM config)
SELECT requests.url AS url,
COUNT(votes.requesturl) AS count,

View file

@ -1,9 +1,9 @@
CREATE OR REPLACE PROCEDURE update_scores()
LANGUAGE SQL
AS $$
UPDATE scores SET score = basescore + votescore
FROM vote_score_all_vw
WHERE scores.url = vote_score_all_vw.url;
UPDATE scores SET score = votescore + scoreModifier
FROM vote_score_vw
WHERE scores.url = vote_score_vw.url;
$$;
CREATE OR REPLACE PROCEDURE add_request(url varchar,requester int)
@ -28,3 +28,10 @@ CREATE OR REPLACE PROCEDURE delete_vote(url varchar,voteuser int)
DELETE FROM votes WHERE requesturl = url AND userid = voteuser;
CALL update_scores();
$$;
CREATE OR REPLACE PROCEDURE update_request_score_modifier(updateurl varchar, scoreDiff int)
LANGUAGE SQL
AS $$
UPDATE scores SET scoreModifier = scoreModifier + scoreDiff WHERE url = updateurl;
CALL update_scores();
$$;