Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian-Kwong committed May 26, 2024
1 parent 51131aa commit 5878f48
Show file tree
Hide file tree
Showing 15 changed files with 46 additions and 87 deletions.
Binary file modified .DS_Store
Binary file not shown.
Binary file modified packages/.DS_Store
Binary file not shown.
1 change: 0 additions & 1 deletion packages/ReverseFood/app/_layout.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Stack } from "expo-router/stack";
import "react-native-reanimated";

export default function Layout() {
return (
Expand Down
58 changes: 31 additions & 27 deletions packages/ReverseFood/app/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,44 @@ import {View , Text } from "react-native";
import { our_styles } from "../styles/styles.jsx";
import { useLocalSearchParams } from "expo-router";
import Table from "../components/table.js";
import SecureStore from "expo-secure-store";
import * as SecureStore from "expo-secure-store";
import { useEffect, useState } from "react";

const URL = "http://localhost:18000/image";
const URL = "http:/10.144.207.193:3000/image";




export default function info (){

const [myData , setData] = useState({ name : 0, description : 0, foodCategory : 0, ingredients : 0, nutrients : []})

export default info = () => {
const [myData , setData] = useState({ name : "Loading", description : "Loading", foodCategory : "Loading", ingredients : "Loading", nutrients : []})

useEffect(() => {
const p = useLocalSearchParams();
fetchData(p)
;});


const fetchData = (params) => {SecureStore.getItemAsync("token").then((token) => {
async function fetchData () { await SecureStore.getItemAsync("token").then((token) => {
const params = useLocalSearchParams();
if (token === undefined) {
console.log("No token found");
}
fetch(URL + {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": token,
},
body: JSON.stringify({
let searchData = {
image: params.image,
foodName: params.foodName,
ingredients: params.ingredients,
description: params.description,
}),
};
console.log(searchData.foodName, searchData.ingredients, searchData.description);
fetch(URL, {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${token}`,
},
body: JSON.stringify(searchData),
}).then((response) => {
if (response.status === 200) {
response.json().then((myData) => {
setData(myData);
return myData
});
} else {
return null;
console.log("Error: " + response.status);
}
}).catch((error) => {
console.log(error);
Expand All @@ -53,13 +49,21 @@ export default function info (){
console.log(error);
return null;
}})};

useEffect(() => {
fetchData().then((data) => {setData({
name : data.name, description : (data.name === undefined), foodCategory : data.foodCategory, ingredients : data.ingredients, nutrients : data.nutrients
})}).catch((error) => console.log(error))
;}, []);




return <View style={our_styles.center_container}>
<Text style={our_styles.heading}>{(myData === 0) ? "Loading" : myData.name}</Text>
<Text style={our_styles.heading}>{(myData.name === 0) ? "Loading" : myData.name}</Text>
<Text></Text>
<Text style={our_styles.subheading}>{(myData === 0) ? "Loading" : myData.description}</Text>
<Text style={our_styles.subheading}>[(myData === 0) ? "Loading" : myData.foodCategory]</Text>
<Text style={our_styles.body}>[(myData === 0) ? "Loading" : myData.ingredients]</Text>
<Table data={(myData === 0) ? "Loading" : myData.nutrients}/>
<Text style={our_styles.subheading}>{myData.name}</Text>
<Text style={our_styles.subheading}>{myData.foodCategory}</Text>
<Text style={our_styles.body}>{myData.ingredients}</Text>
</View>
}
7 changes: 4 additions & 3 deletions packages/ReverseFood/components/FoodInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ import { colors, ourStyles } from "../styles/styles.jsx";
import { router } from "expo-router";
import SecureStore from "expo-secure-store";

function swutchPages(image, foodName, ingredients, desc){
router.push({pathname: "info", params: {image: image, foodName: foodName, ingredients: ingredients, description: desc}})
}


export default function FoodInput() {
Expand Down Expand Up @@ -71,9 +74,7 @@ export default function FoodInput() {
value={desc}
></TextInput>
</View>
<Button title="Submit" onPress={
router.push({pathname: "info", params: {image: image, foodName: foodName, ingredients: ingredients, description: desc}})
} />
<Button title="Submit" onPress={()=>swutchPages(image,foodName,ingredients,desc)}/>
</View>
);
}
Expand Down
3 changes: 1 addition & 2 deletions packages/ReverseFood/components/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {View, Text, ScrollView} from "react-native";
import {our_styles,table_styles} from "../styles/styles.jsx";

function TableHeader(text1, text2, text3,text4) {
console.log(text1 + " " + text2 + " " + text3 + " " + text4);
return <View style={our_styles.tablbleRow}>
<Text style={table_styles.tableHeaderCell}>{text1}</Text>
<Text style={table_styles.tableHeaderCell}>{text2}</Text>
Expand All @@ -13,7 +12,7 @@ function TableHeader(text1, text2, text3,text4) {

function TableCell(text1, text2, text3,text4) {
console.log(text1 + " " + text2 + " " + text3 + " " + text4);
return <View style={our_styles.tablbleRow}>
return <View style={our_styles.tablbleRow} key={text1}>
<Text style={table_styles.tableCell}>{text1}</Text>
<Text style={table_styles.tableCell}>{text2}</Text>
<Text style={table_styles.tableCell}>{text3}</Text>
Expand Down
1 change: 0 additions & 1 deletion packages/backend/.dockerignore

This file was deleted.

11 changes: 0 additions & 11 deletions packages/backend/Dockerfile

This file was deleted.

1 change: 0 additions & 1 deletion packages/backend/api/authHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { userModel } from "../models/user.js";

export function register(req, res){
const { username, password } = req.body;
console.log(username, password);
if (!username || !password) {
res.status(400).send("Bad request: Invalid input data.");
}
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/api/foodHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export async function submitFood(req, res){
return;
}

const foodFacts = await fetch(`http://localhost:18000/foodFacts?foodName=${imgData ? imgData.dish : foodName}`, {method: "GET"}).then((response) => {return response.json()});
const foodFacts = await fetch(`http://localhost:3000/foodFacts?foodName=${imgData ? imgData.dish : foodName}`, {method: "GET"}).then((response) => {return response.json()});

try {
const newFoodItem = await new foodModel({
Expand Down
8 changes: 4 additions & 4 deletions packages/backend/api/images.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,15 @@ export async function getFoodFacts(req, res) {
let foodData = data.foods[0];
foodData = {
name: food,
description: (foodData.description === undefined) ? "Unknown" : changeCase.capitalCase(foodData.description),
foodCategory: (foodData.foodCategory === undefined) ? "Unknown" : changeCase.capitalCase(foodData.foodCategory),
ingredients: (foodData.ingredients === undefined) ? "Unknown" : changeCase.capitalCase(foodData.ingredients),
description: changeCase.capitalCase(foodData.description),
foodCategory: changeCase.capitalCase(foodData.foodCategory),
ingredients: changeCase.capitalCase(foodData.ingredients),
nutrients: foodData.foodNutrients.map((nutrient) => {
return {
name: nutrient.nutrientName,
unit: nutrient.unitName,
value: nutrient.value,
dailyValue: nutrient.percentDailyValue === undefined ? 0 : nutrient.percentDailyValue,
dailyValue: nutrient.dailyValue,
};
}),
image: null,
Expand Down
26 changes: 3 additions & 23 deletions packages/backend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@ import multer from "multer";
import { connect } from './services/mongo.js';
import { addRoutes } from './route.js';
import { addAuthRoutes } from './authroutes.js';
import serverless from "serverless-http";
import dot from "dotenv";


// Set port
dot.config();
const port = process.env.PORT || 3000;

const app = express();
const router = express.Router();
Expand All @@ -27,19 +20,6 @@ app.use("/auth", router);
// Connect to mongo DB
connect("test");


// Binds socket to port
const server = async () =>
app.listen(port, () => {
console.log(`REST API is listening at ${port}`);
});

// Starts server
server();

// Lambda handler
const handler = serverless(app);
export async function handleStart(context, req) {
const res = await handler(context, req);
return res;
}
app.listen(3000, () => {
console.log('Server is running on port 3000');
});
11 changes: 1 addition & 10 deletions packages/backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
"express": "^4.19.2",
"jsonwebtoken": "^9.0.2",
"mongoose": "^8.4.0",
"multer": "^1.4.5-lts.1",
"serverless-http": "^3.2.0"
"multer": "^1.4.5-lts.1"
},
"devDependencies": {
"@types/node": "^20.12.12",
Expand Down
1 change: 0 additions & 1 deletion packages/backend/services/mongo.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ function getMongoURL(dbname) {
const MONGO_PASS = process.env.MONGO_PASS;
let connection_string = `mongodb+srv://${MONGO_USER}:${MONGO_PASS}@cluster0.yomgmem.mongodb.net/${dbname}?retryWrites=true&w=majority`;
if (MONGO_USER && MONGO_PASS) {
console.log("Ok...");
console.log(
"Connecting to MongoDB at",
`mongodb+srv://${MONGO_USER}:<password>@cluster0.yomgmem.mongodb.net/${dbname}`
Expand Down

0 comments on commit 5878f48

Please sign in to comment.