15 Commits

12 changed files with 244 additions and 132 deletions

View File

@ -0,0 +1,32 @@
name: Build DeguApp backend
on: pull_request
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Set up Node.js and TypeScript
uses: actions/setup-node@v1
with:
node-version: "20.14.0"
- name: npm install
working-directory: api/
run: |
npm install
- name: npm run build
working-directory: api/
run: |
npm run build --if-present
- name: npm run test
working-directory: api/
run: |
npm run test

View File

@ -35,7 +35,12 @@ To get started with DeguApp, follow these steps:
2. Install dependencies: 2. Install dependencies:
```bash ```bash
cd deguapp # frontend
cd deguapp/frontend
npm install
# backend
cd deguapp/api
npm install npm install
``` ```
@ -43,11 +48,6 @@ To get started with DeguApp, follow these steps:
5. Open the app in your browser or Android emulator and start exploring! 5. Open the app in your browser or Android emulator and start exploring!
## Contributing
Contributions are welcome! If you'd like to contribute to DeguApp, please fork the repository and submit a pull request with your changes.
Use the upstream of the project, which can be found at https:/git.filiprojek.cz/fr/deguapp. **GitHub repository is just a mirror!**
## Local builds ## Local builds
### Android ### Android
@ -74,12 +74,24 @@ bundletool build-apks --bundle=./frontend/android/app/build/outputs/bundle/relea
bundletool install-apks --apks=./deguapp.apks bundletool install-apks --apks=./deguapp.apks
``` ```
#### Resources:
### Resources:
- https://github.com/expo/eas-cli/issues/1300 - https://github.com/expo/eas-cli/issues/1300
- https://reactnative.dev/docs/signed-apk-android#generating-the-release-aab - https://reactnative.dev/docs/signed-apk-android#generating-the-release-aab
### Server
```bash
cd api/
npm i
npm run build
```
## Contributing
Contributions are welcome! If you'd like to contribute to DeguApp, please fork the repository and submit a pull request with your changes.
Use the upstream of the project, which can be found at https:/git.filiprojek.cz/fr/deguapp. **GitHub repository is just a mirror!**
## License ## License
This project is licensed under the GNU GPLv3 License - see the [LICENSE](LICENSE) file for details. This project is licensed under the GNU GPLv3 License - see the [LICENSE](LICENSE) file for details.

View File

@ -5,9 +5,9 @@ export const router = Router();
router.use("/api/v1", api_v1); router.use("/api/v1", api_v1);
//router.get("*", (req: Request, res: Response) => { router.get("*", (req: Request, res: Response) => {
// res.sendFile(path.join(__dirname, "../views/index.html")); res.sendFile(path.join(__dirname, "../public/index.html"));
//}); });
// 404 // 404
router.use((req: Request, res: Response) => { router.use((req: Request, res: Response) => {

View File

@ -12,9 +12,7 @@
"resizeMode": "contain", "resizeMode": "contain",
"backgroundColor": "#ffffff" "backgroundColor": "#ffffff"
}, },
"assetBundlePatterns": [ "assetBundlePatterns": ["**/*"],
"**/*"
],
"ios": { "ios": {
"supportsTablet": true "supportsTablet": true
}, },

View File

@ -18,7 +18,7 @@ export default function BeerAdd() {
const [open, setOpen] = useState(false); const [open, setOpen] = useState(false);
const [items, setItems] = useState([ const [items, setItems] = useState([
{ label: "Tank beer", value: "tank" }, { label: "Tank beer", value: "tank" },
{ label: "Cask beer", value: "cask" }, { label: "Keg beer", value: "keg" },
{ label: "Glass bottle", value: "glass" }, { label: "Glass bottle", value: "glass" },
{ label: "Can", value: "can" }, { label: "Can", value: "can" },
{ label: "PET bottle", value: "pet" }, { label: "PET bottle", value: "pet" },

View File

@ -19,7 +19,7 @@ export default function reviewAdd() {
const [openSourness, setOpenSourness] = useState(false); const [openSourness, setOpenSourness] = useState(false);
const [openAgain, setOpenAgain] = useState(false); const [openAgain, setOpenAgain] = useState(false);
// pěna // foam
const [itemFoam, setFoamValue] = useState(null); const [itemFoam, setFoamValue] = useState(null);
const [foam, setFoam] = useState([ const [foam, setFoam] = useState([
{ {
@ -54,11 +54,11 @@ export default function reviewAdd() {
}, },
]); ]);
// hořkost / sladkost // bitter / sweetness
const [itemBitter_sweetness, setBitter_sweetnessValue] = useState(null); const [itemBitter_sweetness, setBitter_sweetnessValue] = useState(null);
const [bitter_sweetness, setBitter_sweetness] = useState([ const [bitter_sweetness, setBitter_sweetness] = useState([
{ {
label: "Bad", label: "Bitter",
value: "1", value: "1",
icon: () => ( icon: () => (
<Image <Image
@ -78,7 +78,7 @@ export default function reviewAdd() {
), ),
}, },
{ {
label: "Excellent", label: "Sweet",
value: "3", value: "3",
icon: () => ( icon: () => (
<Image <Image
@ -89,7 +89,7 @@ export default function reviewAdd() {
}, },
]); ]);
//chuť // taste
const [itemTaste, setTasteValue] = useState(null); const [itemTaste, setTasteValue] = useState(null);
const [taste, setTaste] = useState([ const [taste, setTaste] = useState([
{ {
@ -199,7 +199,7 @@ export default function reviewAdd() {
}, },
]); ]);
//kyselost // sourness
const [itemSourness, setSournessValue] = useState(null); const [itemSourness, setSournessValue] = useState(null);
const [sourness, setSourness] = useState([ const [sourness, setSourness] = useState([
{ {
@ -224,7 +224,7 @@ export default function reviewAdd() {
}, },
]); ]);
//dal bych si znovu? // would again
const [itemAgain, setAgainValue] = useState(null); const [itemAgain, setAgainValue] = useState(null);
const [again, setAgain] = useState([ const [again, setAgain] = useState([
{ {

View File

@ -1,4 +1,4 @@
import { View, StyleSheet, FlatList } from "react-native"; import { View, StyleSheet, FlatList, Image } from "react-native";
import Text from "@components/Text"; import Text from "@components/Text";
import Button from "@components/Button"; import Button from "@components/Button";
import { colors } from "@components/style"; import { colors } from "@components/style";
@ -14,6 +14,8 @@ export default function Tab() {
fetchData(); fetchData();
}, []); }, []);
const API_HOST = process.env.EXPO_PUBLIC_API_URL.replace("/api/v1", "");
async function fetchData() { async function fetchData() {
try { try {
const res = await fetch(`${process.env.EXPO_PUBLIC_API_URL}/review/get`, { const res = await fetch(`${process.env.EXPO_PUBLIC_API_URL}/review/get`, {
@ -23,6 +25,28 @@ export default function Tab() {
let data = await res.json(); let data = await res.json();
// show only logged in user's data // show only logged in user's data
data = data.data.filter((review) => review.user_id == user._id); data = data.data.filter((review) => review.user_id == user._id);
let beers = await fetch(`${process.env.EXPO_PUBLIC_API_URL}/beer/get`, {
method: "GET",
credentials: "include",
});
beers = await beers.json();
beers = beers.data;
console.log(beers);
async function getBeerParam(search, beers) {
for (let i = 0; i < beers.length; i++) {
if (beers[i]._id == search) {
return beers[i];
}
}
return null;
}
data.forEach(async (el) => {
el.beer = await getBeerParam(el.beer_id, beers);
});
console.log("reviews", data); console.log("reviews", data);
setData(data); setData(data);
} catch (err) { } catch (err) {
@ -30,27 +54,53 @@ export default function Tab() {
alert("Something went wrong"); alert("Something went wrong");
} }
} }
const opt3 = ["Bad", "Medium", "Excellent!"];
const opt5 = [
"Disgust",
"Not great, not terrible",
"Good",
"Why not?",
"Excellent!",
];
const opt2 = ["Yes", "No"];
const sourness = ["Good", "Bad"];
return ( return (
<View style={styles.container}> <View style={styles.container}>
<Button
title="Add Review"
color={colors.gold}
onPress={() => {
router.replace("/review/add");
}}
/>
<FlatList <FlatList
data={data} data={data}
style={styles.reviewList} style={styles.reviewList}
keyExtractor={(item) => String(item._id)} keyExtractor={(item) => String(item._id)}
renderItem={({ item }) => ( renderItem={({ item }) => (
<View style={styles.item}> <View style={styles.itemContainer}>
<Text>Name: {item.name}</Text> <View>
<Text>Brand: {item.brand}</Text> <Text>{item.beer.name}</Text>
<Text>Degree: {item.degree}</Text> <Text>{item.beer.brand}</Text>
<Text>Packaging: {item.packaging}</Text> <Text>{item.beer.degree}°</Text>
<Text>{item.beer.packaging}</Text>
<Image
source={
item.beer.imgs[0]
? {
uri: `${API_HOST}/public/uploads/${item.beer.imgs[0]}`,
}
: {
uri: "https://imagesvc.meredithcorp.io/v3/mm/image?url=https:%2F%2Fstatic.onecms.io%2Fwp-content%2Fuploads%2Fsites%2F44%2F2020%2F09%2F29%2Flight-beer.jpg",
}
}
style={styles.itemImg}
/>
</View>
<View>
<Text>Foam {opt3[item.foam - 1]}</Text>
<Text>
Bitter / Sweetness {opt3[item.bitter_sweetness - 1]}
</Text>
<Text>Taste {opt5[item.taste - 1]}</Text>
<Text>Packaging {opt5[item.packaging - 1]}</Text>
<Text>Sourness {sourness[item.sourness - 1]}</Text>
<Text>Would again? {opt2[item.would_again - 1]}</Text>
</View>
</View> </View>
)} )}
/> />
@ -70,11 +120,20 @@ export const styles = StyleSheet.create({
paddingHorizontal: "15%", paddingHorizontal: "15%",
marginTop: "5%", marginTop: "5%",
}, },
item: { itemContainer: {
borderColor: "gray", borderColor: "gray",
borderWidth: 1, borderWidth: 1,
borderRadius: 10, borderRadius: 10,
padding: 13, padding: 13,
marginBottom: "5%", marginBottom: "5%",
flex: 1,
flexDirection: "row",
justifyContent: "space-between",
},
itemImg: {
width: 150,
aspectRatio: 1,
resizeMode: "contain",
marginTop: "5%",
}, },
}); });

View File

@ -90,7 +90,7 @@ export function AuthProvider({ children }) {
}); });
if (resUser.status != 200) { if (resUser.status != 200) {
throw Error("user does not have user data"); throw Error("Username or password is incorrect!");
} }
const userData = await resUser.json(); const userData = await resUser.json();
@ -104,7 +104,7 @@ export function AuthProvider({ children }) {
await storageUtil.setItem(TOKEN_KEY, loginData.data.jwt); await storageUtil.setItem(TOKEN_KEY, loginData.data.jwt);
} catch (err) { } catch (err) {
console.error("Failed to log in", err); console.error("Failed to log in", err);
return { error: true, msg: err.res }; return { error: true, msg: err };
} }
} }

View File

@ -20,8 +20,12 @@ function LoginPage() {
} }
}, [authState.authenticated]); }, [authState.authenticated]);
function login() { async function login() {
onLogin(email, pass); const res = await onLogin(email, pass);
if (res !== undefined && res.error === true) {
alert(res.msg);
return;
}
} }
return ( return (

View File

@ -16,23 +16,28 @@ function SignupPage() {
const { onSignin } = useAuth(); const { onSignin } = useAuth();
async function signin() { async function signin() {
if (pass1 == pass2) { if (pass1 != pass2) {
alert("Passwords are not same!");
return;
}
const res = await onSignin(username, email, pass1); const res = await onSignin(username, email, pass1);
if (res.error) { const data = await res.json();
if (res.msg.message == "validation error") {
alert(res.msg.data.message); if (res.status == 400) {
if (data.message == "validation error") {
alert(data.data.message);
} else { } else {
alert(res.msg.message); alert("Something went wrong");
}
}
if (!res.error) {
alert("You have been successfully registered. Please Log In");
router.replace("/login");
} }
return; return;
} }
alert("Passwords are not same!"); if (res.status == 201) {
alert("You have been successfully registered. Please Log In");
router.replace("/login");
return;
}
} }
return ( return (

View File

@ -1,7 +1,7 @@
{ {
"$schema": "https://biomejs.dev/schemas/1.7.3/schema.json", "$schema": "https://biomejs.dev/schemas/1.7.3/schema.json",
"files": { "files": {
"ignore": [".expo/", ".vscode/", "node_modules/"] "ignore": [".expo/", ".vscode/", "node_modules/", "dist/"]
}, },
"organizeImports": { "organizeImports": {
"enabled": true "enabled": true

View File

@ -6,7 +6,9 @@
"start": "expo start", "start": "expo start",
"android": "expo start --android", "android": "expo start --android",
"ios": "expo start --ios", "ios": "expo start --ios",
"web": "expo start --web" "web": "expo start --web",
"build:web": "npx expo export",
"format": "npx @biomejs/biome format --write ."
}, },
"dependencies": { "dependencies": {
"@expo/metro-runtime": "~3.2.1", "@expo/metro-runtime": "~3.2.1",