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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Bilel El Yaagoubi
CaCaoCritics
Commits
01d117cd
Commit
01d117cd
authored
3 years ago
by
Bilel El Yaagoubi
Browse files
Options
Downloads
Patches
Plain Diff
start of work
parent
c1e556d0
Branches
Branches containing commit
No related tags found
1 merge request
!5
Draft: Front bilel
Pipeline
#42443
passed
3 years ago
Stage: lint
Stage: build
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
backend/models/movies.js
+12
-0
12 additions, 0 deletions
backend/models/movies.js
backend/routes/movies.js
+30
-0
30 additions, 0 deletions
backend/routes/movies.js
backend/server.js
+3
-0
3 additions, 0 deletions
backend/server.js
with
45 additions
and
0 deletions
backend/models/movies.js
0 → 100644
+
12
−
0
View file @
01d117cd
const
mongoose
=
require
(
"
mongoose
"
);
const
MovieSchema
=
new
mongoose
.
Schema
({
publisher
:
{
type
:
String
,
required
:
true
},
title
:
{
type
:
String
,
required
:
true
,
unique
:
true
},
date
:
{
type
:
String
},
imageURL
:
{
type
:
String
},
});
const
MovieModel
=
mongoose
.
model
(
"
MovieModel
"
,
MovieSchema
,
"
movies
"
);
module
.
exports
=
MovieModel
;
This diff is collapsed.
Click to expand it.
backend/routes/movies.js
0 → 100644
+
30
−
0
View file @
01d117cd
const
express
=
require
(
"
express
"
);
const
MovieModel
=
require
(
"
../models/movies
"
);
const
router
=
express
.
Router
();
module
.
exports
=
router
;
router
.
get
(
"
/
"
,
function
(
req
,
res
)
{
res
.
send
(
"
Hello world
"
);
});
router
.
post
(
"
/new
"
,
async
function
(
req
,
res
)
{
try
{
const
newMovie
=
new
MovieModel
({
// Movie attributes
publisher
:
req
.
body
.
publisher
,
title
:
req
.
body
.
title
,
date
:
req
.
body
.
date
,
imageURL
:
req
.
body
.
imageURL
,
});
// Create a new movie instance
const
createdMovie
=
await
newMovie
.
save
();
// What to do after movie has been saved !
console
.
log
(
"
Movie Saved
"
);
res
.
send
(
createdMovie
);
}
catch
(
error
)
{
console
.
log
(
error
);
}
});
This diff is collapsed.
Click to expand it.
backend/server.js
+
3
−
0
View file @
01d117cd
...
@@ -4,6 +4,7 @@ const cors = require("cors");
...
@@ -4,6 +4,7 @@ const cors = require("cors");
const
mongoose
=
require
(
"
mongoose
"
);
const
mongoose
=
require
(
"
mongoose
"
);
const
indexRouter
=
require
(
"
./routes/index
"
);
const
indexRouter
=
require
(
"
./routes/index
"
);
const
usersRouter
=
require
(
"
./routes/users
"
);
const
usersRouter
=
require
(
"
./routes/users
"
);
const
moviesRouter
=
require
(
"
./routes/movies
"
);
const
routeNotFoundJsonHandler
=
require
(
"
./services/routeNotFoundJsonHandler
"
);
const
routeNotFoundJsonHandler
=
require
(
"
./services/routeNotFoundJsonHandler
"
);
const
jsonErrorHandler
=
require
(
"
./services/jsonErrorHandler
"
);
const
jsonErrorHandler
=
require
(
"
./services/jsonErrorHandler
"
);
...
@@ -20,6 +21,8 @@ app.use(express.urlencoded({ extended: false }));
...
@@ -20,6 +21,8 @@ app.use(express.urlencoded({ extended: false }));
app
.
use
(
"
/
"
,
indexRouter
);
app
.
use
(
"
/
"
,
indexRouter
);
app
.
use
(
"
/users
"
,
usersRouter
);
app
.
use
(
"
/users
"
,
usersRouter
);
app
.
use
(
"
/movies
"
,
moviesRouter
);
// Register 404 middleware and error handler
// Register 404 middleware and error handler
app
.
use
(
routeNotFoundJsonHandler
);
// this middleware must be registered after all routes to handle 404 correctly
app
.
use
(
routeNotFoundJsonHandler
);
// this middleware must be registered after all routes to handle 404 correctly
app
.
use
(
jsonErrorHandler
);
// this error handler must be registered after all middlewares to catch all errors
app
.
use
(
jsonErrorHandler
);
// this error handler must be registered after all middlewares to catch all errors
...
...
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