diff --git a/api/src/controllers/reviewController.ts b/api/src/controllers/reviewController.ts index 6104e23..8f8ec4b 100644 --- a/api/src/controllers/reviewController.ts +++ b/api/src/controllers/reviewController.ts @@ -18,6 +18,7 @@ new Docs( export async function add_post(req: Request, res: Response) { try { const data: IReview = req.body; + data.user_id = res.locals.user._id const review = new Review(data); await review.save(); res.status(201).json(Log.info(201, "review was added", review)); diff --git a/api/src/models/Review.ts b/api/src/models/Review.ts index f9a4fcf..7c39149 100644 --- a/api/src/models/Review.ts +++ b/api/src/models/Review.ts @@ -28,6 +28,14 @@ const schema = new Schema( type: Boolean, required: true, }, + beer_id: { + type: String, + required: true, + }, + user_id: { + type: String, + required: true, + } }, { timestamps: true, diff --git a/api/src/public/api.json b/api/src/public/api.json index e5ab6ef..97de5a0 100644 --- a/api/src/public/api.json +++ b/api/src/public/api.json @@ -1 +1 @@ -{"version":"2.0.0","endpoints":{"user":{"signup":{"name":"user","operation":"signup","route":"/api/v1/auth/signup","method":"POST","description":"user signup api","body":{"username":"testuser","email":"text@example.com","password":"Test1234"},"response":"status object"},"signin":{"name":"user","operation":"signin","route":"/api/v1/auth/signin","method":"POST","description":"user signin api","body":{"email":"text@example.com","password":"Test1234"},"response":"status object"},"logout":{"name":"user","operation":"logout","route":"/api/v1/auth/logout","method":"POST","description":"user logout api","body":{},"response":"status object"},"status":{"name":"user","operation":"status","route":"/api/v1/auth/status","method":"GET","description":"user login status api","response":"status code | user object"}},"beer":{"add":{"name":"beer","operation":"add","route":"/api/v1/beer/add","method":"POST","description":"beer add api","body":{"brand":"Pilsner Urqell","name":"Kozel","degree":11,"packaging":"can","photos":"optional field | max 4 images | formData"},"response":"status object | beer object"},"get":{"name":"beer","operation":"get","route":"/api/v1/beer/get","method":"GET","description":"beer get api","response":"status object | array of beer objects"},"del":{"name":"beer","operation":"del","route":"/api/v1/beer/del","method":"POST","description":"beer del api","body":{"_id":"6352b303b71cb62222f39895"},"response":"status object"},"edit":{"name":"beer","operation":"edit","route":"/api/v1/beer/edit","method":"POST","description":"beer edit api","body":{"_id":"6355b95dc03fad77bc380146","brand":"Pilsner Urqell","name":"Radegast","degree":12,"packaging":"bottle","imgs":[],"photos":"optional field | max 4 images | formData"},"response":"status object | beer data"}},"docs":{"get_all":{"name":"docs","operation":"get_all","route":"/api/v1","method":"GET","description":"Get docs json","response":"docs json"}}}} \ No newline at end of file +{"version":"2.0.0","endpoints":{"user":{"signup":{"name":"user","operation":"signup","route":"/api/v1/auth/signup","method":"POST","description":"user signup api","body":{"username":"testuser","email":"text@example.com","password":"Test1234"},"response":"status object"},"signin":{"name":"user","operation":"signin","route":"/api/v1/auth/signin","method":"POST","description":"user signin api","body":{"email":"text@example.com","password":"Test1234"},"response":"status object"},"logout":{"name":"user","operation":"logout","route":"/api/v1/auth/logout","method":"POST","description":"user logout api","body":{},"response":"status object"},"status":{"name":"user","operation":"status","route":"/api/v1/auth/status","method":"GET","description":"user login status api","response":"status code | user object"}},"beer":{"add":{"name":"beer","operation":"add","route":"/api/v1/beer/add","method":"POST","description":"beer add api","body":{"brand":"Pilsner Urqell","name":"Kozel","degree":11,"packaging":"can","photos":"optional field | max 4 images | formData"},"response":"status object | beer object"},"get":{"name":"beer","operation":"get","route":"/api/v1/beer/get","method":"GET","description":"beer get api","response":"status object | array of beer objects"},"del":{"name":"beer","operation":"del","route":"/api/v1/beer/del","method":"POST","description":"beer del api","body":{"_id":"6352b303b71cb62222f39895"},"response":"status object"},"edit":{"name":"beer","operation":"edit","route":"/api/v1/beer/edit","method":"POST","description":"beer edit api","body":{"_id":"6355b95dc03fad77bc380146","brand":"Pilsner Urqell","name":"Radegast","degree":12,"packaging":"bottle","imgs":[],"photos":"optional field | max 4 images | formData"},"response":"status object | beer data"}},"docs":{"get_all":{"name":"docs","operation":"get_all","route":"/api/v1","method":"GET","description":"Get docs json","response":"docs json"}},"review":{"add":{"name":"review","operation":"add","route":"/api/v1/review/add","method":"POST","description":"review add api","body":{"beer_id":"6352b303b71cb62222f39895","foam":3,"bitter_sweetness":2,"taste":5,"packaging":3,"sourness":false,"would_again":true},"response":"status object | review object"},"get":{"name":"review","operation":"get","route":"/api/v1/review/get","method":"GET","description":"review get api","response":"status object | array of review objects"},"del":{"name":"review","operation":"del","route":"/api/v1/review/del","method":"POST","description":"review del api","body":{"_id":"6352b303b71cb62222f39895"},"response":"status object"}}}} \ No newline at end of file diff --git a/api/src/validators/reviewValidator.ts b/api/src/validators/reviewValidator.ts index ae1799d..03fe14c 100644 --- a/api/src/validators/reviewValidator.ts +++ b/api/src/validators/reviewValidator.ts @@ -20,6 +20,7 @@ export const add = yup.object({ packaging: yup.number().min(1).max(5).required(), sourness: yup.boolean().required(), would_again: yup.boolean().required(), + user_id: yup.string().notRequired() }); export interface IReview extends yup.InferType, mongooseAddition {} export const addExam: IReview = { diff --git a/frontend/.gitignore b/frontend/.gitignore index 50f5130..778538e 100644 --- a/frontend/.gitignore +++ b/frontend/.gitignore @@ -37,3 +37,4 @@ yarn-error.* .env .vscode/ +*.swp diff --git a/frontend/app/(app)/(tabs)/_layout.js b/frontend/app/(app)/(tabs)/_layout.js index be70c82..57ff21b 100644 --- a/frontend/app/(app)/(tabs)/_layout.js +++ b/frontend/app/(app)/(tabs)/_layout.js @@ -43,7 +43,7 @@ export default function TabLayout() { }} /> ( @@ -66,6 +66,10 @@ export default function TabLayout() { name="beer/add" options={{ href: null, title: "Add beer" }} /> + ); diff --git a/frontend/app/(app)/(tabs)/beer/add.js b/frontend/app/(app)/(tabs)/beer/add.js index e124b03..1b64cc0 100644 --- a/frontend/app/(app)/(tabs)/beer/add.js +++ b/frontend/app/(app)/(tabs)/beer/add.js @@ -108,8 +108,12 @@ export default function BeerAdd() { async function addBeer() { // TODO: after the request - redirect to /beer/{new_beer_id}?; plus some modal about successful state + const data = new FormData(); - data.append("photos", dataURItoBlob(image.uri)); + if (Platform.OS == "web") { + // TODO: On phone its imposibble to upload an image + data.append("photos", dataURItoBlob(image.uri)); + } data.append("brand", b_brand); data.append("name", b_name); data.append("degree", b_degree); @@ -124,7 +128,9 @@ export default function BeerAdd() { const res = await req.json(); if (res.code == 201 && res.data._id) { - window.location.href = `/beer/${res.data._id}`; + // TODO: reditect using expo router + // window.location.href = `/beer/${res.data._id}`; + alert("Added"); } else { alert( "Beer was not added successfully. Please check your data and try again.", @@ -198,9 +204,8 @@ export default function BeerAdd() { ) : ( false )} - - {image && } + {image && }