Skip to content

Commit 244d3e1

Browse files
author
Jon Myrick
authored
Merge pull request CodewarsClone#39 from CodewarsClone/wedBranch
Wed branch
2 parents 7b3f91e + 8a0991a commit 244d3e1

11 files changed

Lines changed: 59 additions & 38 deletions

File tree

controllers/kataCtrl.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const db = app.get('db');
33

44
module.exports = {
55
getKatas: (req, res, next) => {
6+
console.log('get katas ran');
67
if (!req.params.kataId) {
78
db.read.katas((err, kata) => {
89
if (err) {
@@ -17,22 +18,28 @@ module.exports = {
1718
console.log(err);
1819
res.status(500).json(err);
1920
}
20-
return res.status(200).json(kata[0]);
21+
return res.status(200).json(kata);
2122
})
2223
}
2324
},
2425

2526
getRandomKata: (req, res, next) => {
27+
console.log(1);
2628
if (!req.params.kyu) {
27-
db.read.kata((err, katas) => {
29+
console.log(2);
30+
db.read.katas((err, katas) => {
31+
console.log(3);
2832
if (err) {
2933
console.log(err);
3034
res.status(500).json(err);
3135
}
36+
console.log(4);
3237
return res.status(200).json(katas[Math.floor(Math.random() * katas.length + 1)]);
3338
})
3439
} else {
40+
console.log(2.1);
3541
db.read.random_by_kyu([req.params.kyu], (err, katas) => {
42+
console.log(3.1);
3643
if (err) {
3744
console.log(err);
3845
res.status(500).json(err);

db/create/new_user_from_github.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
INSERT INTO users (github_id, name, email, username, picutre_url)
1+
INSERT INTO users (github_id, name, email, username, picture_url)
22
VALUES ($1, $2, $3, $4, $5);

db/read/kata_by_id.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
select * from katas
1+
select id, kyu, description, starter_code, name, examples from katas
22
where id = $1;

db/read/katas.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
select * from katas;
1+
select id, kyu, description, starter_code, name, examples from katas;

db/read/random_by_kyu.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
SELECT * FROM katas
1+
SELECT id, kyu, description, starter_code, name, examples FROM katas
22
WHERE kyu = $1;

db/start/tables.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ CREATE TABLE ratings (
3535
liked boolean not null
3636
);
3737

38-
INSERT INTO users (github_id, name, email, username, picutre_url)
38+
INSERT INTO users (github_id, name, email, username, picture_url)
3939
VALUES ('12', 'Bob Smith', 'bob@smith.com', 'bobIScool', null);
4040

4141
INSERT INTO katas (kyu, description, starter_code, name, examples, test_script)

server.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,20 +92,19 @@ app.get('/auth/github/callback',
9292
});
9393

9494

95-
96-
app.get('/kata', kataCtrl.getKatas);
97-
app.get('/kata/:kataId', kataCtrl.getKatas);
98-
app.get('/kata/completed', kataCtrl.getCompletedKatas);
99-
app.get('/kata/random', kataCtrl.getRandomKata);
100-
app.get('/kata/random/:kyu', kataCtrl.getRandomKata);
101-
app.get('/solutions/:kataId', kataCtrl.getKataSolutions);
102-
app.get('/me', (req, res, next) => {
95+
app.get('/api/me', (req, res, next) => {
10396
return res.status(200).json(req.user);
10497
})
98+
app.get('/api/katas', kataCtrl.getKatas);
99+
app.get('/api/kata/:kataId', kataCtrl.getKatas);
100+
app.get('/api/completed-katas', kataCtrl.getCompletedKatas);
101+
app.get('/api/random-kata', kataCtrl.getRandomKata);
102+
app.get('/api/kata-random/:kyu', kataCtrl.getRandomKata);
103+
app.get('/api/solutions/:kataId', kataCtrl.getKataSolutions);
105104

106105
app.post('/test/suite/:kataId', testCtrl.testKata);
107106
app.post('/test/examples', testCtrl.testExamplesKata);
108-
app.post('/solution/:kataId', kataCtrl.postSolution);
107+
app.post('/api/solution/:kataId', kataCtrl.postSolution);
109108

110109

111110

src/components/home/home.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<section class="home">
1+
<section class="home" ng-init="init()">
22

33
<div class="next-challenge">
44
<p>Here's the next challenge</p>

src/components/home/homeCtrl.js

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,29 @@
11
/***********HOME CONTROLLER***********/
22

3-
// each Ctrl should call - mainService.user - for access to the user object
4-
53
angular.module('app').controller('homeCtrl', function($scope, $state, mainService) {
64

7-
// get random kata using randomKata function on service
5+
$scope.getUser = () => {
6+
mainService.getUser().then(response => {
7+
mainService.user = response.data[0];
8+
console.log(mainService.user);
9+
})
10+
}
11+
12+
$scope.getRandomKata = (id) => {
13+
mainService.getRandomKata(id).then(response => {
14+
console.log(response.data);
15+
$scope.randomKata = response.data;
16+
})
17+
}
18+
19+
// the random kata is stored on $scope.randomKata.
20+
// If there is a button you can link the button to $scope.getRandomKata
21+
22+
$scope.init = () => {
23+
$scope.getUser();
24+
$scope.getRandomKata(mainService.user.id);
25+
}
26+
827

9-
mainService.getMe().then(response => {
10-
mainService.user = response.data[0];
11-
console.log(mainService.user);
12-
})
1328

1429
});

src/components/kata_list/kata_listCtrl.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
angular.module('app').controller('kata_listCtrl', function($scope, $state, mainService) {
44

55

6-
// a fimctopm tjat dpes tje following things !. gets all the katas according to user ability (kyu lebel) showing only one level higher and all the levels easier
6+
// a function that does the following things !. gets all the katas according to user ability (kyu level) showing only one level higher and all the levels easier
77
// then the function will shuffle the order on the frontend
88

99

0 commit comments

Comments
 (0)