Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
Frontend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IDATT2106 Scrum Team 02
Frontend
Commits
a6b5f814
Commit
a6b5f814
authored
1 year ago
by
Ingrid
Browse files
Options
Downloads
Patches
Plain Diff
la inn noen kjøleskapsapimetoder
parent
f84a080f
No related branches found
No related tags found
1 merge request
!13
Fridge view
Pipeline
#221988
failed
1 year ago
Stage: build
Stage: test
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/stores/fridgeStore.js
+29
-0
29 additions, 0 deletions
src/stores/fridgeStore.js
src/util/API.js
+54
-7
54 additions, 7 deletions
src/util/API.js
src/views/FridgeView.vue
+8
-0
8 additions, 0 deletions
src/views/FridgeView.vue
with
91 additions
and
7 deletions
src/stores/fridgeStore.js
0 → 100644
+
29
−
0
View file @
a6b5f814
import
{
defineStore
}
from
"
pinia
"
;
export
const
useFridgeStore
=
defineStore
(
"
fridge
"
,
{
state
:
()
=>
{
return
{
items
:
[]
};
},
persist
:
{
storage
:
localStorage
},
getters
:
{
getItems
()
{
return
this
.
items
;
},
getItem
(
state
){
return
(
id
)
=>
state
.
items
.
filter
(
item
=>
item
.
id
===
id
)
}
},
actions
:
{
reset
()
{
this
.
$reset
();
},
addToFridge
(
item
){
this
.
items
.
push
(
item
);
}
}
});
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/util/API.js
+
54
−
7
View file @
a6b5f814
...
...
@@ -115,19 +115,66 @@ export const API = {
.
catch
(
err
=>
{
console
.
log
(
err
)})
})
.
catch
(()
=>
{
throw
new
Error
()})
}
}
export
const
API
=
{
}
,
/**
* Fetches all fridgeItems
* fetches all fridge items belonging to user
* @returns {Promise<*>}
*/
getFridgeItems
(){
return
axios
.
get
(
`
${
import
.
meta
.
env
.
VITE_BACKEND_URL
}
/fridge`
)
getFridgeItems
:
async
()
=>
{
const
authStore
=
useAuthStore
();
return
axios
.
get
(
`
${
import
.
meta
.
env
.
VITE_BACKEND_URL
}
/fridge`
,
{
headers
:
{
Authorization
:
`Bearer
${
authStore
.
token
}
`
},
})
.
then
((
response
)
=>
{
return
response
.
data
;
}).
catch
(()
=>
{
throw
new
Error
();
throw
new
Error
(
"
Could not fetch fridge items
"
);
});
},
//returns fridgeItem of specific id
getFridgeItem
:
async
(
id
)
=>
{
const
authStore
=
useAuthStore
();
return
axios
.
get
(
`
${
import
.
meta
.
env
.
VITE_BACKEND_URL
}
/fridge/
${
id
}
`
,
{
headers
:
{
Authorization
:
`Bearer
${
authStore
.
token
}
`
},
})
.
then
((
response
)
=>
{
return
response
.
data
;
})
.
catch
(()
=>
{
throw
new
Error
(
"
Could not fetch fridge item
"
);
});
},
/**
* Adds item(s) to the fridge
* @param request List<Ingredient> listOfIngredients
* @returns {Promise<void>}
*/
addToFridge
:
async
(
request
)
=>
{
const
authStore
=
useAuthStore
();
return
axios
.
post
(
`
${
import
.
meta
.
env
.
VITE_BACKEND_URL
}
/fridge`
,
{
headers
:
{
Authorization
:
`Bearer
${
authStore
.
token
}
`
},
}).
then
((
response
)
=>
{
return
response
.
data
;
}).
catch
(()
=>
{
throw
new
Error
(
"
Could not add item to fridge:
"
);
})
},
/**
* Removes x amount of item from fridge
* @param id id of fridgeItem
* @param request ... amount
*/
removeFromFridge
(
id
,
request
){
//TODO
}
}
This diff is collapsed.
Click to expand it.
src/views/FridgeView.vue
+
8
−
0
View file @
a6b5f814
...
...
@@ -3,6 +3,7 @@
<h1>
Kjøleskap
</h1><br><br>
<eat-fridge-item-modal
@
closeModal=
"hideModal"
v-if=
"visible"
:fridge-item=
"selectedItem"
></eat-fridge-item-modal>
<div
id =
"itemContainer"
>
<FridgeItem
v-for=
"item in fridgeStore.items"
></FridgeItem>
<!--
<FridgeItem
v-for=
"item in fridgeItems"
:key=
"item.id"
fridgeItem=
"item"
></FridgeItem>
-->
<FridgeItem
@
appleBtnPressed=
"showModal"
item-name=
"Melk"
quantity=
"5"
quantity-unit=
"dl"
expiration=
"21.04.23"
></FridgeItem>
<FridgeItem
@
appleBtnPressed=
"showModal"
item-name=
"Melk"
quantity=
"5"
quantity-unit=
"dl"
expiration=
"22.04.23"
></FridgeItem>
...
...
@@ -29,10 +30,17 @@
import
FridgeItem
from
"
@/components/FridgeItem.vue
"
;
import
EatFridgeItemModal
from
"
@/components/EatFridgeItemModal.vue
"
;
import
{
API
}
from
"
@/util/API
"
;
import
{
mapState
,
mapStores
}
from
"
pinia
"
;
import
{
useAuthStore
}
from
"
@/stores/authStore
"
;
import
{
useFridgeStore
}
from
"
@/stores/fridgeStore
"
;
export
default
{
name
:
"
FridgeView
"
,
components
:
{
EatFridgeItemModal
,
FridgeItem
},
computed
:{
...
mapState
(
useAuthStore
,
[
'
account
'
]),
...
mapStores
(
useFridgeStore
),
},
data
()
{
return
{
visible
:
false
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment