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
a0caa3af
Commit
a0caa3af
authored
3 years ago
by
Bilel El Yaagoubi
Browse files
Options
Downloads
Patches
Plain Diff
hop
parent
0704cf05
No related branches found
No related tags found
1 merge request
!5
Draft: Front bilel
Pipeline
#42477
failed
3 years ago
Stage: lint
Stage: build
Changes
4
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
backend/models/movie.js
+39
-16
39 additions, 16 deletions
backend/models/movie.js
backend/models/user.js
+5
-6
5 additions, 6 deletions
backend/models/user.js
backend/populate.js
+4
-4
4 additions, 4 deletions
backend/populate.js
backend/routes/movies.js
+15
-2
15 additions, 2 deletions
backend/routes/movies.js
with
63 additions
and
28 deletions
backend/models/movie.js
+
39
−
16
View file @
a0caa3af
const
mongoose
=
require
(
"
mongoose
"
);
const
{
Schema
}
=
mongoose
;
const
MovieSchema
=
new
mongoose
.
Schema
({
const
MovieSchema
=
new
mongoose
.
Schema
(
{
adult
:
{
type
:
Boolean
},
backdrop_path
:
{
type
:
String
},
genre_ids
:
[
Number
],
...
...
@@ -9,13 +9,36 @@ const MovieSchema = new mongoose.Schema({
original_language
:
{
type
:
String
},
original_title
:
{
type
:
String
},
overview
:
{
type
:
String
},
popularity
:
{
type
:
String
},
popularity
:
{
type
:
Number
},
poster_path
:
{
type
:
String
},
release_date
:
{
type
:
String
},
release_date
:
{
type
:
Date
},
title
:
{
type
:
String
},
video
:
{
type
:
Boolean
},
vote_average
:
{
type
:
String
},
vote_average
:
{
type
:
Number
},
vote_count
:
{
type
:
Number
},
},
{
toJSON
:
{
virtuals
:
true
},
// So `res.json()` and other `JSON.stringify()` functions include virtuals
toObject
:
{
virtuals
:
true
},
// So `console.log()` and other functions that use `toObject()` include virtuals
}
);
MovieSchema
.
virtual
(
"
liking_users
"
,
{
ref
:
"
UserModel
"
,
localField
:
"
_id
"
,
// The user _id should match the viewers field in movies
foreignField
:
"
liked_movies
"
,
});
MovieSchema
.
virtual
(
"
later_watchers
"
,
{
ref
:
"
UserModel
"
,
localField
:
"
_id
"
,
// The user _id should match the viewers field in movies
foreignField
:
"
to_see_later
"
,
});
MovieSchema
.
virtual
(
"
masking_users
"
,
{
ref
:
"
UserModel
"
,
localField
:
"
_id
"
,
// The user _id should match the viewers field in movies
foreignField
:
"
masked_movies
"
,
});
const
MovieModel
=
mongoose
.
model
(
...
...
This diff is collapsed.
Click to expand it.
backend/models/user.js
+
5
−
6
View file @
a0caa3af
const
mongoose
=
require
(
"
mongoose
"
);
const
{
Schema
}
=
mongoose
;
const
UserSchema
=
new
mongoose
.
Schema
(
{
email
:
{
type
:
String
,
required
:
true
,
unique
:
true
},
firstName
:
{
type
:
String
},
lastName
:
{
type
:
String
},
is_admin
:
{
type
:
Boolean
},
liked_movies
:
[{
type
:
Schema
.
Types
.
ObjectId
,
ref
:
"
MovieModel
"
}],
to_see_later
:
[{
type
:
Schema
.
Types
.
ObjectId
,
ref
:
"
MovieModel
"
}],
masked_movies
:
[{
type
:
Schema
.
Types
.
ObjectId
,
ref
:
"
MovieModel
"
}],
},
{
toJSON
:
{
virtuals
:
true
},
// So `res.json()` and other `JSON.stringify()` functions include virtuals
...
...
@@ -12,12 +17,6 @@ const UserSchema = new mongoose.Schema(
}
);
UserSchema
.
virtual
(
"
watchedMovies
"
,
{
ref
:
"
MovieModel
"
,
localField
:
"
_id
"
,
// The user _id should match the viewers field in movies
foreignField
:
"
viewers
"
,
});
const
UserModel
=
mongoose
.
model
(
"
UserModel
"
,
UserSchema
,
"
users
"
);
module
.
exports
=
UserModel
;
This diff is collapsed.
Click to expand it.
backend/populate.js
+
4
−
4
View file @
a0caa3af
...
...
@@ -61,12 +61,12 @@ async function dropDataBase() {
}
}
async
function
populate
()
{
async
function
populate
(
N
)
{
// Connect mongoose client
const
client
=
await
mongoose
.
connect
(
process
.
env
.
MONGO_DB_URL
);
await
dropDataBase
();
for
(
let
n
=
1
;
n
<
300
;
n
++
)
{
for
(
let
n
=
1
;
n
<
N
;
n
++
)
{
const
movies
=
await
fetchMoviesFromTheMovieDatabase
(
n
);
await
populateMovies
(
movies
);
console
.
log
(
n
);
...
...
@@ -76,7 +76,7 @@ async function populate() {
// await client.disconnect();
}
populate
(
2
)
populate
(
N
)
.
then
(()
=>
{
console
.
log
(
"
All done !
"
);
})
...
...
This diff is collapsed.
Click to expand it.
backend/routes/movies.js
+
15
−
2
View file @
a0caa3af
...
...
@@ -4,9 +4,22 @@ const router = express.Router();
module
.
exports
=
router
;
router
.
get
(
"
/
"
,
async
function
(
req
,
res
)
{
router
.
get
(
"
/
popular/:number
"
,
async
function
(
req
,
res
)
{
try
{
const
getMovies
=
await
MovieModel
.
find
({}).
populate
(
"
viewers
"
);
const
filmNumber
=
await
req
.
params
[
"
number
"
];
const
getMovies
=
await
MovieModel
.
find
({})
.
sort
({
popularity
:
"
desc
"
})
.
limit
(
filmNumber
);
res
.
send
(
getMovies
);
}
catch
(
error
)
{
console
.
log
(
error
);
}
});
router
.
get
(
"
/id/:id
"
,
async
function
(
req
,
res
)
{
try
{
const
movieId
=
await
req
.
params
[
"
id
"
];
const
getMovies
=
await
MovieModel
.
findOne
({
id
:
movieId
});
res
.
send
(
getMovies
);
}
catch
(
error
)
{
console
.
log
(
error
);
...
...
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