Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
215 commits
Select commit Hold shift + click to select a range
0797f2b
Merge pull request #3 from StealthySnakes/master
StealthySnakes Apr 3, 2019
b45dd5c
added docker-compose
elilaird Apr 4, 2019
3026ee2
Merge branch 'backend' of https://github.com/StealthySnakes/AnyFit in…
elilaird Apr 4, 2019
dc1e932
Added Dockerfile and compose file for mysql instance, with init scripts
elilaird Apr 6, 2019
163dd47
so I can pull docker
StealthySnakes Apr 8, 2019
25ef08a
trying to pull
StealthySnakes Apr 8, 2019
8ebfd63
Added updated UML diagram
elilaird Apr 10, 2019
7393ffe
trying to pull
StealthySnakes Apr 10, 2019
f4d7762
normalizing tables
StealthySnakes Apr 12, 2019
04c828d
updated gitignore
elilaird Apr 16, 2019
1f6b258
Adding workout counter to tables init
StealthySnakes Apr 16, 2019
9b36dff
added server.js
StealthySnakes Apr 17, 2019
6f0ffa0
added api file
elilaird Apr 17, 2019
450cdb1
Merge branch 'backend' of https://github.com/StealthySnakes/AnyFit in…
elilaird Apr 17, 2019
a853f4e
added DB details
StealthySnakes Apr 17, 2019
2ca919d
Merge branch 'backend' of https://github.com/StealthySnakes/AnyFit in…
elilaird Apr 17, 2019
0a83b3d
working on first get request
StealthySnakes Apr 17, 2019
0e1994b
still working on end points
StealthySnakes Apr 17, 2019
25ab4d9
Updated server.js
Apr 17, 2019
733001a
added endpoints to server.js
Apr 17, 2019
a8828c8
trying to pull for updated files
StealthySnakes Apr 17, 2019
ef28b86
plz let me merge
StealthySnakes Apr 17, 2019
b9a0eb6
only one server,js
StealthySnakes Apr 17, 2019
4a3295d
added dependencies for api
Apr 18, 2019
05af5fa
Image attribute for exercise
sdelabra Apr 18, 2019
b76a0c2
updated server.js
elilaird Apr 18, 2019
09a8fb9
Fixed merge conflicts
elilaird Apr 18, 2019
194e4e0
added checks for empty sets
elilaird Apr 18, 2019
9bcd990
Added more endpoints
elilaird Apr 19, 2019
73aa308
commiting so I can pull
StealthySnakes Apr 19, 2019
941747c
Return all exercises
sdelabra Apr 19, 2019
49e858f
commiting so I can pull
StealthySnakes Apr 19, 2019
0ef1049
please let me pull
StealthySnakes Apr 19, 2019
a75fb1e
Return exercise_image endpoint
sdelabra Apr 19, 2019
49bfbe1
changed server.js
elilaird Apr 19, 2019
631d226
Merge branch 'backend' of https://github.com/StealthySnakes/AnyFit in…
elilaird Apr 19, 2019
75c3df4
removed server.js from frontend folder
StealthySnakes Apr 19, 2019
d6215ba
Merge branch 'backend' of https://github.com/StealthySnakes/AnyFit-Ba…
StealthySnakes Apr 19, 2019
1c563a2
Fixing console log
sdelabra Apr 19, 2019
3ad1028
Merge branch 'backend' of https://github.com/StealthySnakes/AnyFit in…
elilaird Apr 24, 2019
f280769
removed Dockerfiles and excess .js
elilaird Apr 24, 2019
b44ae55
Exercises w/ specified set get api
sdelabra Apr 24, 2019
ce9bc7b
Added username validation at sign up
elilaird Apr 24, 2019
cc870f8
Added username validation at sign up
elilaird Apr 24, 2019
5ea7ab2
editing init_tables to match current DB
StealthySnakes Apr 25, 2019
9ef0a40
Update server.js
TroyRWalker Apr 25, 2019
32f5133
Merge branch 'backend' of https://github.com/StealthySnakes/AnyFit-Ba…
TroyRWalker Apr 25, 2019
724482c
Update server.js
TroyRWalker Apr 25, 2019
381e988
app.get favorite_workout
sdelabra Apr 26, 2019
25d3758
Update server.js
TroyRWalker Apr 26, 2019
a7409a7
Update server.js
TroyRWalker Apr 26, 2019
1c6bfe5
Update server.js
TroyRWalker Apr 26, 2019
045fee2
Edited init sql file to match DB
StealthySnakes Apr 26, 2019
0925918
test
StealthySnakes Apr 26, 2019
a14d5ce
Added time_stamp to the initTables.sql
StealthySnakes Apr 29, 2019
9dbc8bb
Changes to server.js
elilaird Apr 29, 2019
f751cfc
Merge branch 'backend' of https://github.com/StealthySnakes/AnyFit in…
elilaird Apr 29, 2019
6c2d974
Minor Fix
sdelabra Apr 29, 2019
e1c747b
Commenting out Update APIs
sdelabra Apr 29, 2019
649b20e
Create Workout
sdelabra Apr 29, 2019
dd6fcdf
added get workout by workout id
elilaird Apr 29, 2019
4508fad
fixed merge conflicts
elilaird Apr 29, 2019
f19702e
Added create user endpoint, modified create workout
elilaird Apr 29, 2019
b74d637
Parse Workout Object
sdelabra Apr 29, 2019
eb5da12
Updated UML diagram
elilaird Apr 30, 2019
be284b9
Update server.js
TroyRWalker Apr 30, 2019
5af2800
Update server.js
TroyRWalker Apr 30, 2019
8c51dc0
Update init_tables.sql
TroyRWalker Apr 30, 2019
f5ab283
Update server.js
TroyRWalker Apr 30, 2019
3567852
Update server.js
TroyRWalker Apr 30, 2019
4a4afc0
Update UML.pdf
TroyRWalker Apr 30, 2019
a26e00c
Update server.js
TroyRWalker Apr 30, 2019
9c7a920
Added endpoint for creating an exercise
TroyRWalker Apr 30, 2019
2aed753
Updated add exercise
TroyRWalker Apr 30, 2019
d9ada3e
added api to get exercise info from params
StealthySnakes Apr 30, 2019
edb5ec1
added api to get exercise info from params
StealthySnakes Apr 30, 2019
ec7f5a6
Edited create user and create workout
elilaird Apr 30, 2019
6d970d0
Merge branch 'backend' of https://github.com/StealthySnakes/AnyFit in…
elilaird Apr 30, 2019
e436147
Added changes to create user and workout
elilaird Apr 30, 2019
eebba69
Update server.js
TroyRWalker Apr 30, 2019
23df70f
Found API
TroyRWalker Apr 30, 2019
6cc5019
Update server.js
TroyRWalker Apr 30, 2019
e011463
Update server.js
TroyRWalker Apr 30, 2019
96f42e5
fixed api to get exercise info from params
StealthySnakes Apr 30, 2019
a3c1e66
fixed api to get exercise info from params
StealthySnakes Apr 30, 2019
de6ead0
Edited tables to auto increment certain values
StealthySnakes Apr 30, 2019
9f48da4
added autoincrement functionality
elilaird Apr 30, 2019
af978ca
Merge branch 'backend' of https://github.com/StealthySnakes/AnyFit in…
elilaird Apr 30, 2019
d209e61
Added error handling
elilaird Apr 30, 2019
d8e2a7a
Added try catches and gitignore files
elilaird Apr 30, 2019
ff27ca2
fixed formatting issues
elilaird Apr 30, 2019
2971b8e
Added try catch for all endpoints and reformatted
elilaird May 1, 2019
1f2c8ba
modified init tables
StealthySnakes May 1, 2019
b8645d1
Changed add workout
elilaird May 1, 2019
392e685
Post Exercise to Workout api
sdelabra May 1, 2019
eda3cfe
added intensity
elilaird May 1, 2019
1653de8
Merge branch 'backend' of https://github.com/StealthySnakes/AnyFit in…
elilaird May 1, 2019
bec3713
changed init tables format
elilaird May 1, 2019
dcb28a3
Merge branch 'backend' of https://github.com/StealthySnakes/AnyFit in…
elilaird May 1, 2019
bba9e73
Create user api change put to post
sdelabra May 1, 2019
e8c83f1
Merge branch 'backend' of https://github.com/StealthySnakes/AnyFit in…
elilaird May 1, 2019
3383846
changed table increments and keys
elilaird May 1, 2019
997efef
Merge branch 'backend' of https://github.com/StealthySnakes/AnyFit in…
elilaird May 1, 2019
0aa1b14
editing server.js
StealthySnakes May 1, 2019
5e37527
trying to merge
StealthySnakes May 1, 2019
08cfef5
edited create workout
elilaird May 1, 2019
5497c5b
Merge branch 'backend' of https://github.com/StealthySnakes/AnyFit in…
elilaird May 1, 2019
c9b3ce9
Merge branch 'backend' of https://github.com/StealthySnakes/AnyFit in…
elilaird May 1, 2019
5fdd5dc
Create workout works
elilaird May 1, 2019
be1f9fa
Adding comments to the server.js code
StealthySnakes May 1, 2019
7d8ff84
adding comments
StealthySnakes May 1, 2019
f87cd74
More editing ot server.js
StealthySnakes May 1, 2019
8511f93
edited workout rating put
StealthySnakes May 1, 2019
7e8dc70
Testing add exercise
elilaird May 1, 2019
2113669
Merge branch 'backend' of https://github.com/StealthySnakes/AnyFit in…
elilaird May 1, 2019
952a6d1
testing
elilaird May 1, 2019
48b68ba
Merge branch 'backend' of https://github.com/StealthySnakes/AnyFit in…
elilaird May 1, 2019
f638392
edited workout comment put
StealthySnakes May 1, 2019
a6a1e67
Merge branch 'backend' of https://github.com/StealthySnakes/AnyFit in…
elilaird May 1, 2019
fbbb785
Edited change comment
elilaird May 1, 2019
e8a9cac
fixed merge conflicts
elilaird May 1, 2019
6708385
Merge branch 'backend' of https://github.com/StealthySnakes/AnyFit in…
elilaird May 1, 2019
0c6291e
fixed merge conflicts
elilaird May 1, 2019
b90dfd3
Merge branch 'backend' of https://github.com/StealthySnakes/AnyFit in…
elilaird May 1, 2019
6ab12fa
testing exercise object
elilaird May 1, 2019
af35def
Merge branch 'backend' of https://github.com/StealthySnakes/AnyFit in…
elilaird May 1, 2019
c4548ac
Debugging add exercise
elilaird May 1, 2019
a22740e
Merge branch 'backend' of https://github.com/StealthySnakes/AnyFit in…
elilaird May 1, 2019
bcf140e
Debugging add exercise
elilaird May 1, 2019
fe6bff8
Merge branch 'backend' of https://github.com/StealthySnakes/AnyFit in…
elilaird May 1, 2019
037b983
Debugging add exercise
elilaird May 1, 2019
5160757
Merge branch 'backend' of https://github.com/StealthySnakes/AnyFit in…
elilaird May 1, 2019
3277c3d
Debugging add exercise
elilaird May 1, 2019
61fa0ad
Debugging add exercise
elilaird May 1, 2019
fa32641
Merge branch 'backend' of https://github.com/StealthySnakes/AnyFit in…
elilaird May 1, 2019
2856004
Debugging add exercise
elilaird May 1, 2019
11db288
Merge branch 'backend' of https://github.com/StealthySnakes/AnyFit in…
elilaird May 1, 2019
ecf5cc8
Debugging add exercise
elilaird May 1, 2019
c5cfbd6
Merge branch 'backend' of https://github.com/StealthySnakes/AnyFit in…
elilaird May 1, 2019
bc33ad9
Debugging add exercise
elilaird May 1, 2019
47e6e4d
Merge branch 'backend' of https://github.com/StealthySnakes/AnyFit in…
elilaird May 1, 2019
08fb99b
fixing scoping issues
elilaird May 1, 2019
b166aa7
Merge branch 'backend' of https://github.com/StealthySnakes/AnyFit in…
elilaird May 1, 2019
7febdbf
Added put command to update workouts
StealthySnakes May 1, 2019
3b6cc41
Added put command to update workouts
StealthySnakes May 1, 2019
8be09ed
fixing scoping issues
elilaird May 1, 2019
2106fe7
Merge branch 'backend' of https://github.com/StealthySnakes/AnyFit in…
elilaird May 1, 2019
ea3bfb8
Merge branch 'backend' of https://github.com/StealthySnakes/AnyFit in…
elilaird May 1, 2019
2d47461
fixing sql syntax error
elilaird May 1, 2019
63566ad
syntax error
elilaird May 1, 2019
ef55046
added ability to pull workouts from a user's ID
StealthySnakes May 1, 2019
fc3c1c1
added ability to pull workouts from a user's ID
StealthySnakes May 1, 2019
afd4964
split up adding exercise to workout
elilaird May 1, 2019
bed6324
Merge branch 'backend' of https://github.com/StealthySnakes/AnyFit in…
elilaird May 1, 2019
aaad754
merge
elilaird May 1, 2019
d8d94ad
Merge branch 'backend' of https://github.com/StealthySnakes/AnyFit in…
elilaird May 1, 2019
305fbf4
added ability to pull workouts from a user's ID
StealthySnakes May 1, 2019
788cced
syntax
elilaird May 1, 2019
7b9c045
Merge branch 'backend' of https://github.com/StealthySnakes/AnyFit in…
elilaird May 1, 2019
4deb74b
fixed syntax
elilaird May 1, 2019
f8e2025
Merge branch 'backend' of https://github.com/StealthySnakes/AnyFit in…
elilaird May 1, 2019
4e23b0b
split api
elilaird May 1, 2019
2d09048
added middleware for adding exercises
elilaird May 1, 2019
0a38483
deleted files
elilaird May 1, 2019
06e5a4b
Removed excess commented out code
elilaird May 1, 2019
5b89526
Fixed merge error
elilaird May 1, 2019
3836c68
Merge branch 'backend' of https://github.com/StealthySnakes/AnyFit in…
elilaird May 1, 2019
f05935a
Updated init tables to reflect data base
TroyRWalker May 1, 2019
14d4ff4
add friend api
TroyRWalker May 1, 2019
f1d3c00
Added in hash function
StealthySnakes May 1, 2019
59dda3c
Merge branch 'backend' of https://github.com/StealthySnakes/AnyFit-Ba…
StealthySnakes May 1, 2019
79dd117
added ability to pass post through body
elilaird May 1, 2019
9391620
body parsing dependencies
elilaird May 1, 2019
d458fb6
merge conflicts
elilaird May 1, 2019
3b16114
fixed merge errors
elilaird May 1, 2019
625565c
Merge errors
elilaird May 1, 2019
367bf41
merge errors
elilaird May 1, 2019
be387ad
Merge conflicts resolved
elilaird May 2, 2019
b5ff9b8
fixed merge errors
elilaird May 2, 2019
3ccde15
fixed error in package file
elilaird May 2, 2019
d881294
edited workouu_desc
StealthySnakes May 2, 2019
693eb89
Solving the node crisis
StealthySnakes May 2, 2019
35d6505
Merge branch 'backend' of https://github.com/StealthySnakes/AnyFit-Ba…
StealthySnakes May 2, 2019
81911c0
Solved nodes
StealthySnakes May 2, 2019
8f5f2d3
changed names of databases
StealthySnakes May 2, 2019
fdf0b0a
added call to delete a workout
StealthySnakes May 2, 2019
96ac28d
added workout_desc to a request
StealthySnakes May 2, 2019
0a30210
generate workout
elilaird May 2, 2019
6fec852
added workout_desc to a request
StealthySnakes May 2, 2019
95f12a3
Finished adding exercises
elilaird May 2, 2019
51772eb
Merge branch 'backend' of https://github.com/StealthySnakes/AnyFit in…
elilaird May 2, 2019
bce3a07
committing to pull
StealthySnakes May 2, 2019
d47c177
committing to pull
StealthySnakes May 2, 2019
14ede47
creating user api
StealthySnakes May 2, 2019
45edeea
commiting to pull
elilaird May 2, 2019
0cd3d0d
Merge branch 'backend' of https://github.com/StealthySnakes/AnyFit in…
elilaird May 2, 2019
ce288b3
Removed Hash
StealthySnakes May 2, 2019
9ed3af7
fixed issues
elilaird May 2, 2019
3217cf9
Merge branch 'backend' of https://github.com/StealthySnakes/AnyFit in…
elilaird May 2, 2019
e96c555
cleaned up code
elilaird May 2, 2019
a53482a
Removed Hash
StealthySnakes May 2, 2019
218addf
working on returning user avatar
StealthySnakes May 2, 2019
53354e2
working on updating description
StealthySnakes May 2, 2019
e9e44f8
working on updating description
StealthySnakes May 2, 2019
451b94f
working on updating description
StealthySnakes May 2, 2019
2daf1ce
working on updating user sign up
StealthySnakes May 2, 2019
7076742
Object Log updated
TroyRWalker May 2, 2019
04cd1e5
working on updating user sign up
StealthySnakes May 2, 2019
b5fa526
logs
elilaird May 2, 2019
e61013f
commiting to merge
StealthySnakes May 2, 2019
024ca63
working on updating user sign up
StealthySnakes May 2, 2019
13c135e
editing favorites
StealthySnakes May 2, 2019
62b6add
editing favorites
StealthySnakes May 2, 2019
6fbfc49
avatar console logs
elilaird May 2, 2019
cb1e824
working
elilaird May 2, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Binary file modified .DS_Store
Binary file not shown.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Node Modules
./node_modules
node_modules/
Binary file modified Backend/.DS_Store
Binary file not shown.
322 changes: 322 additions & 0 deletions Backend/2
Original file line number Diff line number Diff line change
@@ -0,0 +1,322 @@
'use strict';

const mysql = require('mysql');
const express = require('express');
const app = express();
const port = 3000;
const cors = require('cors');

app.use(cors());

app.post('/home/:login/password/:password', (req, res) => {
con.query('SELECT user_id FROM user_info WHERE username = \'' + req.params['login'] + '\' AND _password =\'' + req.params['password'] + "\';" , function (error, results, fields) {
if (error){
throw error;
}
if(results.length >= 1){
res.send(results);
}
else {
res.send("null");
}

console.log("Incoming login request...");
});
});

//create user
app.put('newuser/:name/:username/:password/:avatar', (req,res) => {
var userId;
con.query('SELECT MAX(user_id) as userID FROM user_info;', function (error1, results1, fields1) {
if(error1)
throw error1;
userId = results1[0].userID + 1;

con.query('INSERT INTO user_info VALUES(' + userId + ',\'' + req.params['username'] + '\',\'' + req.params['name'] + '\',\'' + req.params['password'] + '\',\'' + req.params['avatar'] + ',\'\')', function(error,results,fields) {
if(error)
throw error;
res.send(results);
console.log('Incoming request to create user...');
});
});
});



//return user's friends
app.get('/home/:userID', (req,res) => {
con.query('SELECT f_username,friend_id FROM friends WHERE user_id = ' + req.params['userID'] + ' ;', function(error,results,fields) {
if (error){
throw error;
}
if(results.length >= 1){
res.send(results);
}
console.log("Incoming request for friends data...");
});
});

//return user's avatar
app.get('/home/:userID/avatar', (req,res) =>{
con.query('SELECT avatar FROM user_info WHERE user_id = ' + req.params['userID'] + ' ;', function(error,results,fields) {
if (error){
throw error;
}
if(results.length >= 1){
res.send(results);
}
else {
res.send('https://via.placeholder.com/150');
}
console.log("Incoming request for user avatar...");
});
});

//return user bio
app.get('/home/:userID/bio', (req,res) =>{
con.query('SELECT user_bio FROM user_info WHERE user_id = ' + req.params['userID'] + ' ;', function(error,results,fields) {
if (error){
throw error;
}
if(results.length >= 1){
res.send(results);
}
else {
res.send("");
}
console.log("Incoming request for user bio...");
});
});

app.put('/exercises/:userID/workout_id/:workout_id/favorite/:favorite', (req, res) => {
con.query('UPDATE user_workout SET favorite_workout = '+ req.params['favorite'] +' WHERE user_id = '+ req.params['userID'] + ' AND workout_id = ' + req.params['workout_id'] + ';' , function (error, results, fields) {
if (error)
throw error;
res.send(results);
console.log("Incoming request to update user_workout's favorite_workout...");
});
});

//Return list of favorite workouts
app.get('/home/:userID/favorite_workout', (req, res) => {
con.query('SELECT favorite_workout FROM user_workout WHERE user_id = \'' + req.params['userID'] + "\';" , function (error, results, fields) {
if (error)
throw error;
res.send(results);
console.log(results);
});
});

//Return all exercises
app.get('/exerciseNames/', (req, res) => {
con.query('SELECT exercise_name FROM exercise;' , function (error, results, fields) {
if (error)
throw error;
res.send(results);
console.log("Incoming request for exercise name... ");
});
});

//Return exercise image url!
app.get('/exerciseName/:exercise_name', (req, res) => {
con.query('SELECT exercise_image FROM exercise WHERE exercise_name = \''+ req.params['exercise_name'] + '\' ;' , function (error, results, fields) {
if (error)
throw error;
res.send(results);
console.log(results);
console.log("Incoming request for exercise image...");
});
});

app.get('/exercises/workout_info', (req, res) => {
con.query('SELECT * FROM workout_info;' , function (error, results, fields) {
if (error)
throw error;
res.send(results);
console.log("Incoming request for workout_info... ");
});
});

app.put('/exercises/:workout_id/set_count/:set_count', (req, res) => {
con.query('UPDATE workout_info SET set_count = '+ req.params['set_count'] +' WHERE workout_id = '+ req.params['workout_id'] + ';' , function (error, results, fields) {
if (error)
throw error;
res.send(results);
console.log("Incoming request to update workout_id's set count...");
});
});

app.put('/exercises/:workout_id/rep_count/:rep_count', (req, res) => {
con.query('UPDATE workout_info SET rep_count = '+ req.params['rep_count'] +' WHERE workout_id = '+ req.params['workout_id'] + ';' , function (error, results, fields) {
if (error)
throw error;
res.send(results);
console.log("Incoming request to update workout_id's rep count...");
});
});

app.put('/exercises/:workout_id/workout_length/:workout_length', (req, res) => {
con.query('UPDATE workout_info SET workout_length = '+ req.params['workout_length'] +' WHERE workout_id = '+ req.params['workout_id'] + ';' , function (error, results, fields) {
if (error)
throw error;
res.send(results);
console.log("Incoming request to update workout_id's workout length...");
});
});

app.put('/exercises/:workout_id/workout_desc/:workout_desc', (req, res) => {
con.query('UPDATE workout_info SET workout_desc = '+ req.params['workout_desc'] +' WHERE workout_id = '+ req.params['workout_id'] + ';' , function (error, results, fields) {
if (error)
throw error;
res.send(results);
console.log("Incoming request to update workout_id's workout desc...");
});
});

app.put('/exercises/:workout_id/workout_name/:workout_name', (req, res) => {
con.query('UPDATE workout_info SET workout_name = '+ req.params['workout_name'] +' WHERE workout_id = '+ req.params['workout_id'] + ';' , function (error, results, fields) {
if (error)
throw error;
res.send(results);
console.log("Incoming request to update workout_id's workout name...");
});
});

app.put('/exercises/:workout_id/rating/:rating', (req, res) => {
con.query('UPDATE workout_info SET rating = '+ req.params['rating'] +' WHERE workout_id = '+ req.params['workout_id'] + ';' , function (error, results, fields) {
if (error)
throw error;
res.send(results);
console.log("Incoming request to update workout_id's rating...");
});
});

app.put('/exercises/:workout_id/category/:category', (req, res) => {
con.query('UPDATE workout_info SET category = '+ req.params['category'] +' WHERE workout_id = '+ req.params['workout_id'] + ';' , function (error, results, fields) {
if (error)
throw error;
res.send(results);
console.log("Incoming request to update workout_id's category...");
});
});

app.put('/exercises/:workout_id/intensity/:intensity', (req, res) => {
con.query('UPDATE workout_info SET intensity = '+ req.params['intensity'] +' WHERE workout_id = '+ req.params['workout_id'] + ';' , function (error, results, fields) {
if (error)
throw error;
res.send(results);
console.log("Incoming request to update workout_id's intensity...");
});
});

app.put('/exercises/:workout_id/explevel/:ExpLevel', (req, res) => {
con.query('UPDATE workout_info SET ExpLevel = '+ req.params['ExpLevel'] +' WHERE workout_id = '+ req.params['workout_id'] + ';' , function (error, results, fields) {
if (error)
throw error;
res.send(results);
console.log("Incoming request to update workout_id's ExpLevel...");
});
});

app.put('/exercises/:workout_id/comments/:comments', (req, res) => {
con.query('UPDATE workout_info SET comments = '+ req.params['comments'] +' WHERE workout_id = '+ req.params['workout_id'] + ';' , function (error, results, fields) {
if (error)
throw error;
res.send(results);
console.log("Incoming request to update workout_id's comments...");
});
});

app.put('/exercises/:workout_id/visibility/:visibility', (req, res) => {
con.query('UPDATE workout_info SET visibility = '+ req.params['visibility'] +' WHERE workout_id = '+ req.params['workout_id'] + ';' , function (error, results, fields) {
if (error)
throw error;
res.send(results);
console.log("Incoming request to update workout_id's visibility...");
});
});

//return workout by workout_id
app.get('/workout/:workout_id', (req,res) => {
var workout_id = parseInt(req.params['workout_id']);
con.query('SELECT DISTINCT * from workout_info NATURAL JOIN user_workout NATURAL JOIN exercise WHERE workout_id = ' + workout_id + ' ;', function(error,results,fields) {
if(error)
throw error;
res.send(results);
console.log("Incoming request for workout...");
});
});

app.get('/focus/:focus/expertise/:expertise/length/:length/intensity/:intensity', (req, res) => {
con.query('SELECT exercise_name, rep_count, set_count, default_length FROM exercise NATURAL JOIN workout_info NATURAL JOIN user_workout WHERE category = \'' + req.params['focus'] + '\' AND ExpLevel = \'' + req.params['expertise'] + '\' AND workout_length = \'' + req.params['length'] + '\' AND intensity = \'' + req.params['intensity'] + "\';" , function (error, results, fields) {
if (error)
throw error;
res.send(results);
console.log(results);
});
});

//add try catch
//Return Workout ID for newly created Workout
app.post('/newWorkoutId/:workoutObject' , (req, res) => {
var obj = JSON.parse(req.params['workoutObject']);
var maxWorkout;
con.query('SELECT MAX(workout_id) as workoutID FROM workout_info;', function (error1, results1, fields1) {
if(error1)
throw error1;
maxWorkout = results1[0].workoutID + 1;
console.log(results1[0].workoutID);
console.log(maxWorkout);
//try{
con.query('INSERT INTO user_workout (user_id, workout_id, workout_length, workout_desc, workout_name, category, intensity, ExpLevel, Time_stamp) VALUES (' + obj['userID'] + ',' + maxWorkout + ',' + obj['workoutDuration'] + ', \'' + obj['workoutDesc'] + '\' , \'' + obj['workoutName'] + '\', \'' + obj['category'] + '\',' + obj['intensity'] + ', \'' + obj['experience'] + '\', CURRENT_TIMESTAMP);', function (error, results, fields) {
if(error)
throw error;
res.send(maxWorkout);
console.log("Incoming request to create workout...");
//console.log(maxWorkout);
});



});
});



app.get('/home/username/:username', (req,res) => {
con.query('SELECT COUNT(1) as user FROM user_info WHERE username = \'' + req.params['username'] + '\';', function(error,results,fields) {
if(error)
throw error;
if(results[0].user == 1){
res.send('Username already taken');
}
else if(results[0].user == 0){
res.send('');
}
else{
res.send('error');
}
});
console.log('Incoming username validation...');
});

var con = mysql.createConnection({
host: "127.0.0.1",
user: "dev",
password: "anyfit0987",
database: "anyfit",
});

// checks connection to database
con.connect(function(err) {
if (err) {
console.error('Error Connecting to DB...' + err.stack);
return;
}
console.log("Connected!");
});


app.listen(port, () => {
console.log('Incoming Request');
});
Loading