Skip to content

Commit

Permalink
topic backend added
Browse files Browse the repository at this point in the history
  • Loading branch information
Luxshan2000 committed Oct 16, 2023
1 parent edc071a commit d417cfe
Show file tree
Hide file tree
Showing 10 changed files with 240 additions and 89 deletions.
4 changes: 2 additions & 2 deletions backend/config/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ const connectMongoDb = ()=>{

/*Debugging Purpose*/
// const sample = async ()=>{
// const title = "Overview"
// const no = 1
// const title = "What are the ways to apply License?"
// const no = 3
// const videoUrl = "videourl"
// const script = '<h1 >This is an script</h1>'
// const questions = [
Expand Down
4 changes: 2 additions & 2 deletions backend/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const cookieParser = require('cookie-parser')

const connectMongoDb = require("./config/database")
const authRoutes = require('./src/routes/authRoutes');

const materialRoutes = require('./src/routes/materialRoutes')

const app = express()
app.use(cookieParser())
Expand All @@ -24,7 +24,7 @@ connectMongoDb()


app.use('/api/auth', authRoutes);

app.use('/api/material',materialRoutes )



Expand Down
3 changes: 2 additions & 1 deletion backend/src/controllers/authController.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,9 @@ const googleLoginBase = async (req, res, isWeb) => {
const saltRounds = 10; // Adjust
const hashedPassword = await bcrypt.hash(password, saltRounds);

const isAdmin = false
//create a new user
const newUser = new User({ email, hashedPassword, name })
const newUser = new User({ email, hashedPassword, name, isAdmin })
await newUser.save()

// Send the response
Expand Down
20 changes: 20 additions & 0 deletions backend/src/controllers/topicController.js
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})
}
}





28 changes: 28 additions & 0 deletions backend/src/repositories/topicRepository.js
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
36 changes: 36 additions & 0 deletions backend/src/routes/materialRoutes.js
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;
39 changes: 39 additions & 0 deletions backend/src/services/topicServices.js
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;
2 changes: 1 addition & 1 deletion webapp/src/assets/CSS/headingStyle.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ a{

.hover-effect {
transition: background-color, box-shadow 0.5s ease;
background-color: rgb(225, 238, 254);
background-color: rgb(241, 246, 253);
}
.hover-effect:hover {
background-color: rgb(233, 242, 255);
Expand Down
18 changes: 9 additions & 9 deletions webapp/src/components/HeadingComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ function HeadingComponent({heading}) {
style={{cursor:'pointer'}}
data-bs-toggle="collapse"
onClick={()=>setToggle(prv=>!prv)}
data-bs-target={`#id${heading.id}`}
data-bs-target={`#id${heading._id}`}
aria-expanded={toggle}
aria-controls={`id${heading.id}`}>
aria-controls={`id${heading._id}`}>
<div className=' text-start row pe-2'>
<h5 className=' col-11 CourseHeading'>
{heading.name}
{heading.no + ". "+ heading.title}
<span className='instructionFamily badge ms-1 p-2 text-dark bg-success-subtle'>
Completed!
</span>
Expand All @@ -27,7 +27,7 @@ function HeadingComponent({heading}) {

</div>
</div>
<div className="collapse" id={`id${heading.id}`}>
<div className="collapse" id={`id${heading._id}`}>
<hr className=' hrFirst mt-0 m-1'/>
<div className='rounded-3 mb-3 p-3 pb-0 '>
<div className='text-start mb-3 p-1'>
Expand All @@ -36,15 +36,12 @@ function HeadingComponent({heading}) {
<span class=" rounded-5 bg-success-subtle p-2 m-1 ">
<i class="bi bi-book"></i>
</span>
{heading.subHeadings[0]}
{heading.videoUrl? `${heading.no}.1 Interactive Video and notes` :"" }
</Link>
</h5>
<span className='instructionFamily badge m-1 p-2 text-dark bg-success-subtle'>
Done: Complete the activity
</span>
<span className='instructionFamily badge m-1 p-2 text-dark bg-warning-subtle'>
To unlock: Upgrade to premium
</span>
</div>
<div>
<hr/>
Expand All @@ -55,12 +52,15 @@ function HeadingComponent({heading}) {
<span class=" rounded-5 bg-danger-subtle p-2 m-1 ">
<i class="bi bi-pencil"></i>
</span>
{heading.subHeadings[1]}
{`${heading.no}.2 Quiz`}
</Link>
</h5>
<span className='instructionFamily badge m-1 p-2 text-dark bg-danger-subtle'>
To do: Complete the activity
</span>
<span className='instructionFamily badge m-1 p-2 text-dark bg-warning-subtle'>
To unlock: Upgrade to premium
</span>
</div>


Expand Down
Loading

0 comments on commit d417cfe

Please sign in to comment.