-
Notifications
You must be signed in to change notification settings - Fork 0
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
edc071a
commit d417cfe
Showing
10 changed files
with
240 additions
and
89 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
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,20 @@ | ||
const Topic = require('../models/topic') | ||
const jwt = require("jsonwebtoken"); | ||
|
||
|
||
exports.getAllTopics = async (req, res) => { | ||
// console.log(req.email) | ||
|
||
try{ | ||
const topics = await Topic.find().select('title no videoUrl _id') | ||
res.status(200).json(topics) | ||
} | ||
catch(err){ | ||
res.status(500).json({error: err}) | ||
} | ||
} | ||
|
||
|
||
|
||
|
||
|
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,28 @@ | ||
// repositories/useroRepository.js | ||
|
||
const Topic = require('../models/topic'); | ||
|
||
class TopicRepository { | ||
async getAll() { | ||
return await Topic.find().exec() | ||
} | ||
|
||
// async getById(userId){ | ||
// return await Topic.findById(userId).exec() | ||
// } | ||
|
||
// async create(userInfo) { | ||
// const user = new User(userInfo) | ||
// return await user.save() | ||
// } | ||
|
||
// async deleteById(useId){ | ||
// return await User.findByIdAndDelete(useId) | ||
// } | ||
|
||
// async updateById(userId, userInfo){ | ||
// return await User.findByIdAndUpdate(userId,userInfo) | ||
// } | ||
} | ||
|
||
module.exports = TopicRepository |
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,36 @@ | ||
const express = require('express'); | ||
const router = express.Router(); | ||
const jwt = require("jsonwebtoken"); | ||
const topicController = require('../controllers/topicController'); | ||
require('dotenv').config(); | ||
|
||
|
||
const verifyUser = (req,res,next) => { | ||
const token = req.cookies.token | ||
if(!token){ | ||
res.json({msg:"provide token!"}) | ||
} | ||
else{ | ||
jwt.verify(token,process.env.SECURITY_KEY, (err,decoded)=>{ | ||
if(err){ | ||
try { | ||
res.clearCookie('token') | ||
res.json({ msg: "Done" }) | ||
} | ||
catch (err) { | ||
res.status(404).json({error:err}) | ||
} | ||
} | ||
else{ | ||
req.email = decoded.email | ||
next() | ||
} | ||
}) | ||
} | ||
} | ||
|
||
router.get('/topics',verifyUser,topicController.getAllTopics) | ||
|
||
|
||
|
||
module.exports = router; |
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,39 @@ | ||
// services/topicService.js | ||
|
||
const TopicRepository = require('../repositories/topicRepository'); | ||
|
||
|
||
class TopicService { | ||
constructor() { | ||
this.topicRepository = new TopicRepository() | ||
|
||
} | ||
|
||
// async createUser(userInfo, type){ | ||
// userInfo = this.userFactory.createUser(userInfo, type) | ||
// return await this.userRepository.create(userInfo) | ||
// } | ||
|
||
async getAllTopics() { | ||
return await this.topicRepository.getAll() | ||
} | ||
|
||
// async getUserById(userId){ | ||
// return await this.userRepository.getById(userId) | ||
// } | ||
|
||
// async deleteUserById(useId){ | ||
// return await this.userRepository.deleteUserById(useId) | ||
// } | ||
|
||
// async updatePasswordById(userId, newpassword){ | ||
// const updatedInfo = { | ||
// hashedPassword: newpassword | ||
// } | ||
// return await this.userRepository.updateById(userId, updatedInfo) | ||
// } | ||
|
||
|
||
} | ||
|
||
module.exports = TopicService; |
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
Oops, something went wrong.