Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
imdeveshshukla authored Sep 7, 2024
2 parents 65af42e + dbc1a5a commit 78795b8
Show file tree
Hide file tree
Showing 10 changed files with 249 additions and 37 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "Poll" ADD COLUMN "topic" TEXT;
1 change: 1 addition & 0 deletions backend/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ model User{
model Poll {
id String @id @default(uuid())
title String
topic String?
description String?
options PollOption[]
createdAt DateTime @default(now())
Expand Down
49 changes: 46 additions & 3 deletions backend/src/controller/poll.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
import prisma from "../../db/db.config.js";

export const createPoll = async (req, res) => {
const { title, options,subCommunity } = req.body;
const { title, options,subCommunity,topic } = req.body;
try {
const poll = await prisma.poll.create({
data: {
title,
topic,
options: {
create: options.map((option) => ({
text: option,
})),
},
userId: req.userId,
subCommunity: subCommunity
subCommunity: subCommunity,
},
});
// console.log(poll);
res.status(200).send(poll);
} catch (error) {
console.log(error);
Expand Down Expand Up @@ -115,6 +117,9 @@ export const getPoll = async (req, res) => {
};





export const getAllPolls= async(req,res)=>{

const limit= parseInt(req.query.limit) ||15;
Expand Down Expand Up @@ -150,6 +155,43 @@ export const getAllPolls= async(req,res)=>{
}
}

export const getHotPolls = async(req,res)=>{
const topic = req.query.topic;
const page = parseInt(req.query.page) || 1;
const limit = parseInt(req.query.limit) || 10;
const offset = (page - 1) * limit;

console.log(topic)
try {
const polls = await prisma.poll.findMany({
where:{
topic
},
include: {
options: {
include: {
votes: true,
},
},
createdBy:true
},
orderBy: {
createdAt: "desc",
},
skip: offset,
take: limit,
})
console.log(polls);
res.status(200).send(polls);
} catch (error) {
res.status(500).json({
msg:"Server Issue",
error:error.message
})
}
}


export const deletePoll = async(req,res)=>{
const id= req.query.id;

Expand Down Expand Up @@ -208,4 +250,5 @@ export const isPollFromRoom = async(req,res)=>{
msg:"Server Issue"
})
}
}
}

1 change: 1 addition & 0 deletions backend/src/controller/posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ export const deletePost = async(req,res) =>{
}



export const getPopularPosts = async (req, res) => {
const page = parseInt(req.query.page) || 1;
const limit = parseInt(req.query.limit) || 10;
Expand Down
4 changes: 3 additions & 1 deletion backend/src/routes/poll.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import express from "express"
import { verifyToken } from "../middlewares/verifytoken.js";
import { createPoll, deletePoll, getAllPolls, getPoll, isPollFromRoom, votePoll } from "../controller/poll.js";
import { createPoll, deletePoll, getAllPolls, getHotPolls, getPoll, isPollFromRoom, votePoll } from "../controller/poll.js";


const pollRoutes = express.Router();

pollRoutes.get('/getpoll/', getPoll );
pollRoutes.get('/getpollRoom',verifyToken,isPollFromRoom);
pollRoutes.get('/getallpolls/', getAllPolls);

pollRoutes.get('/q/hottopicspoll',getHotPolls)
pollRoutes.post('/createpoll', verifyToken, createPoll );
pollRoutes.post('/votepoll', verifyToken, votePoll );
pollRoutes.delete('/deletepoll',verifyToken,deletePoll);
Expand Down
14 changes: 7 additions & 7 deletions frontend/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import baseAddress from "./utils/localhost";
import Postdetail from './components/Postdetail'
import Postskelton, { CommentSkelton, PollSkelton, ProfileSkelton } from './components/Postskelton'
import { setSkeltonLoader } from './redux/skelton'
import HotTopicPosts from './pages/HotTopicPosts'
import HotTopicPosts, { HotTopicPostsorPolls } from './pages/HotTopicPosts'
import sportsdp from './assets/sportsdp.jpg'
import sportsbg from './assets/sportsbg.jpg'
import ietdp from './assets/ietdp.png'
Expand Down Expand Up @@ -241,12 +241,12 @@ function App() {
<Route path='/post/:id' element={ <Postdetail />} />
<Route path='/poll/:id' element={ <PollDetail />} />

<Route path='/q/sports' element={<HotTopicPosts topic={"sports"} title={"Sports"} dp={sportsdp} bg={sportsbg} />} />
<Route path='/q/lucknow' element={<HotTopicPosts topic={"lucknow"} title={"Lucknow"} dp={lkodp} bg={lkobg} />} />
<Route path='/q/iet' element={<HotTopicPosts topic={"iet"} title={"I.E.T"} dp={ietdp} bg={ietbg} />} />
<Route path='/q/lifestyle' element={<HotTopicPosts topic={"lifestyle"} title={"LifeStyle"} dp={lifedp} bg={lifebg} />} />
<Route path='/q/entertainment' element={<HotTopicPosts topic={"entertainment"} title={"Entertainment"} dp={enterdp} bg={enterbg} />} />
<Route path='/q/dsa' element={<HotTopicPosts topic={"dsa"} title={"DS&A"} dp={dsadp} bg={dsabg} />} />
<Route path='/q/sports' element={<HotTopicPostsorPolls topic={"sports"} title={"Sports"} dp={sportsdp} bg={sportsbg} />} />
<Route path='/q/lucknow' element={<HotTopicPostsorPolls topic={"lucknow"} title={"Lucknow"} dp={lkodp} bg={lkobg} />} />
<Route path='/q/iet' element={<HotTopicPostsorPolls topic={"iet"} title={"I.E.T"} dp={ietdp} bg={ietbg} />} />
<Route path='/q/lifestyle' element={<HotTopicPostsorPolls topic={"lifestyle"} title={"LifeStyle"} dp={lifedp} bg={lifebg} />} />
<Route path='/q/entertainment' element={<HotTopicPostsorPolls topic={"entertainment"} title={"Entertainment"} dp={enterdp} bg={enterbg} />} />
<Route path='/q/dsa' element={<HotTopicPostsorPolls topic={"dsa"} title={"DS&A"} dp={dsadp} bg={dsabg} />} />
<Route path='/setting/' element={<Settings />} />
<Route path="/test/" element={<Postskelton />} />
<Route path="/about/" element={<About />} />
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/Polls.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ const deletePoll=async(id)=>{
<img onClick={() => Navigate(`/u/${poll?.createdBy?.username}`)} src={poll?.createdBy?.dp || dp} alt="Profile" className="w-8 h-8 rounded-full cursor-pointer bg-white" />
<div className=' flex flex-wrap gap-1 xs:gap-2 md:gap-4 items-center'>
<span onClick={() => Navigate(`/u/${poll?.createdBy?.username}`)} className='font-semibold cursor-pointer hover:text-green-900'>u/{poll?.createdBy?.username}</span>{(inRoom && <><span onClick={() => Navigate(`/room/${user.userID}/${room?.title}`)} className=' cursor-pointer hover:text-rose-900 text-sm font-semibold'>q/{room?.title}</span> <span></span></>)
|| (topic && <><span onClick={() => Navigate(`/q/${"topic"}`)} className=' cursor-pointer hover:text-rose-900 text-sm font-semibold'>q/{topic}</span> <span></span></>)}<span className='text-xs text-gray-700'>{`${getTime(poll?.createdAt)} ago`}</span>
|| (topic && <><span onClick={() => Navigate(`/q/${topic}`)} className=' cursor-pointer hover:text-rose-900 text-sm font-semibold'>q/{topic}</span> <span></span></>)}<span className='text-xs text-gray-700'>{`${getTime(poll?.createdAt)} ago`}</span>

</div>
{
Expand Down
29 changes: 29 additions & 0 deletions frontend/src/pages/CreatePost.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,11 @@ export const CreatePoll = () => {
const dispatch = useDispatch()
const Navigate = useNavigate()
const { roomTitle,roomCreatorId } = useOutletContext()
const [selectedOption, setSelectedOption] = useState(null);

const handleSelectChange = (event) => {
setSelectedOption(event.target.value);
};

const handleTitleChange=(e)=>{

Expand Down Expand Up @@ -344,6 +349,7 @@ export const CreatePoll = () => {
const res = await axios.post(`${baseAddress}poll/createpoll`, {
title: poll.title,
options: poll.options,
topic: selectedOption,
subCommunity:roomTitle
})

Expand Down Expand Up @@ -372,6 +378,29 @@ export const CreatePoll = () => {
return (<div className=" relative h-[90%] overflow-auto">
<h2 className="text-xl font-bold mb-2 text-[#656923]">Create Poll....</h2>
<form onSubmit={handleSubmit} className=" flex flex-col ">
{!roomTitle ? <div className='flex mt-2 px-28 justify-start '>
<div className='flex hover:bg-[#808449cf] items-center px-2 py-1 rounded-full border-[1px] border-black '>

<span className=' rounded-full border-2 border-white'>
<svg width="30" height="30" xmlns="http://www.w3.org/2000/svg">
<circle cx="15" cy="15" r="15" fill="black" />
<text x="50%" y="50%" fontSize="18" textAnchor="middle" fill="white" fontFamily="Arial, sans-serif" dominantBaseline="middle">q/</text>
</svg>
</span>
<select className=' cursor-pointer bg-transparent px-2 sm:px-4 outline-none' id="options" value={selectedOption} onChange={(e) => handleSelectChange(e)}>

<option className='bg-[#808449] text-white font-extralight 1_5md:text-lg' value="">Select a Topic</option>
<option className='bg-[#808449] text-white font-extralight 1_5md:text-lg' value="sports">Sports</option>
<option className='bg-[#808449] text-white font-extralight 1_5md:text-lg' value="dsa">DSA</option>
<option className='bg-[#808449] text-white font-extralight 1_5md:text-lg' value="iet">IET</option>
<option className='bg-[#808449] text-white font-extralight 1_5md:text-lg' value="entertainment">Entertainment</option>
<option className='bg-[#808449] text-white font-extralight 1_5md:text-lg' value="lifestyle">Lifestyle</option>
<option className='bg-[#808449] text-white font-extralight 1_5md:text-lg' value="lucknow">Lucknow</option>
</select>
</div>
</div>
: <></>
}
<div>
<div>
<div className=" flex items-center justify-between">
Expand Down
Loading

0 comments on commit 78795b8

Please sign in to comment.