-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fd6895c
commit 94fc54c
Showing
10 changed files
with
1,078 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
const Video = require('../models/video') | ||
|
||
const postVideo = async (req, res, next) => { | ||
try { | ||
await Video.create({...req.body}); | ||
await res.status(201).json({ | ||
'message' : 'success' | ||
}); | ||
} | ||
|
||
catch(err) { | ||
await res.status(500).json({ | ||
'error' : err | ||
}); | ||
} | ||
}; | ||
|
||
const getVideo = async (req, res, next) => { | ||
try { | ||
const videoId = req.params['videoId']; | ||
const video = await Video.findById(videoId); | ||
await res.status(200).json({ | ||
'message' : 'success', | ||
'Video': video | ||
}); | ||
} | ||
|
||
catch(err) { | ||
await res.status(500).json({ | ||
'error' : err | ||
}); | ||
} | ||
|
||
}; | ||
|
||
const updateVideo = async (req, res, next) => { | ||
try { | ||
const videoId = req.params['videoId']; | ||
await Video.findByIdAndUpdate(videoId, {...req.body, 'updatedAt' : Date.now()}); | ||
await res.status(200).json({ | ||
'message' : 'success' | ||
}); | ||
} | ||
|
||
catch(err) { | ||
await res.status(500).json({ | ||
'error' : err | ||
}); | ||
} | ||
}; | ||
|
||
const deleteVideo = async (req, res, next) => { | ||
try { | ||
const videoId = req.params['videoId']; | ||
await Video.findByIdAndDelete(videoId); | ||
await res.status(200).json({ | ||
'message' : 'success' | ||
}); | ||
} | ||
|
||
catch(err) { | ||
await res.status(500).json({ | ||
'error' : err | ||
}); | ||
} | ||
}; | ||
|
||
module.exports = { postVideo, getVideo, updateVideo, deleteVideo }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const mongoose = require('mongoose') | ||
const Schema = mongoose.Schema | ||
|
||
const videoSchema = new Schema({ | ||
location : { | ||
type : String, | ||
required : true | ||
}, | ||
videoURL : { | ||
type : String, | ||
required : true | ||
} | ||
}) | ||
|
||
module.exports = mongoose.model('Video', videoSchema) |
Oops, something went wrong.