To all: I have merged my Multi-Threading server branch to the master branch. It showed no conflict yet I can't tell if it works for everyone. So before you do any further changes (e.g. new commits), make sure you:
- Pull from the newest master branch
- Configure your Java Environment to use your version
- Change the database login information in the
DatabaseDriver.java
- Clean your Tomcat working directory: I observed that Tomcat is lazy and it retains files from previous version
- Give eclipse some time to index the new code and see if there are warnings or errors
- Rerun the project and check if everything works well.
Currently, only the login notification is implemented. There can be duplicate notifications and we are working on that. If there are any problems, post here or on messenger, and I will look into it as soon as possible. Thank you all.
Every request is a POST. You can see the data by going here. As I complete each call, I will include a version in that site. Instead of submitting it, it will print the data submitted in an alert box.
Status: Front end completed and tested.
This is the first integration we should make. The challenge here, besides connecting the first bridge, will be to receive and store the image. Here is something that might help, at least pseudocode.
I am including the name of the original file in case you need to extract the extension (png vs jpg, etc).
- type: "register"
- firstName: "some text"
- lastName: "some text"
- email: "some text"
- picture: [bynary] OR "undefined"
- pictureName: "something.jpg" OR "something.png"
- password: "some text"
{
type: "register",
firstName: "Alex",
lastName: "",
email: "",
picture: "",
pictureName: "something.jpg"
password: ""
}
I built some tests that will let you know what answer are you sending to the front end and whether it conforms to this protocol. If successful, it will advance to the page loggedIn.html
.
- type:
- "success": all is well
- "exists": an account exists with this email
- "invalid": parameters missing or bad request
- message: "e.g. A message to display to the user if or "
if the user has already exists,
{
type: "exist",
message: "Account already exists with this email!"
}
if successfully created an account,
{
type: "success",
message: "3Successfully registered!"
}
if the user does not fill in all of the information
{
type: "invalid",
message: "Error! Some information are missing!"
}
- type: "login"
- email: ""
- password: ""
- type:
- "success": all is well
- "notexists": doesn't exist
- "invalid": parameters missing or bad request
- message:
- if it fails, "e.g. A message to display to the user or "
- if successful, userID
If the user trying to log in does not exist in the database,
{
type: "notexist",
message: "The specified the user does not exist! Please check your email and password again!"
}
if the user successfully logged in,
{
type: "success",
message: "Successfully logged in!"
}
if the user does not fill all of the information
{
type: "invalid",
message: "Error! Some information are missing!"
}
Front end sends
{
type: "logout"
}
Back end response
{
type: "success"
}
The response exists so that FE knows that BE acknowledged request as opposed as the connection broke or the like.
This call should get people that the current user is not currently following.
The field number in the request determines how many users return.
The response field likes returns a few item foods that the suggested person has included in her/his diet.
{
type: "Suggestions",
number: 2
}
[
{
userId: 3,
picture: "picture.png",
name: "Veronica",
meals: "Vegan Meal, Meat diet",
likes: "Smoothies, apples"
},
{
userId: 4,
picture: "picture.png",
name: "John",
meals: "Pork meal, Fish diet",
likes: "Tea, Coffee"
}
]
Pull friends' meals that are public or have been suggested to this user.
createdBy returns the name of the creator of the meal.
{
type: "suggestedMeals",
numbers: 2
}
[{
mealId: 3,
mealName: "Veggie"
foodItems: "Apple, Orange, Lettuce",
createdBy: "Taylor Swift"
},{
mealId: 3,
mealName: "Veggie"
foodItems: "Apple, Orange, Lettuce",
createdBy: "Taylor Swift"
}]
Return an array of the followers of this user
{
type: "followers"
}
[{
userId: 3,
name: "Taylor Swift",
picture "taylor.jpg"
},{
userId: 4,
name: "Mickey Mouse",
picture "mouse.jpg"
}]
User suggests a meal to a follower
{
type: "suggestMealToFollower",
followerId: 3,
mealId: 5
}
{
"type": "success"
}
Add or remove a follow relation between two users
Given two users user1 and user2, if user1 is following user2, delete the follow relation. Otherwise let user1 follow user2.
{
type: "FollowRelation",
userId: 1
}
If the backend added their relation
{
message: "relation added"
}
if the backend deleted their relation
{
message: "relation deleted"
}
- type: "search"
- q: ""
{
type: "search",
q: "a"
}
The backend should return all the food items that begin with the string passed in q. Spaces are considered OR requests. Empty q should return all food items (maybe just the first one hundred). Notice this is a JSON array so the syntax is a bit different (but not too much).
- foodID:
- foodName:
e.g.
[
{
"foodId":"2",
"foodName":"apple"
},
{
"foodId":"3",
"foodName":"orange"
}
]
- type: "getFood"
- foodId: "3"
{
foodId: 3,
foodName: "Apple",
calories: "500",
protein: "",
vitamin : "",
sugar: ""
}
{
type: "compare",
food1: "food1Id",
food2: "food2Id"
}
[
{
"foodId": 1005,
"foodName": "Cheese, brick",
"calories": "371.000 kcal",
"protein": "23.240 g",
"sugar": "0.510 g"
},
{
"foodId": 1006,
"foodName": "Cheese, brie",
"calories": "334.000 kcal",
"protein": "20.750 g",
"sugar": "0.450 g"
}
]
Gets all the user meals
{
type: "getMeals"
}
[
{
"mealId": 3
"name": "Veggie Meal",
"foodItems": "Apple, cookie, butter",
"privacy": "Private"
},
{
"mealId": 3
"name": "Burger Meal",
"foodItems": "Meat, bread, butter",
"privacy": "Public"
}
]
This happens when a user has combined food items and wants to save this into a meal that is presumably consuming.
{
type: "saveMeal"
name: "Veggie Meal",
content: [3,2,10,19]
}
This should only be done by a logged in user. If the request is sent from an account that is not logged, BE notifies so FE can redirect user to the correct page.
if comes from a logged user, make sure you are tracking the calories that the user is consuming in this meal. Also return the following.
Include the mealId so that FE knows how to id it for future requests.
{
type: "success",
mealId: "4"
}
When deleting a meal, ensure that no other user has a relationship with the same mealId.
If no other user has a relationship to the same mealId, you can delete the relationship between the mealId and the foodId rows along with the relationship between the mealId and userId. Otherwise, delete only the relationship between the mealId and the userId.
{
type: "deleteMeal",
mealId: "mealId"
}
{
type: "success"
}
When a user decides to try a suggested meal
{
type: "tryMeal",
mealId: 3
}
{
type: "success"
}
Meals are private by default. Upon a call of this call, a meal should be declared
- public if it is private or
- private if it is public
{
type: "toggleMealPrivacy",
mealId: "mealId"
}
{
newStatus: "Public"
}
or
{
newStatus: "Private"
}
Frontend requests for summary of the amount of calories in the past two weeks.
{
type: "getData"
}
Passing amount of calories consumed in the last 14 days to the frontend Note: all arrays in the response object have length 7
{
axis: ["Sunday", ...],
week1: [45, ...],
week2: [23, ...]
}
-
Integrating saveMeal, addMeal, shareMeal and deleteMeal with the front end (already tested with simulation on the backend)
-
Implement Suggestions and integrate with front end
-
Implement suggestedMeals and integrate with front end
-
Implement followers and integrate with front end
-
Implement FollowRelation and integrate with front end
-
Figuring out a way to store profile pictures on the backend
Use the basic way to initialize the web socket in any of the front-end pages, for ex.
function ConnectToServer() {
socket = new WebSocket("ws://localhost:8080/YouAreWhatYouEat/ss");
// Set up the four basic web-socket functions here
}
Note: Currently it is not clear whether the session storage is shared between a regular servlet and a web socket servlet. If it is possible, there is no need to pass in an id parameter from the front end. Otherwise we'll have to pass an id parameter to make the socket aware of which user the current session belongs to. The web-socket utilize a path parameter to capture the id, so bascally it's calling a sub-routine in addition to the websocket server. ex.
socket = new WebSocket("ws://localhost:8080/YouAreWhatYouEat/ss/" + id);
Upon success, FE connects to the websocket and sends the message
logged
before redirecting the user to loggedIn.html
User that has been logged in loggedIn.html
. As soon as the page loads, the front end connects to the websocket. Any message from the server is displayed using notification.
Method name - notify(data)
Location - notify.js
Purpose - to display message boxes given a string
Example
<button type="button" onClick="notify('Testing')">
Click Me!
</button>
Requirements:
<script src="notify.js"></script>
**Dependencies: ** jQuery 1.11.1, Bootstrap 3.3.7
This file has been implemented so that when the websocket receives a message, it displays it using this method.
Instructions: In MySQLWorkbench, click on Server --> Data Import, and import the file nutrition_sr28.sql. After this process is completed, a database called "nutrition" will be created. See the script example_query_usda.sql for an example on how to query all the nutritional information for the search "smoothie".