From 09f0436f986639f8e4e79f24376730679ae57431 Mon Sep 17 00:00:00 2001
From: Adrian Thompson
Date: Thu, 27 Aug 2020 13:25:44 +0200
Subject: [PATCH 01/22] add search functionality
---
api/vinmonopolet.js | 0
api/wineinfo.js | 46 ++++++++++++++++++++++++++++++++++
src/api.js | 16 ++++++++++++
src/components/RequestWine.vue | 44 ++++++++++++++++++++++++++++++++
src/routes/vinlottisRouter.js | 6 +++++
5 files changed, 112 insertions(+)
create mode 100644 api/vinmonopolet.js
create mode 100644 src/components/RequestWine.vue
diff --git a/api/vinmonopolet.js b/api/vinmonopolet.js
new file mode 100644
index 0000000..e69de29
diff --git a/api/wineinfo.js b/api/wineinfo.js
index 237de19..8c444dd 100644
--- a/api/wineinfo.js
+++ b/api/wineinfo.js
@@ -9,6 +9,52 @@ router.use((req, res, next) => {
next();
});
+const convertToOurWineObject = wine => {
+ console.log("traff her", wine)
+ return {
+ name: wine.basic.productShortName,
+ image: `https://bilder.vinmonopolet.no/cache/300x300-0/${wine.basic.productId}-1.jpg`,
+ rating: undefined,
+ price: wine.prices[0].salesPrice,
+ country: wine.origins.origin.country,
+ vivinoLink: undefined
+ }
+}
+
+router.route("/wineinfo/search").get(async (req, res) => {
+ console.log("h")
+ console.log(req)
+ const {query} = req.query
+ let url = new URL(`https://apis.vinmonopolet.no/products/v0/details-normal?productShortNameContains=test&maxResults=5`)
+ url.searchParams.set('productShortNameContains', query)
+
+ const vinmonopoletResponse = await fetch(url, {
+ headers: {
+ "Ocp-Apim-Subscription-Key": ""
+ }
+ })
+ .then(resp => resp.json())
+
+ const winesConverted = vinmonopoletResponse.map(convertToOurWineObject)
+ console.log(winesConverted)
+
+ if (vinmonopoletResponse.errors != null) {
+ return vinmonopoletResponse.errors.map(error => {
+ if (error.type == "UnknownProductError") {
+ return res.status(404).json({
+ message: error.message
+ })
+ } else {
+ return next()
+ }
+ })
+ }
+
+ res.send(winesConverted);
+});
+
+
+
router.route("/wineinfo/:ean").get(async (req, res) => {
const vinmonopoletResponse = await fetch("https://app.vinmonopolet.no/vmpws/v2/vmp/products/barCodeSearch/" + req.params.ean)
.then(resp => resp.json())
diff --git a/src/api.js b/src/api.js
index eb6d3c2..395de2d 100644
--- a/src/api.js
+++ b/src/api.js
@@ -160,6 +160,21 @@ const barcodeToVinmonopolet = id => {
});
};
+const searchForWine = searchString => {
+ const url = new URL("/api/wineinfo/search?query=" + searchString, BASE_URL);
+
+ return fetch(url.href).then(async resp => {
+ if (!resp.ok) {
+ if (resp.status == 404) {
+ throw await resp.json();
+ }
+ } else {
+ return resp.json();
+ }
+ });
+};
+
+
const handleErrors = async resp => {
if ([400, 409].includes(resp.status)) {
throw await resp.json();
@@ -269,6 +284,7 @@ export {
logWines,
wineSchema,
barcodeToVinmonopolet,
+ searchForWine,
login,
register,
addAttendee,
diff --git a/src/components/RequestWine.vue b/src/components/RequestWine.vue
new file mode 100644
index 0000000..b1af2f3
--- /dev/null
+++ b/src/components/RequestWine.vue
@@ -0,0 +1,44 @@
+
+
+
+ Anbefal en vin!
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/routes/vinlottisRouter.js b/src/routes/vinlottisRouter.js
index 32ae017..9a2e9cf 100644
--- a/src/routes/vinlottisRouter.js
+++ b/src/routes/vinlottisRouter.js
@@ -12,6 +12,8 @@ import WinnerPage from "@/components/WinnerPage";
import LotteryPage from "@/components/LotteryPage";
import HistoryPage from "@/components/HistoryPage";
+import RequestWine from "@/components/RequestWine";
+
const routes = [
{
path: "*",
@@ -52,6 +54,10 @@ const routes = [
{
path: "/history",
component: HistoryPage
+ },
+ {
+ path: "/request",
+ component: RequestWine
}
];
From 15b84a9b18c3c90e20341e12a81771f8256ddaba Mon Sep 17 00:00:00 2001
From: Adrian Thompson
Date: Thu, 27 Aug 2020 15:15:43 +0200
Subject: [PATCH 02/22] add token and some styling
---
.gitignore | 1 +
api/wineinfo.js | 25 ++++++------
src/components/RequestWine.vue | 72 ++++++++++++++++++++++++++++++----
3 files changed, 77 insertions(+), 21 deletions(-)
diff --git a/.gitignore b/.gitignore
index 86fe51d..2a2c678 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,6 +4,7 @@ public/index.html
public/sw/
config/env/lottery.config.js
config/env/push.config.js
+config/env/vinmonopolet.config.js
# Logs
logs
diff --git a/api/wineinfo.js b/api/wineinfo.js
index 8c444dd..1b4c7ff 100644
--- a/api/wineinfo.js
+++ b/api/wineinfo.js
@@ -2,6 +2,7 @@ const express = require("express");
const path = require("path");
const router = express.Router();
const fetch = require('node-fetch')
+const config = require(path.join(__dirname + "/../config/env/vinmonopolet.config"));
const mustBeAuthenticated = require(path.join(__dirname + "/../middleware/mustBeAuthenticated"))
@@ -10,33 +11,31 @@ router.use((req, res, next) => {
});
const convertToOurWineObject = wine => {
- console.log("traff her", wine)
- return {
- name: wine.basic.productShortName,
- image: `https://bilder.vinmonopolet.no/cache/300x300-0/${wine.basic.productId}-1.jpg`,
- rating: undefined,
- price: wine.prices[0].salesPrice,
- country: wine.origins.origin.country,
- vivinoLink: undefined
+ if(wine.basic.ageLimit === "18"){
+ return {
+ name: wine.basic.productShortName,
+ image: `https://bilder.vinmonopolet.no/cache/300x300-0/${wine.basic.productId}-1.jpg`,
+ rating: undefined,
+ price: wine.prices[0].salesPrice,
+ country: wine.origins.origin.country,
+ vivinoLink: undefined
+ }
}
}
router.route("/wineinfo/search").get(async (req, res) => {
- console.log("h")
- console.log(req)
const {query} = req.query
let url = new URL(`https://apis.vinmonopolet.no/products/v0/details-normal?productShortNameContains=test&maxResults=5`)
url.searchParams.set('productShortNameContains', query)
const vinmonopoletResponse = await fetch(url, {
headers: {
- "Ocp-Apim-Subscription-Key": ""
+ "Ocp-Apim-Subscription-Key": `${config.gatewayToken}`
}
})
.then(resp => resp.json())
- const winesConverted = vinmonopoletResponse.map(convertToOurWineObject)
- console.log(winesConverted)
+ const winesConverted = vinmonopoletResponse.map(convertToOurWineObject).filter(Boolean)
if (vinmonopoletResponse.errors != null) {
return vinmonopoletResponse.errors.map(error => {
diff --git a/src/components/RequestWine.vue b/src/components/RequestWine.vue
index b1af2f3..d02c6f0 100644
--- a/src/components/RequestWine.vue
+++ b/src/components/RequestWine.vue
@@ -1,16 +1,30 @@
- Anbefal en vin!
+ Foreslå en vin!
@@ -39,6 +53,48 @@ export default {
}
-
\ No newline at end of file
From f785a111d852244a0d199baf1e0fd7950a941d76 Mon Sep 17 00:00:00 2001
From: Adrian Thompson
Date: Thu, 27 Aug 2020 16:50:04 +0200
Subject: [PATCH 03/22] cleanup
---
api/wineinfo.js | 4 +-
src/components/RequestWine.vue | 93 +++++++++++++++++++++++++---------
src/styles/global.scss | 6 ++-
3 files changed, 75 insertions(+), 28 deletions(-)
diff --git a/api/wineinfo.js b/api/wineinfo.js
index 1b4c7ff..37afbf2 100644
--- a/api/wineinfo.js
+++ b/api/wineinfo.js
@@ -15,10 +15,10 @@ const convertToOurWineObject = wine => {
return {
name: wine.basic.productShortName,
image: `https://bilder.vinmonopolet.no/cache/300x300-0/${wine.basic.productId}-1.jpg`,
- rating: undefined,
+ rating: wine.basic.alcoholContent,
price: wine.prices[0].salesPrice,
country: wine.origins.origin.country,
- vivinoLink: undefined
+ vivinoLink: "https://www.vinmonopolet.no/p/" + wine.basic.productId
}
}
}
diff --git a/src/components/RequestWine.vue b/src/components/RequestWine.vue
index d02c6f0..75a189a 100644
--- a/src/components/RequestWine.vue
+++ b/src/components/RequestWine.vue
@@ -4,8 +4,10 @@
Foreslå en vin!
+
+ Fant ingen viner med det navnet!
+
@@ -40,14 +52,15 @@ export default {
data() {
return {
searchString: undefined,
- res: undefined,
wines: undefined,
}
},
methods: {
fetchWineFromVin(){
- searchForWine(this.searchString)
- .then(res => this.wines = res)
+ if(this.searchString){
+ searchForWine(this.searchString)
+ .then(res => this.wines = res)
+ }
},
},
}
@@ -61,6 +74,7 @@ export default {
main{
margin: auto;
width: 80%;
+ text-align: center;
}
input[type="text"] {
@@ -69,32 +83,61 @@ input[type="text"] {
border-radius: 4px;
padding: 0.5rem 1rem;
border: 1px solid black;
- max-width: 200px;
+ max-width: 80%;
+}
+
+.search-section{
+ display: flex;
+ justify-content: space-around;
+ flex-flow: row;
}
.search-results-container{
display: flex;
- border: 1px solid black;
+ padding: 3px;
+ border-radius: 1px;
+ box-shadow: 0px 0px 0px 1px rgba(0,0,0,0.3);
+ margin: 1rem 0;
+ justify-content: space-around;
+ flex-flow: row wrap;
+ align-items: stretch;
+
+
+ .wine-image {
+ height: 100px;
+ }
+
+ .wine-placeholder {
+ height: 100px;
+ width: 70px;
+ }
+
+ .wine-info{
+ display: flex;
+ flex-direction: column;
+ .__details{
+ display: flex;
+ flex-direction: column;
+ }
+ }
+ .wine-link {
+ color: #333333;
+ font-family: Arial;
+ text-decoration: none;
+ font-weight: bold;
+ border-bottom: 1px solid #ff5fff;
+ width: fit-content;
+ }
.buttons{
- margin-left: auto;
+ display: flex;
+ align-items: center;
order: 2;
+ justify-content: space-between;
+ width: 40%;
+ margin-right: 1rem;
}
}
-.wine-image {
- height: 100px;
-}
-
-.wine-placeholder {
- height: 100px;
- width: 70px;
-}
-
-.wine-info{
- display: flex;
- flex-direction: column;
-}
-
\ No newline at end of file
diff --git a/src/styles/global.scss b/src/styles/global.scss
index 57e3251..cc89a83 100644
--- a/src/styles/global.scss
+++ b/src/styles/global.scss
@@ -133,13 +133,17 @@ textarea {
0 16px 32px rgba(0, 0, 0, 0.07), 0 32px 64px rgba(0, 0, 0, 0.07);
}
- &:hover {
+ &:hover:not(:disabled) {
transform: scale(1.02) translateZ(0);
&::after {
opacity: 1;
}
}
+ &:disabled{
+ opacity: 0.25;
+ cursor: not-allowed;
+ }
}
.no-margin {
From 7b7895728bdc835a3dd6c65d24f3343f986aea34 Mon Sep 17 00:00:00 2001
From: Adrian Thompson
Date: Fri, 28 Aug 2020 17:01:53 +0200
Subject: [PATCH 04/22] loko
---
api/request.js | 60 ++++++++++++++++++++++++++++++++++
api/wineinfo.js | 14 ++++----
server.js | 2 ++
src/components/RequestWine.vue | 22 +++++++++++--
4 files changed, 90 insertions(+), 8 deletions(-)
create mode 100644 api/request.js
diff --git a/api/request.js b/api/request.js
new file mode 100644
index 0000000..d2aca2b
--- /dev/null
+++ b/api/request.js
@@ -0,0 +1,60 @@
+const express = require("express");
+const path = require("path");
+const router = express.Router();
+const fetch = require('node-fetch');
+const { send } = require("process");
+const RequestedWine = require(path.join(
+ __dirname + "/../schemas/RequestedWine"
+));
+const Wine = require(path.join(
+ __dirname + "/../schemas/Wine"
+));
+
+router.use((req, res, next) => {
+ next();
+});
+
+
+router.route("/request").get(async (req, res) => {
+ const rWines = await RequestedWine.find({}).populate("wine")
+ return res.send(rWines)
+})
+
+router.route("/request").post(async (req, res) => {
+ const {wine} = req.body
+ console.log(wine)
+
+ let thisWineIsLOKO = await Wine.findOne({id: wine.id})
+
+ if(thisWineIsLOKO == undefined){
+ thisWineIsLOKO = new Wine({
+ name: wine.name,
+ vivinoLink: wine.vivinoLink,
+ rating: null,
+ occurences: null,
+ image: wine.image,
+ id: wine.id
+ });
+ await thisWineIsLOKO.save()
+ }
+ console.log(thisWineIsLOKO)
+
+ let requestedWine = await RequestedWine.findOne({ "wineId": wine.id})
+
+ if(requestedWine == undefined){
+ // console.log(localWine)
+ requestedWine = new RequestedWine({
+ count: 1,
+ wineId: wine.id,
+ wine: thisWineIsLOKO
+ })
+ } else {
+ requestedWine.count += 1;
+ }
+ await requestedWine.save()
+
+ res.send(requestedWine);
+
+});
+
+module.exports = router;
diff --git a/api/wineinfo.js b/api/wineinfo.js
index 37afbf2..053a68c 100644
--- a/api/wineinfo.js
+++ b/api/wineinfo.js
@@ -14,11 +14,13 @@ const convertToOurWineObject = wine => {
if(wine.basic.ageLimit === "18"){
return {
name: wine.basic.productShortName,
- image: `https://bilder.vinmonopolet.no/cache/300x300-0/${wine.basic.productId}-1.jpg`,
+ vivinoLink: "https://www.vinmonopolet.no/p/" + wine.basic.productId,
rating: wine.basic.alcoholContent,
- price: wine.prices[0].salesPrice,
- country: wine.origins.origin.country,
- vivinoLink: "https://www.vinmonopolet.no/p/" + wine.basic.productId
+ occurences: 0,
+ id: wine.basic.productId,
+ image: `https://bilder.vinmonopolet.no/cache/300x300-0/${wine.basic.productId}-1.jpg`,
+ price: wine.prices[0].salesPrice.toString(),
+ country: wine.origins.origin.country
}
}
}
@@ -34,8 +36,8 @@ router.route("/wineinfo/search").get(async (req, res) => {
}
})
.then(resp => resp.json())
+ .catch(err => console.error(err))
- const winesConverted = vinmonopoletResponse.map(convertToOurWineObject).filter(Boolean)
if (vinmonopoletResponse.errors != null) {
return vinmonopoletResponse.errors.map(error => {
@@ -48,7 +50,7 @@ router.route("/wineinfo/search").get(async (req, res) => {
}
})
}
-
+ const winesConverted = vinmonopoletResponse.map(convertToOurWineObject).filter(Boolean)
res.send(winesConverted);
});
diff --git a/server.js b/server.js
index e0fef6f..8cd45e2 100644
--- a/server.js
+++ b/server.js
@@ -11,6 +11,7 @@ const retrieveApi = require(path.join(__dirname + "/api/retrieve"));
const subscriptionApi = require(path.join(__dirname + "/api/subscriptions"));
const loginApi = require(path.join(__dirname + "/api/login"));
const wineinfoApi = require(path.join(__dirname + "/api/wineinfo"));
+const requestApi = require(path.join(__dirname + "/api/request"));
const virtualApi = require(path.join(__dirname + "/api/virtualLottery"));
const virtualRegistrationApi = require(path.join(
__dirname + "/api/virtualRegistration"
@@ -94,6 +95,7 @@ app.use("/", loginApi);
app.use("/api/", updateApi);
app.use("/api/", retrieveApi);
app.use("/api/", wineinfoApi);
+app.use("/api/", requestApi);
app.use("/api/", chatHistory);
app.use("/api/lottery", lottery);
app.use("/api/virtual/", virtualApi(io));
diff --git a/src/components/RequestWine.vue b/src/components/RequestWine.vue
index 75a189a..edc217c 100644
--- a/src/components/RequestWine.vue
+++ b/src/components/RequestWine.vue
@@ -26,7 +26,7 @@
+
+
From 1c9524485021f1924ac80aab77a0b8a012333457 Mon Sep 17 00:00:00 2001
From: Adrian Thompson
Date: Mon, 31 Aug 2020 16:45:19 +0200
Subject: [PATCH 11/22] interface on requested wines with sub-par css
---
src/components/AllRequestedWines.vue | 24 +++++++---
src/ui/Modal.vue | 1 +
src/ui/RequestedWineCard.vue | 72 ++++++++++++++++++++++++++++
3 files changed, 90 insertions(+), 7 deletions(-)
create mode 100644 src/ui/RequestedWineCard.vue
diff --git a/src/components/AllRequestedWines.vue b/src/components/AllRequestedWines.vue
index 8b84f61..cabfb87 100644
--- a/src/components/AllRequestedWines.vue
+++ b/src/components/AllRequestedWines.vue
@@ -1,30 +1,40 @@
- Alle viner
+ Alle viner foreslåtte viner
-
-
\ No newline at end of file
diff --git a/src/ui/Modal.vue b/src/ui/Modal.vue
index 6d44ca6..0d0e8f8 100644
--- a/src/ui/Modal.vue
+++ b/src/ui/Modal.vue
@@ -97,4 +97,5 @@ export default {
position: relative;
padding: 20px 10px;
}
+
\ No newline at end of file
diff --git a/src/ui/RequestedWineCard.vue b/src/ui/RequestedWineCard.vue
new file mode 100644
index 0000000..76b30fd
--- /dev/null
+++ b/src/ui/RequestedWineCard.vue
@@ -0,0 +1,72 @@
+
+
+
![]()
+
![Wine image]()
+
+ {{ wine.name }}
+ (no name)
+ Antall ganger denne har blitt foreslått: {{requestedElement.count}}
+
+
+
+
+
+
+
+
\ No newline at end of file
From a5ae46f5c39b5497b66302f0fcb4c3f0cc50ab8e Mon Sep 17 00:00:00 2001
From: Adrian Thompson
Date: Tue, 1 Sep 2020 10:17:17 +0200
Subject: [PATCH 12/22] working delete requested wine if admin
---
api/request.js | 7 +++++++
src/api.js | 16 ++++++++++++++++
src/components/AllRequestedWines.vue | 15 ++++++++++-----
src/ui/RequestedWineCard.vue | 16 +++++++++++++++-
4 files changed, 48 insertions(+), 6 deletions(-)
diff --git a/api/request.js b/api/request.js
index 53511c9..d318beb 100644
--- a/api/request.js
+++ b/api/request.js
@@ -9,11 +9,18 @@ const RequestedWine = require(path.join(
const Wine = require(path.join(
__dirname + "/../schemas/Wine"
));
+const mustBeAuthenticated = require(path.join(
+ __dirname + "/../middleware/mustBeAuthenticated"
+));
router.use((req, res, next) => {
next();
});
+router.route("/request/").delete(mustBeAuthenticated, async (req, res) => {
+ await RequestedWine.deleteOne({wineId: req.body.id})
+ res.json(true);
+})
router.route("/request").get(async (req, res) => {
const rWines = await RequestedWine.find({}).populate("wine")
diff --git a/src/api.js b/src/api.js
index b549d22..1d5bb7f 100644
--- a/src/api.js
+++ b/src/api.js
@@ -100,6 +100,21 @@ const winners = () => {
return fetch(url.href).then(resp => resp.json());
};
+const deleteRequestedWine = wineToBeDeleted => {
+ console.log("when do i get here", wineToBeDeleted)
+ const url = new URL("api/request", BASE_URL);
+
+ const options = {
+ headers: {
+ "Content-Type": "application/json"
+ },
+ method: "DELETE",
+ body: JSON.stringify(wineToBeDeleted)
+ };
+
+ return fetch(url.href, options).then(resp => resp.json())
+}
+
const deleteWinners = () => {
const url = new URL("/api/virtual/winners", BASE_URL);
@@ -302,6 +317,7 @@ export {
winnersSecure,
deleteWinners,
deleteAttendees,
+ deleteRequestedWine,
getChatHistory,
finishedDraw,
getAmIWinner,
diff --git a/src/components/AllRequestedWines.vue b/src/components/AllRequestedWines.vue
index cabfb87..01033af 100644
--- a/src/components/AllRequestedWines.vue
+++ b/src/components/AllRequestedWines.vue
@@ -1,10 +1,10 @@
- Alle viner foreslåtte viner
+ Alle foreslåtte viner
@@ -22,9 +22,14 @@ export default {
canRequest: true
}
},
- async mounted() {
- const wines = await allRequestedWines();
- this.wines = wines
+ methods: {
+ async refreshData(){
+ const wines = await allRequestedWines()
+ this.wines = wines
+ }
+ },
+ mounted() {
+ this.refreshData()
}
}
diff --git a/src/ui/RequestedWineCard.vue b/src/ui/RequestedWineCard.vue
index 76b30fd..3c85be0 100644
--- a/src/ui/RequestedWineCard.vue
+++ b/src/ui/RequestedWineCard.vue
@@ -19,11 +19,16 @@
class="wine-link"
>Les mer på polet
+
From c38f5c88195c51572973e00172997afb74fcf1a8 Mon Sep 17 00:00:00 2001
From: Adrian Thompson
Date: Tue, 1 Sep 2020 10:44:54 +0200
Subject: [PATCH 13/22] some cleaning and empty wine list check
---
src/api.js | 2 +-
src/components/AllRequestedWines.vue | 4 ++++
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/src/api.js b/src/api.js
index 1d5bb7f..f08e3ed 100644
--- a/src/api.js
+++ b/src/api.js
@@ -101,7 +101,7 @@ const winners = () => {
};
const deleteRequestedWine = wineToBeDeleted => {
- console.log("when do i get here", wineToBeDeleted)
+
const url = new URL("api/request", BASE_URL);
const options = {
diff --git a/src/components/AllRequestedWines.vue b/src/components/AllRequestedWines.vue
index 01033af..ffd8d6c 100644
--- a/src/components/AllRequestedWines.vue
+++ b/src/components/AllRequestedWines.vue
@@ -4,6 +4,7 @@
Alle foreslåtte viner
+ Ingen har foreslått noe enda!
@@ -35,6 +36,9 @@ export default {