Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
CaCaoCritics
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
Container 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
Bilel El Yaagoubi
CaCaoCritics
Commits
c092f8c1
Commit
c092f8c1
authored
2 years ago
by
Bilel El Yaagoubi
Browse files
Options
Downloads
Patches
Plain Diff
You can now like
parent
41672658
Branches
Branches containing commit
No related tags found
1 merge request
!20
You can now like
Pipeline
#42632
passed
2 years ago
Stage: lint
Stage: build
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
backend/routes/users.js
+33
-5
33 additions, 5 deletions
backend/routes/users.js
frontend/src/components/MovieInfos.vue
+51
-7
51 additions, 7 deletions
frontend/src/components/MovieInfos.vue
with
84 additions
and
12 deletions
backend/routes/users.js
+
33
−
5
View file @
c092f8c1
...
@@ -9,6 +9,18 @@ router.get("/", function (req, res) {
...
@@ -9,6 +9,18 @@ router.get("/", function (req, res) {
});
});
});
});
router
.
get
(
"
/isliked/:movieId/:userId
"
,
async
function
(
req
,
res
)
{
const
userId
=
await
req
.
params
[
"
userId
"
];
console
.
log
(
userId
);
const
movieId
=
await
req
.
params
[
"
movieId
"
];
const
user
=
await
UserModel
.
findById
(
userId
);
const
movieOid
=
await
MovieModel
.
findOne
({
id
:
movieId
});
const
likedMovies
=
user
.
liked_movies
;
const
myIndex
=
likedMovies
.
indexOf
(
movieOid
.
_id
)
+
1
;
console
.
log
(
Boolean
(
myIndex
));
res
.
send
(
Boolean
(
myIndex
));
});
router
.
post
(
"
/new
"
,
function
(
req
,
res
)
{
router
.
post
(
"
/new
"
,
function
(
req
,
res
)
{
const
newUser
=
new
UserModel
({
const
newUser
=
new
UserModel
({
email
:
req
.
body
.
email
,
email
:
req
.
body
.
email
,
...
@@ -39,11 +51,22 @@ router.put("/like", async function (req, res) {
...
@@ -39,11 +51,22 @@ router.put("/like", async function (req, res) {
const
movieId
=
await
req
.
body
.
movieId
;
const
movieId
=
await
req
.
body
.
movieId
;
const
movieOid
=
await
MovieModel
.
findOne
({
id
:
movieId
});
const
movieOid
=
await
MovieModel
.
findOne
({
id
:
movieId
});
const
user
=
await
UserModel
.
findById
(
userId
);
const
user
=
await
UserModel
.
findById
(
userId
);
const
likedMovies
=
user
.
liked_movies
.
concat
([
movieOid
.
_id
]);
const
likedMovies
=
user
.
liked_movies
;
const
myIndex
=
likedMovies
.
indexOf
(
movieOid
.
_id
);
if
(
myIndex
==
-
1
)
{
likedMovies
.
splice
(
myIndex
,
1
);
await
UserModel
.
findByIdAndUpdate
(
userId
,
{
await
UserModel
.
findByIdAndUpdate
(
userId
,
{
liked_movies
:
likedMovies
,
liked_movies
:
likedMovies
.
concat
([
movieOid
.
_id
])
,
});
});
console
.
log
(
movieOid
.
title
);
console
.
log
(
movieOid
.
_id
);
res
.
send
(
"
Done
"
);
res
.
send
(
"
Done
"
);
}
else
{
console
.
log
(
movieOid
.
title
);
console
.
log
(
movieOid
.
_id
);
console
.
log
(
"
This movie is already liked
"
);
res
.
send
(
"
This movie is already liked
"
);
}
}
catch
(
error
)
{
}
catch
(
error
)
{
console
.
log
(
error
);
console
.
log
(
error
);
res
.
send
(
"
Internal problem
"
);
res
.
send
(
"
Internal problem
"
);
...
@@ -64,8 +87,13 @@ router.put("/unlike", async function (req, res) {
...
@@ -64,8 +87,13 @@ router.put("/unlike", async function (req, res) {
liked_movies
:
likedMovies
,
liked_movies
:
likedMovies
,
});
});
res
.
send
(
"
Done
"
);
res
.
send
(
"
Done
"
);
console
.
log
(
movieOid
.
title
);
console
.
log
(
movieOid
.
_id
);
}
else
{
}
else
{
res
.
send
(
"
This movie wasn't liked
"
);
res
.
send
(
"
This movie wasn't liked
"
);
console
.
log
(
movieOid
.
title
);
console
.
log
(
movieOid
.
_id
);
console
.
log
(
"
This movie wasn't liked
"
);
}
}
}
catch
(
error
)
{
}
catch
(
error
)
{
console
.
log
(
error
);
console
.
log
(
error
);
...
...
This diff is collapsed.
Click to expand it.
frontend/src/components/MovieInfos.vue
+
51
−
7
View file @
c092f8c1
...
@@ -22,7 +22,7 @@ export default {
...
@@ -22,7 +22,7 @@ export default {
data
:
function
()
{
data
:
function
()
{
return
{
return
{
genreArray
:
[],
genreArray
:
[],
liking
:
"
Unlike
"
,
liking
:
true
,
userId
:
"
toto
"
,
userId
:
"
toto
"
,
};
};
},
},
...
@@ -55,11 +55,45 @@ export default {
...
@@ -55,11 +55,45 @@ export default {
}
}
},
},
handleLike
:
async
function
()
{
handleLike
:
async
function
()
{
if
(
this
.
liking
==
"
Unlike
"
)
{
console
.
log
(
"
clic
"
);
await
axios
.
put
(
backendURL
+
"
/users/unlike/
"
,
{
userId
:
this
.
userId
,
movieId
:
this
.
movieId
,
});
this
.
getLiking
().
then
((
results
)
=>
{
console
.
log
(
results
);
if
(
results
)
{
this
.
liking
=
"
Unlike
"
;
}
else
{
this
.
liking
=
"
Like
"
;
}
});
}
else
{
console
.
log
(
"
clic
"
);
console
.
log
(
"
clic
"
);
await
axios
.
put
(
backendURL
+
"
/users/like/
"
,
{
await
axios
.
put
(
backendURL
+
"
/users/like/
"
,
{
userId
:
this
.
userId
,
userId
:
this
.
userId
,
movieId
:
this
.
movieId
,
movieId
:
this
.
movieId
,
});
});
this
.
getLiking
().
then
((
results
)
=>
{
console
.
log
(
results
);
if
(
results
)
{
this
.
liking
=
"
Unlike
"
;
}
else
{
this
.
liking
=
"
Like
"
;
}
});
}
},
getLiking
:
async
function
()
{
try
{
const
likingValue
=
await
axios
.
get
(
backendURL
+
"
/users/isliked/
"
+
this
.
movieId
+
"
/
"
+
this
.
userId
);
return
likingValue
.
data
;
}
catch
(
error
)
{
console
.
log
(
error
);
}
},
},
},
},
created
()
{
created
()
{
...
@@ -67,6 +101,14 @@ export default {
...
@@ -67,6 +101,14 @@ export default {
this
.
genreArray
=
results
;
this
.
genreArray
=
results
;
});
});
this
.
userId
=
this
.
$route
.
query
.
uid
;
this
.
userId
=
this
.
$route
.
query
.
uid
;
this
.
getLiking
().
then
((
results
)
=>
{
console
.
log
(
results
);
if
(
results
)
{
this
.
liking
=
"
Unlike
"
;
}
else
{
this
.
liking
=
"
Like
"
;
}
});
console
.
log
(
this
.
userId
);
console
.
log
(
this
.
userId
);
},
},
};
};
...
@@ -85,11 +127,12 @@ export default {
...
@@ -85,11 +127,12 @@ export default {
.mark
{
.mark
{
text-align
:
center
;
text-align
:
center
;
vertical-align
:
center
;
vertical-align
:
center
;
width
:
1
0
%
;
width
:
1
5
%
;
height
:
auto
;
height
:
auto
;
background-color
:
#912f56
;
background-color
:
#912f56
;
border-radius
:
25%
;
border-radius
:
25%
;
margin-left
:
auto
;
margin-left
:
auto
;
color
:
#eaf2ef
;
}
}
.like_button
{
.like_button
{
text-align
:
center
;
text-align
:
center
;
...
@@ -102,5 +145,6 @@ export default {
...
@@ -102,5 +145,6 @@ export default {
margin-right
:
auto
;
margin-right
:
auto
;
margin-bottom
:
auto
;
margin-bottom
:
auto
;
cursor
:
pointer
;
cursor
:
pointer
;
color
:
#eaf2ef
;
}
}
</
style
>
</
style
>
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