Skip to content

Commit 1057743

Browse files
author
Jon Myrick
authored
Merge pull request CodewarsClone#82 from CodewarsClone/monBranch
Mon branch
2 parents c4dddea + 5ff087d commit 1057743

5 files changed

Lines changed: 28 additions & 10 deletions

File tree

db/start/tables.sql

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
DROP TABLE IF EXISTS ratings, rating, solutions, katas, kata, users;
1+
DROP TABLE IF EXISTS kata_ratings, sol_ratings, ratings, rating, solutions, katas, kata, users;
22

33
CREATE TABLE users (
44
id serial primary key,
@@ -29,14 +29,20 @@ CREATE TABLE solutions (
2929
script text not null
3030
);
3131

32-
CREATE TABLE ratings (
32+
CREATE TABLE sol_ratings (
3333
id serial primary key,
3434
user_id integer references users(id),
35-
kata_id integer references katas(id),
3635
solution_id integer references solutions(id),
3736
liked boolean not null
3837
);
3938

39+
CREATE TABLE kata_ratings (
40+
id serial primary key,
41+
user_id integer references users(id),
42+
kata_id integer references katas(id),
43+
liked boolean not null
44+
)
45+
4046
INSERT INTO users (github_id, name, email, username, picture_url, points)
4147
VALUES ('12', 'Bob Smith', 'bob@smith.com', 'bobIScool', null, 25);
4248

db/update/kata_likes.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
UPDATE kata_ratings SET liked = false
2+
WHERE user_id = $1 AND kata_id = $2;

db/update/solution_likes.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
UPDATE sol_ratings SET liked = false
2+
WHERE user_id = $1 AND solution_id = $2;

server.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ app.post('/api/submit-answer/:kataid', kataCtrl.sumbitAnswer);
106106
app.post('/api/kata-by-name', kataCtrl.searchByKatasName);
107107

108108
app.put('/api/points', kataCtrl.addPointsToUser);
109-
app.put('/api/kata-votes', kataCtrl.upVoteKata);
110-
app.put('/api/solution-votes', kataCtrl.upVoteSolution);
109+
app.put('/api/kata-votes/:kataid', kataCtrl.upVoteKata);
110+
app.put('/api/solution-votes/:kataid', kataCtrl.upVoteSolution);
111111

112112

113113
app.listen(config.port, function () {

src/components/mainService.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ angular.module('app').service('mainService', function($http, $q, $sce) {
7070
});
7171
};
7272

73-
// homeCtrl - displaying one kata withing range
73+
// homeCtrl - displaying one kata within range
7474
this.getRandomKata = (userkyu) => {
7575
return $http({
7676
method: 'GET',
@@ -122,17 +122,25 @@ angular.module('app').service('mainService', function($http, $q, $sce) {
122122
})
123123
};
124124

125-
this.upVoteKata = () => {
125+
this.upVoteKata = (userid, kataid) => {
126126
return $http({
127127
method: 'PUT',
128-
url: `/api/kata-votes`
128+
url: `/api/kata-votes/` + kataid,
129+
data: {
130+
userid: userid,
131+
kataid: kataid
132+
}
129133
})
130134
}
131135

132-
this.upVoteSolution = () => {
136+
this.upVoteSolution = (kataid, userid, solutionid) => {
133137
return $http({
134138
method: 'PUT',
135-
url: `/api/solution-votes`
139+
url: `/api/solution-votes/` + kataid,
140+
data: {
141+
userid: userid,
142+
solutionid: solutionid
143+
}
136144
})
137145
}
138146

0 commit comments

Comments
 (0)