Changeset 3b6962d
- Timestamp:
- 11/23/22 12:15:28 (2 years ago)
- Branches:
- main
- Children:
- af801e3, e49d1b6
- Parents:
- c68150f
- Files:
-
- 7 added
- 28 edited
Legend:
- Unmodified
- Added
- Removed
-
reactapp/src/Components/OpinionTree.js
rc68150f r3b6962d 42 42 43 43 useEffect(() => { 44 const url = `http://192.168.0.1 7:8080/secure/currentUser`;44 const url = `http://192.168.0.19:8080/secure/currentUser`; 45 45 46 46 const fetchUser = async () => { … … 68 68 ) { 69 69 const response = await axios( 70 `http://192.168.0.1 7:8080/secure/upvoteOpinion/${post.postId}`,70 `http://192.168.0.19:8080/secure/upvoteOpinion/${post.postId}`, 71 71 { 72 72 method: "get", … … 91 91 ) { 92 92 const response = await axios( 93 `http://192.168.0.1 7:8080/secure/downvoteOpinion/${post.postId}`,93 `http://192.168.0.19:8080/secure/downvoteOpinion/${post.postId}`, 94 94 { 95 95 method: "get", … … 111 111 setReplyModalDisplay("block"); 112 112 setPostForModal(opinion); 113 document.body.style.overflowY = "hidden"; 113 114 } else { 114 115 navigate("/login"); … … 118 119 const handleModalCloseClick = () => { 119 120 setReplyModalDisplay("none"); 121 document.body.style.overflowY = "auto"; 120 122 }; 121 123 … … 129 131 if (!replyContent.length < 1) { 130 132 const response = await axios( 131 `http://192.168.0.1 7:8080/secure/professor/${professor.professorId}/replyToOpinion/${postId}`,133 `http://192.168.0.19:8080/secure/professor/${professor.professorId}/replyToOpinion/${postId}`, 132 134 { 133 135 method: "post", … … 159 161 {child.content} 160 162 </p> 161 <OpinionReplyCardContentTime> 162 {dateConverter( 163 new Date(child.timePosted).toString().slice(4, -43) 164 )} 165 </OpinionReplyCardContentTime> 163 {child.timePosted === child.timeLastEdited ? ( 164 <OpinionCardContentTime> 165 {dateConverter( 166 new Date(child.timePosted).toString().slice(4, -43) 167 )} 168 </OpinionCardContentTime> 169 ) : ( 170 <OpinionCardContentTime> 171 {dateConverter( 172 new Date(child.timeLastEdited).toString().slice(4, -43) 173 )}{" "} 174 (едитирано од модератор) 175 </OpinionCardContentTime> 176 )} 166 177 167 178 <div … … 181 192 (e) => e.vote === "UPVOTE" && e.user.id === user.id 182 193 ) 183 ? "green yellow"194 ? "green" 184 195 : "darkgrey" 185 196 : "darkgrey" … … 249 260 {opinion.content} 250 261 </p> 251 <OpinionCardContentTime> 252 {dateConverter( 253 new Date(opinion.timePosted).toString().slice(4, -43) 254 )} 255 </OpinionCardContentTime> 262 {opinion.timePosted === opinion.timeLastEdited ? ( 263 <OpinionCardContentTime> 264 {dateConverter( 265 new Date(opinion.timePosted).toString().slice(4, -43) 266 )} 267 </OpinionCardContentTime> 268 ) : ( 269 <OpinionCardContentTime> 270 {dateConverter( 271 new Date(opinion.timeLastEdited) 272 .toString() 273 .slice(4, -43) 274 )}{" "} 275 (едитирано од модератор) 276 </OpinionCardContentTime> 277 )} 256 278 257 279 <div … … 273 295 e.vote === "UPVOTE" && e.user.id === user.id 274 296 ) 275 ? "green yellow"297 ? "green" 276 298 : "darkgrey" 277 299 : "darkgrey" … … 343 365 value={replyContent} 344 366 onChange={handleContentChange} 367 spellCheck={false} 345 368 /> 346 369 </label> -
reactapp/src/Components/Search.js
rc68150f r3b6962d 15 15 16 16 useEffect(() => { 17 const url = `http://192.168.0.1 7:8080/public/professors/nameContains/${transliterate(17 const url = `http://192.168.0.19:8080/public/professors/nameContains/${transliterate( 18 18 query 19 19 )}`; -
reactapp/src/Components/Styled/Modal.style.js
rc68150f r3b6962d 28 28 top: 0; 29 29 width: 100%; 30 height: auto;30 height: 100%; 31 31 overflow: auto; 32 32 background-color: rgb(0, 0, 0); … … 47 47 export const ModalContent = styled.div` 48 48 background-color: #fefefe; 49 margin: 15% auto;49 margin: 2% auto; 50 50 padding: 20px; 51 51 border: 1px solid #888; … … 107 107 padding: 12px 16px; 108 108 border: 1px solid #ccc; 109 font-family: inherit; 109 110 `; 110 111 … … 116 117 border: 1px solid #ccc; 117 118 resize: none; 119 font-family: inherit; 118 120 `; -
reactapp/src/Components/UserHeader.js
rc68150f r3b6962d 10 10 11 11 useEffect(() => { 12 const url = `http://192.168.0.1 7:8080/secure/currentUser`;12 const url = `http://192.168.0.19:8080/secure/currentUser`; 13 13 14 14 const fetchUser = async () => { -
reactapp/src/Pages/Faculty.js
rc68150f r3b6962d 27 27 28 28 useEffect(() => { 29 const urlProfessors = `http://192.168.0.1 7:8080/public/professors?facultyId=${params.facultyId}`;30 const urlStudyProgrammes = `http://192.168.0.1 7:8080/public/study_programmes?facultyId=${params.facultyId}`;29 const urlProfessors = `http://192.168.0.19:8080/public/professors?facultyId=${params.facultyId}`; 30 const urlStudyProgrammes = `http://192.168.0.19:8080/public/study_programmes?facultyId=${params.facultyId}`; 31 31 32 32 const fetchDataProfessors = async () => { -
reactapp/src/Pages/Professor.js
rc68150f r3b6962d 39 39 40 40 useEffect(() => { 41 const url = `http://192.168.0.1 7:8080/public/professor/${params.professorId}`;41 const url = `http://192.168.0.19:8080/public/professor/${params.professorId}`; 42 42 43 43 const fetchProfessor = async () => { … … 60 60 if (auth) { 61 61 setPostModalDisplay("block"); 62 document.body.style.overflowY = "hidden"; 62 63 } else { 63 64 navigate("/login"); … … 67 68 const handleModalCloseClick = () => { 68 69 setPostModalDisplay("none"); 70 document.body.style.overflowY = "auto"; 69 71 }; 70 72 … … 74 76 if (!postContent.length < 1) { 75 77 const response = await axios( 76 `http://192.168.0.1 7:8080/secure/professor/${params.professorId}/addOpinion`,78 `http://192.168.0.19:8080/secure/professor/${params.professorId}/addOpinion`, 77 79 { 78 80 method: "post", … … 152 154 rows="8" 153 155 cols="100" 156 spellCheck={false} 154 157 value={postContent} 155 158 onChange={handleContentChange} -
reactapp/src/Pages/Subject.js
rc68150f r3b6962d 46 46 47 47 useEffect(() => { 48 const url = `http://192.168.0.1 7:8080/public/subject/${params.subjectId}`;48 const url = `http://192.168.0.19:8080/public/subject/${params.subjectId}`; 49 49 50 50 const fetchData = async () => { … … 67 67 if (auth) { 68 68 setTopicModalDisplay("block"); 69 document.body.style.overflowY = "hidden"; 69 70 } else { 70 71 navigate("/login"); … … 74 75 const handleModalCloseClick = () => { 75 76 setTopicModalDisplay("none"); 77 document.body.style.overflowY = "auto"; 76 78 }; 77 79 … … 81 83 if (!topicTitle.length < 1 && !topicContent.length < 1) { 82 84 const response = await axios( 83 `http://192.168.0.1 7:8080/secure/subject/${params.subjectId}/addThread`,85 `http://192.168.0.19:8080/secure/subject/${params.subjectId}/addThread`, 84 86 { 85 87 method: "post", … … 178 180 value={topicTitle} 179 181 onChange={handleTitleChange} 182 spellCheck={false} 180 183 /> 181 184 </label> … … 188 191 value={topicContent} 189 192 onChange={handleContentChange} 193 spellCheck={false} 190 194 /> 191 195 </label> -
reactapp/src/Pages/Topic.js
rc68150f r3b6962d 48 48 49 49 useEffect(() => { 50 const url1 = `http://192.168.0.1 7:8080/public/thread/${params.topicId}`;51 const url2 = `http://192.168.0.1 7:8080/secure/currentUser`;50 const url1 = `http://192.168.0.19:8080/public/thread/${params.topicId}`; 51 const url2 = `http://192.168.0.19:8080/secure/currentUser`; 52 52 53 53 const fetchTopic = async () => { … … 84 84 setReplyModalDisplay("block"); 85 85 setPostForModal(post); 86 document.body.style.overflowY = "hidden"; 86 87 } else { 87 88 navigate("/login"); … … 98 99 if (!replyContent.length < 1) { 99 100 const response = await axios( 100 `http://192.168.0.1 7:8080/secure/subject/${thread.targetSubject.subjectId}/replyToThread/${postId}`,101 `http://192.168.0.19:8080/secure/subject/${thread.targetSubject.subjectId}/replyToThread/${postId}`, 101 102 { 102 103 method: "post", … … 117 118 if (auth) { 118 119 setPostModalDisplay("block"); 120 document.body.style.overflowY = "hidden"; 119 121 } else { 120 122 navigate("/login"); … … 126 128 if (!postContent.length < 1) { 127 129 const response = await axios( 128 `http://192.168.0.1 7:8080/secure/subject/${thread.targetSubject.subjectId}/replyToThread/${params.topicId}`,130 `http://192.168.0.19:8080/secure/subject/${thread.targetSubject.subjectId}/replyToThread/${params.topicId}`, 129 131 { 130 132 method: "post", … … 144 146 setPostModalDisplay("none"); 145 147 setReplyModalDisplay("none"); 148 document.body.style.overflowY = "auto"; 146 149 }; 147 150 const handleContentChange = (e) => { … … 157 160 ) { 158 161 const response = await axios( 159 `http://192.168.0.1 7:8080/secure/upvoteThread/${post.postId}`,162 `http://192.168.0.19:8080/secure/upvoteThread/${post.postId}`, 160 163 { 161 164 method: "get", … … 180 183 ) { 181 184 const response = await axios( 182 `http://192.168.0.1 7:8080/secure/downvoteThread/${post.postId}`,185 `http://192.168.0.19:8080/secure/downvoteThread/${post.postId}`, 183 186 { 184 187 method: "get", … … 210 213 {child.content} 211 214 </p> 212 <OpinionReplyCardContentTime> 213 {dateConverter( 214 new Date(child.timePosted).toString().slice(4, -43) 215 )} 216 </OpinionReplyCardContentTime> 215 {thread.timePosted === thread.timeLastEdited ? ( 216 <OpinionCardContentTime> 217 {dateConverter( 218 new Date(thread.timePosted).toString().slice(4, -43) 219 )} 220 </OpinionCardContentTime> 221 ) : ( 222 <OpinionCardContentTime> 223 {dateConverter( 224 new Date(thread.timeLastEdited).toString().slice(4, -43) 225 )}{" "} 226 (едитирано од модератор) 227 </OpinionCardContentTime> 228 )} 217 229 218 230 <div … … 232 244 (e) => e.vote === "UPVOTE" && e.user.id === user.id 233 245 ) 234 ? "green yellow"246 ? "green" 235 247 : "darkgrey" 236 248 : "darkgrey" … … 337 349 value={postContent} 338 350 onChange={handleContentChange} 351 spellCheck={false} 339 352 /> 340 353 </label> … … 356 369 {thread.content} 357 370 </p> 358 <OpinionCardContentTime> 359 {dateConverter( 360 new Date(thread.timePosted).toString().slice(4, -43) 361 )} 362 </OpinionCardContentTime> 371 {thread.timePosted === thread.timeLastEdited ? ( 372 <OpinionCardContentTime> 373 {dateConverter( 374 new Date(thread.timePosted).toString().slice(4, -43) 375 )} 376 </OpinionCardContentTime> 377 ) : ( 378 <OpinionCardContentTime> 379 {dateConverter( 380 new Date(thread.timeLastEdited).toString().slice(4, -43) 381 )}{" "} 382 (едитирано од модератор) 383 </OpinionCardContentTime> 384 )} 363 385 <div 364 386 style={{ … … 377 399 (e) => e.vote === "UPVOTE" && e.user.id === user.id 378 400 ) 379 ? "green yellow"401 ? "green" 380 402 : "darkgrey" 381 403 : "darkgrey" … … 422 444 {directChild.content} 423 445 </p> 424 <OpinionCardContentTime> 425 {dateConverter( 426 new Date(directChild.timePosted).toString().slice(4, -43) 427 )} 428 </OpinionCardContentTime> 446 {directChild.timePosted === directChild.timeLastEdited ? ( 447 <OpinionCardContentTime> 448 {dateConverter( 449 new Date(directChild.timePosted).toString().slice(4, -43) 450 )} 451 </OpinionCardContentTime> 452 ) : ( 453 <OpinionCardContentTime> 454 {dateConverter( 455 new Date(directChild.timeLastEdited) 456 .toString() 457 .slice(4, -43) 458 )}{" "} 459 (едитирано од модератор) 460 </OpinionCardContentTime> 461 )} 429 462 <div 430 463 style={{ … … 444 477 (e) => e.vote === "UPVOTE" && e.user.id === user.id 445 478 ) 446 ? "green yellow"479 ? "green" 447 480 : "darkgrey" 448 481 : "darkgrey" -
reactapp/src/Pages/University.js
rc68150f r3b6962d 22 22 23 23 useEffect(() => { 24 const url = `http://192.168.0.1 7:8080/public/faculties?universityId=${params.universityId}`;24 const url = `http://192.168.0.19:8080/public/faculties?universityId=${params.universityId}`; 25 25 26 26 const fetchData = async () => { -
reactapp/src/Pages/UserDashboard.js
rc68150f r3b6962d 13 13 import JSOG from "jsog"; 14 14 import AuthApi from "../api/AuthApi"; 15 import {EntityLi, EntityTypeSelector, EntityUl} from "../Components/Styled/EntityList.style"; 16 import { 17 AddOpinionButton, 18 Modal, 19 ModalBody, 20 ModalClose, 21 ModalContent, ModalFooter, 22 ModalHeader, ModalTextarea, 23 ModalInput 24 } from "../Components/Styled/Modal.style"; 15 25 16 26 function UserDashboard() { … … 21 31 const [fetchError, setFetchError] = useState(false); 22 32 33 const [postReports, setPostReports] = useState(null); 34 const [loadedPostReports, setLoadedPostReports] = useState(false); 35 36 const [reportModalDisplay, setReportModalDisplay] = useState("none"); 37 const [reportForModal, setReportForModal] = useState(null); 38 39 const [actionType, setActionType] = useState(0); 40 41 const [newPostContent, setNewPostContent] = useState(""); 42 const [newPostTitle, setNewPostTitle] = useState(""); 43 44 const [markResolved, setMarkResolved] = useState(false); 45 46 const handleModalCloseClick = () => { 47 setReportForModal(null); 48 setReportModalDisplay("none"); 49 document.body.style.overflowY = "auto"; 50 }; 51 52 const handleViewReportButtonClick = (e,report) => { 53 e.preventDefault(); 54 setReportForModal(report); 55 } 56 23 57 useEffect(() => { 24 const url = `http://192.168.0.17:8080/secure/currentUser`; 58 if(reportForModal!==null) { 59 if (reportForModal.post !== null) { 60 setNewPostContent(reportForModal.post.content); 61 if(reportForModal.post.title !== null) setNewPostTitle(reportForModal.post.title); 62 } 63 setReportModalDisplay("block"); 64 document.body.style.overflowY = "hidden"; 65 } 66 }, [reportForModal]); 67 68 useEffect(() => { 69 const url1 = `http://192.168.0.19:8080/secure/currentUser`; 70 const url2 = `http://192.168.0.19:8080/secure/getAllPostReports`; 25 71 26 72 const fetchUser = async () => { 27 73 try { 28 const response = await axios.get(url, { withCredentials: true }); 29 var cyclicGraph = await response.data; 30 var jsogStructure = JSOG.encode(cyclicGraph); 31 cyclicGraph = JSOG.decode(jsogStructure); 32 setUser(cyclicGraph); 33 setLoadedUser(true); 74 if(!loadedUser) { 75 const response = await axios.get(url1, {withCredentials: true}); 76 let cyclicGraph = await response.data; 77 var jsogStructure = JSOG.encode(cyclicGraph); 78 cyclicGraph = JSOG.decode(jsogStructure); 79 setUser(cyclicGraph); 80 setLoadedUser(true); 81 } 82 if(user.userRole==='MODERATOR')fetchPostReports(); 34 83 } catch (error) { 35 84 setFetchError(true); … … 37 86 }; 38 87 88 const fetchPostReports = async () => { 89 try { 90 const response = await axios.get(url2, {withCredentials: true}); 91 var cyclicGraph = await response.data; 92 var jsogStructure = JSOG.encode(cyclicGraph); 93 cyclicGraph = JSOG.decode(jsogStructure); 94 setPostReports(cyclicGraph); 95 setLoadedPostReports(true); 96 } catch (error) { 97 setFetchError(true); 98 } 99 }; 100 39 101 if (auth) fetchUser(); 40 }, []); 102 103 }, [user]); 41 104 42 105 // useEffect(() => { … … 50 113 if (post.parent === null) return post; 51 114 return findParentThread(post.parent); 115 } 116 117 const handleEdit = async (e) => { 118 e.preventDefault(); 119 try { 120 if(reportForModal.post !== null && reportForModal.post.targetProfessor !== undefined) { 121 await axios(`http://192.168.0.19:8080/secure/updateOpinion/${reportForModal.post.postId}`, 122 { 123 method: "put", 124 data: { 125 newContent: newPostContent, 126 newTargetProfessorId: reportForModal.post.targetProfessor.professorId, 127 }, 128 withCredentials: true, 129 }) 130 window.location.reload(false); 131 } else if(reportForModal.post !== null && reportForModal.post.targetProfessor === undefined) { 132 await axios(`http://192.168.0.19:8080/secure/updateThread/${reportForModal.post.postId}`, 133 { 134 method: "put", 135 data: { 136 newTitle: newPostTitle, 137 newContent: newPostContent, 138 newTargetSubjectId: reportForModal.post.targetSubject.subjectId 139 }, 140 withCredentials: true, 141 }) 142 window.location.reload(false); 143 } 144 } catch (error) { 145 setFetchError(true); 146 } 147 } 148 149 const handleDelete = (e) => { 150 e.preventDefault(); 151 } 152 153 const handleMarkResolved = () => { 154 if (actionType !== 1) setMarkResolved(!markResolved); 52 155 } 53 156 … … 68 171 </UserDetailsCardContent> 69 172 <UserDetailsCardContent> 70 <b>Карма:</b> {user.karma} 173 <b>Карма:</b>{" "} 174 <span style={{ color: user.karma < 0 ? "indianred" : "green" }}> 175 {user.karma} 176 </span> 71 177 </UserDetailsCardContent> 72 178 </UserDetailsCard> 179 {loadedPostReports ? postReports.length > 0 ? ( 180 <h3 style={{ marginBottom: "10px" }}>Пријави за мислења:</h3> 181 ) : ( 182 <h3>Нема пријавени мислења</h3> 183 ) : loadedUser && user.userRole==='MODERATOR' ? "се вчитува..." : ""} 184 <EntityUl style={{marginTop:"25px"}}> 185 {loadedPostReports && postReports.map((postReport) => { 186 return <EntityLi bgcolor="cornsilk" key={postReport.postReportId} style={{padding:"15px"}}> 187 <p style={{color: postReport.resolved ? "grey" : "black"}}><span style={{fontSize:"14px", fontStyle:"italic", fontWeight:"normal"}}>{dateConverter( 188 new Date(postReport.time).toString().slice(4, -43) 189 )}</span><br/>{postReport.description.substring(0,45 )}{postReport.description.length >= 45 ? ("...") : ("")} {postReport.resolved ? <span style={{fontStyle:"italic"}}>(разрешено)</span> : ""} 190 </p> 191 <AddOpinionButton onClick={(e)=>handleViewReportButtonClick(e,postReport)} style={{height:"30px", padding:"5px", fontSize:"14px", position:"absolute", top:"30%", right:"20px" }}>Разгледај</AddOpinionButton> 192 </EntityLi>; 193 })} 194 </EntityUl> 73 195 {user.authoredPosts.length > 0 ? ( 74 <h3 style={{ marginBottom: "10px" }}>Ваши мислења:</h3>196 <h3 style={{ marginBottom: "10px", marginTop:"30px" }}>Ваши мислења:</h3> 75 197 ) : ( 76 <h3 >Немате објавени мислења</h3>198 <h3 style={{ marginBottom: "10px" }}>Немате објавени мислења</h3> 77 199 )} 78 200 {user.authoredPosts.map((post) => { … … 110 232 ); 111 233 })} 234 {reportForModal && ( 235 <Modal display={reportModalDisplay}> 236 <ModalContent> 237 <ModalHeader> 238 <ModalClose onClick={handleModalCloseClick}>×</ModalClose> 239 <h3 style={{ marginTop: "5px" }}> 240 Преглед на пријава за мислење 241 </h3> 242 </ModalHeader> 243 <ModalBody> 244 <p style={{fontWeight:"bold",marginBottom:"15px"}}>Пријавил: <span style={{fontWeight:"normal"}}>{reportForModal.user !== null ? <a href={"/user/"+reportForModal.user.id}>{reportForModal.user.username}</a> : "(избришан корисник)"}</span></p> 245 <p style={{fontWeight:"bold",marginBottom:"15px"}}>Време на пријава: <span style={{fontWeight:"normal"}}>{dateConverter( 246 new Date(reportForModal.time).toString().slice(4, -43) 247 )}</span></p> 248 <p style={{fontWeight:"bold",marginBottom:"15px"}}>Образложение: </p> <p style={{marginBottom:"15px"}}>{reportForModal.description}</p> 249 <p style={{fontWeight:"bold", marginBottom:"15px"}}>Информации за пријавеното мислење:</p> 250 {reportForModal.post !== null ? 251 <OpinionCard> 252 <OpinionCardContent> 253 <p style={{fontStyle: "italic", marginBottom: "10px"}}> 254 во дискусија за{" "} 255 {reportForModal.post.targetProfessor !== undefined ? ( 256 <a href={"/professor/" + reportForModal.post.targetProfessor.professorId}> 257 {reportForModal.post.targetProfessor.professorName} 258 </a> 259 ) : ( 260 <a 261 href={ 262 reportForModal.post.parent === null 263 ? "/topic/" + reportForModal.post.postId 264 : "/topic/" + findParentThread(reportForModal.post).postId 265 } 266 > 267 {reportForModal.post.targetSubject.subjectName} 268 </a> 269 )} 270 </p> 271 {reportForModal.post.title === null ? 272 <p style={{ fontStyle: "italic", marginBottom: "10px" }}> 273 <a href={"/user/" + reportForModal.post.author.id}> 274 {reportForModal.post.author.username} 275 </a>{" "} 276 напишал 277 </p> : 278 <p style={{ fontStyle: "italic", marginBottom: "10px" }}> 279 <a href={"/user/" + reportForModal.post.author.id}> 280 {reportForModal.post.author.username} 281 </a>{" "} 282 отворил тема со наслов <span style={{fontWeight:"bold"}}>{reportForModal.post.title}</span> 283 </p> 284 } 285 <p style={{marginBottom: "10px"}}>{reportForModal.post.content}</p> 286 <OpinionCardContentTime> 287 {dateConverter( 288 new Date(reportForModal.post.timePosted).toString().slice(4, -43) 289 )} 290 </OpinionCardContentTime> 291 </OpinionCardContent> 292 </OpinionCard> 293 : "Пријавеното мислење или неговиот автор се избришани"} 294 295 {reportForModal.post !== null && 296 <div style={{ display: "flex" }}> 297 {actionType===0 ? <EntityTypeSelector 298 backgroundcolor="rgba(0, 102, 204, 1)" 299 color="white" 300 boxshadow="none" 301 boxshadowhover="none" 302 opacityhover="0.6" 303 cursor="auto" 304 > 305 Измени содржина или наслов 306 </EntityTypeSelector> : <EntityTypeSelector 307 boxshadow="2px 2px 5px #aaaaaa" 308 cursor="pointer" 309 boxshadowhover="2px 2px 10px #aaaaaa" 310 opacityhover="1" 311 onClick={() => setActionType(0)} 312 > 313 Измени содржина или наслов 314 </EntityTypeSelector>} 315 {actionType===1 ? <EntityTypeSelector 316 backgroundcolor="rgba(0, 102, 204, 1)" 317 color="white" 318 boxshadow="none" 319 boxshadowhover="none" 320 opacityhover="0.6" 321 cursor="auto" 322 > 323 Избриши 324 </EntityTypeSelector> : <EntityTypeSelector 325 boxshadow="2px 2px 5px #aaaaaa" 326 cursor="pointer" 327 boxshadowhover="2px 2px 10px #aaaaaa" 328 opacityhover="1" 329 onClick={() => {setActionType(1); setMarkResolved(true)}} 330 > 331 Избриши 332 </EntityTypeSelector>} 333 {actionType===2 ? <EntityTypeSelector 334 backgroundcolor="rgba(0, 102, 204, 1)" 335 color="white" 336 boxshadow="none" 337 boxshadowhover="none" 338 opacityhover="0.6" 339 cursor="auto" 340 > 341 Премести 342 </EntityTypeSelector> : <EntityTypeSelector 343 boxshadow="2px 2px 5px #aaaaaa" 344 cursor="pointer" 345 boxshadowhover="2px 2px 10px #aaaaaa" 346 opacityhover="1" 347 onClick={() => setActionType(2)} 348 > 349 Премести 350 </EntityTypeSelector>} 351 </div>} 352 {reportForModal.post !== null ? 353 actionType === 0 ? 354 (<form onSubmit={e => handleEdit(e)}> 355 {reportForModal.post.title !== null && <label> 356 <b>Нов наслов на тема:</b> 357 <ModalInput 358 value={newPostTitle} 359 onChange={e => setNewPostTitle(e.target.value)} 360 id="title" 361 spellCheck={false} 362 style={{marginTop:"10px"}} 363 /> 364 </label>} 365 <label> 366 <b>Нова содржина:</b> 367 <ModalTextarea 368 value={newPostContent} 369 onChange={e => setNewPostContent(e.target.value)} 370 id="content" 371 rows="8" 372 cols="100" 373 spellCheck={false} 374 style={{marginTop:"10px"}} 375 /> 376 </label> 377 <div style={{marginTop:"15px"}}> 378 <label> 379 <input 380 type="checkbox" 381 checked={markResolved} 382 onChange={handleMarkResolved} 383 /> 384 <span style={{marginLeft:"10px", fontWeight:"bold"}}>Означи како разрешено</span> 385 </label> 386 </div> 387 <ModalFooter type="submit">ПОТВРДИ</ModalFooter> 388 </form>) 389 : actionType === 1 ? 390 (<form onSubmit={e => handleDelete(e)}> 391 <p style={{color:"red", display:"flex", justifyContent:"space-around"}}>Избриши го мислењето? (оваа акција е иреверзибилна)</p> 392 <div style={{marginTop:"15px"}}> 393 <label> 394 <input 395 type="checkbox" 396 checked={markResolved} 397 onChange={handleMarkResolved} 398 /> 399 <span style={{marginLeft:"10px", fontWeight:"bold"}}>Означи како разрешено</span> 400 </label> 401 </div> 402 <ModalFooter type="submit">ПОТВРДИ</ModalFooter> 403 </form>) 404 : 405 ("123") 406 : null 407 } 408 </ModalBody> 409 </ModalContent> 410 </Modal> 411 )} 112 412 </> 113 413 ) : ( -
reactapp/src/api/axios.js
rc68150f r3b6962d 2 2 3 3 export default axios.create({ 4 baseURL: "http://192.168.0.1 7:8080",4 baseURL: "http://192.168.0.19:8080", 5 5 }); -
springapp/src/main/java/mk/profesori/springapp/Controller/PublicController.java
rc68150f r3b6962d 25 25 @RestController 26 26 @RequestMapping("/public") 27 @CrossOrigin(origins = { "http://192.168.0.1 7:3000", "http://192.168.0.39:3000" })27 @CrossOrigin(origins = { "http://192.168.0.19:3000", "http://192.168.0.39:3000" }) 28 28 public class PublicController { 29 29 -
springapp/src/main/java/mk/profesori/springapp/Controller/SecureController.java
rc68150f r3b6962d 3 3 import com.fasterxml.jackson.databind.node.ObjectNode; 4 4 import mk.profesori.springapp.Model.CustomUserDetails; 5 import mk.profesori.springapp.Model.PostReport; 6 import mk.profesori.springapp.Model.UserRole; 5 7 import mk.profesori.springapp.Service.CustomUserDetailsService; 6 8 import mk.profesori.springapp.Service.MainService; 9 import org.apache.tomcat.websocket.AuthenticationException; 7 10 import org.springframework.security.core.Authentication; 8 11 import org.springframework.security.core.annotation.CurrentSecurityContext; … … 11 14 import org.springframework.web.bind.annotation.*; 12 15 16 import java.util.List; 17 13 18 @RestController 14 19 @RequestMapping("/secure") 15 @CrossOrigin(origins = { "http://192.168.0.1 7:3000", "http://192.168.0.39:3000" })20 @CrossOrigin(origins = { "http://192.168.0.19:3000", "http://192.168.0.39:3000" }) 16 21 public class SecureController { 17 22 18 23 private final MainService mainService; 19 final 20 CustomUserDetailsService customUserDetailsService; 24 final CustomUserDetailsService customUserDetailsService; 21 25 22 26 public SecureController(MainService mainService, CustomUserDetailsService customUserDetailsService) { … … 28 32 public void addOpinion(@RequestBody ObjectNode objectNode, @PathVariable Long professorId, 29 33 @CurrentSecurityContext SecurityContext context) { 30 31 Authentication authentication = context.getAuthentication(); 32 34 Authentication authentication = context.getAuthentication(); 33 35 if (authentication != null && authentication.getPrincipal() instanceof CustomUserDetails currentUser) { 34 36 String content = objectNode.get("content").asText(); … … 40 42 public void replyToOpinion(@RequestBody ObjectNode objectNode, @PathVariable Long professorId, 41 43 @PathVariable Long postId, @CurrentSecurityContext SecurityContext context) { 42 43 Authentication authentication = context.getAuthentication(); 44 44 Authentication authentication = context.getAuthentication(); 45 45 if (authentication != null && authentication.getPrincipal() instanceof CustomUserDetails currentUser) { 46 46 String content = objectNode.get("content").asText(); … … 52 52 public void addThread(@RequestBody ObjectNode objectNode, @PathVariable Long subjectId, 53 53 @CurrentSecurityContext SecurityContext context) { 54 55 Authentication authentication = context.getAuthentication(); 56 54 Authentication authentication = context.getAuthentication(); 57 55 if (authentication != null && authentication.getPrincipal() instanceof CustomUserDetails currentUser) { 58 56 String title = objectNode.get("title").asText(); … … 65 63 public void replyToThread(@RequestBody ObjectNode objectNode, @PathVariable Long subjectId, 66 64 @PathVariable Long postId, @CurrentSecurityContext SecurityContext context) { 67 68 Authentication authentication = context.getAuthentication(); 69 65 Authentication authentication = context.getAuthentication(); 70 66 if (authentication != null && authentication.getPrincipal() instanceof CustomUserDetails currentUser) { 71 67 String content = objectNode.get("content").asText(); … … 76 72 @RequestMapping(value = "/currentUser", method = RequestMethod.GET) 77 73 public UserDetails getUserDetails(@CurrentSecurityContext SecurityContext context) { 78 79 74 Authentication authentication = context.getAuthentication(); 80 75 if (authentication != null && authentication.getPrincipal() instanceof CustomUserDetails currentUser) { 81 76 return customUserDetailsService.loadUserByUsername(currentUser.getEmail()); 82 77 } 83 84 78 return null; 85 79 } … … 87 81 @RequestMapping(value = "/upvoteOpinion/{postId}", method = RequestMethod.GET) 88 82 public void upvoteOpinion(@PathVariable Long postId, @CurrentSecurityContext SecurityContext context) { 89 90 Authentication authentication = context.getAuthentication(); 91 83 Authentication authentication = context.getAuthentication(); 92 84 if (authentication != null && authentication.getPrincipal() instanceof CustomUserDetails currentUser) { 93 85 mainService.upvoteOpinion(postId, currentUser); … … 97 89 @RequestMapping(value = "/downvoteOpinion/{postId}", method = RequestMethod.GET) 98 90 public void downvoteOpinion(@PathVariable Long postId, @CurrentSecurityContext SecurityContext context) { 99 100 Authentication authentication = context.getAuthentication(); 101 91 Authentication authentication = context.getAuthentication(); 102 92 if (authentication != null && authentication.getPrincipal() instanceof CustomUserDetails currentUser) { 103 93 mainService.downvoteOpinion(postId, currentUser); … … 107 97 @RequestMapping(value = "/upvoteThread/{postId}", method = RequestMethod.GET) 108 98 public void upvoteThread(@PathVariable Long postId, @CurrentSecurityContext SecurityContext context) { 109 110 Authentication authentication = context.getAuthentication(); 111 99 Authentication authentication = context.getAuthentication(); 112 100 if (authentication != null && authentication.getPrincipal() instanceof CustomUserDetails currentUser) { 113 101 mainService.upvote_Thread(postId, currentUser); … … 119 107 120 108 Authentication authentication = context.getAuthentication(); 121 122 109 if (authentication != null && authentication.getPrincipal() instanceof CustomUserDetails currentUser) { 123 110 mainService.downvote_Thread(postId, currentUser); … … 125 112 } 126 113 114 @RequestMapping(value = "/deleteOpinion/{postId}", method = RequestMethod.DELETE) 115 public void deleteOpinion(@PathVariable Long postId, @CurrentSecurityContext SecurityContext context) 116 throws Exception { 117 Authentication authentication = context.getAuthentication(); 118 if (authentication != null && authentication.getPrincipal() instanceof CustomUserDetails currentUser 119 && currentUser.getUserRole().equals(UserRole.MODERATOR)) { 120 mainService.deleteOpinion(postId); 121 } else 122 throw new AuthenticationException("Auth exception"); 123 } 124 125 @RequestMapping(value = "/deleteThread/{postId}", method = RequestMethod.DELETE) 126 public void deleteThread(@PathVariable Long postId, @CurrentSecurityContext SecurityContext context) { 127 Authentication authentication = context.getAuthentication(); 128 if (authentication != null && authentication.getPrincipal() instanceof CustomUserDetails currentUser 129 && currentUser.getUserRole().equals(UserRole.MODERATOR)) { 130 mainService.delete_Thread(postId); 131 } 132 } 133 134 @RequestMapping(value = "/updateOpinion/{postId}", method = RequestMethod.PUT) 135 public void updateOpinion(@RequestBody ObjectNode objectNode, @PathVariable Long postId, 136 @CurrentSecurityContext SecurityContext context) { 137 Authentication authentication = context.getAuthentication(); 138 if (authentication != null && authentication.getPrincipal() instanceof CustomUserDetails currentUser 139 && currentUser.getUserRole().equals(UserRole.MODERATOR)) { 140 String newContent = objectNode.get("newContent").asText(); 141 Long newTargetProfessorId = objectNode.get("newTargetProfessorId").asLong(); 142 mainService.updateOpinion(newContent, newTargetProfessorId, postId); 143 } 144 } 145 146 @RequestMapping(value = "/updateThread/{postId}", method = RequestMethod.PUT) 147 public void updateThread(@RequestBody ObjectNode objectNode, @PathVariable Long postId, 148 @CurrentSecurityContext SecurityContext context) { 149 Authentication authentication = context.getAuthentication(); 150 if (authentication != null && authentication.getPrincipal() instanceof CustomUserDetails currentUser 151 && currentUser.getUserRole().equals(UserRole.MODERATOR)) { 152 String newTitle = objectNode.get("newTitle").asText(); 153 String newContent = objectNode.get("newContent").asText(); 154 Long newTargetSubjectId = objectNode.get("newTargetSubjectId").asLong(); 155 156 if (objectNode.has("newParentThreadId")) { 157 Long newParentThreadId = objectNode.get("newParentThreadId").asLong(); 158 mainService.update_Thread(newTitle, newContent, newTargetSubjectId, newParentThreadId, postId); 159 } else { 160 mainService.update_Thread(newTitle, newContent, newTargetSubjectId, null, postId); 161 } 162 } 163 } 164 165 @RequestMapping(value = "/lockUser/{userId}", method = RequestMethod.GET) 166 public void lockUser(@PathVariable Long userId, @CurrentSecurityContext SecurityContext context) { 167 Authentication authentication = context.getAuthentication(); 168 if (authentication != null && authentication.getPrincipal() instanceof CustomUserDetails currentUser 169 && currentUser.getUserRole().equals(UserRole.MODERATOR)) { 170 mainService.lockUser(userId); 171 } 172 } 173 174 @RequestMapping(value = "/deleteUser/{userId}", method = RequestMethod.DELETE) 175 public void deleteUser(@PathVariable Long userId, @CurrentSecurityContext SecurityContext context) { 176 Authentication authentication = context.getAuthentication(); 177 if (authentication != null && authentication.getPrincipal() instanceof CustomUserDetails currentUser 178 && currentUser.getUserRole().equals(UserRole.MODERATOR)) { 179 mainService.deleteUser(userId); 180 } 181 } 182 183 @RequestMapping(value = "/updateUserFullName/{userId}", method = RequestMethod.PUT) 184 public void updateUserFullName(@RequestBody ObjectNode objectNode, @PathVariable Long userId, 185 @CurrentSecurityContext SecurityContext context) { 186 Authentication authentication = context.getAuthentication(); 187 if (authentication != null && authentication.getPrincipal() instanceof CustomUserDetails currentUser 188 && (currentUser.getUserRole().equals(UserRole.MODERATOR) || currentUser.getId().equals(userId))) { 189 String newFullName = objectNode.get("newFullName").asText(); 190 mainService.updateUserFullName(newFullName, userId); 191 } 192 } 193 194 @RequestMapping(value = "/updateUserUsername/{userId}", method = RequestMethod.PUT) 195 public void updateUserUsername(@RequestBody ObjectNode objectNode, @PathVariable Long userId, 196 @CurrentSecurityContext SecurityContext context) { 197 Authentication authentication = context.getAuthentication(); 198 if (authentication != null && authentication.getPrincipal() instanceof CustomUserDetails currentUser 199 && (currentUser.getUserRole().equals(UserRole.MODERATOR) || currentUser.getId().equals(userId))) { 200 String newUsername = objectNode.get("newUsername").asText(); 201 mainService.updateUserUsername(newUsername, userId); 202 } 203 } 204 205 @RequestMapping(value = "/reportOpinion/{postId}", method = RequestMethod.POST) 206 public void reportOpinion(@RequestBody ObjectNode objectNode, @PathVariable Long postId, 207 @CurrentSecurityContext SecurityContext context) { 208 Authentication authentication = context.getAuthentication(); 209 if (authentication != null && authentication.getPrincipal() instanceof CustomUserDetails currentUser) { 210 String description = objectNode.get("description").asText(); 211 mainService.reportOpinion(postId, currentUser, description); 212 } 213 } 214 215 @RequestMapping(value = "/reportThread/{postId}", method = RequestMethod.POST) 216 public void reportThread(@RequestBody ObjectNode objectNode, @PathVariable Long postId, 217 @CurrentSecurityContext SecurityContext context) { 218 Authentication authentication = context.getAuthentication(); 219 if (authentication != null && authentication.getPrincipal() instanceof CustomUserDetails currentUser) { 220 String description = objectNode.get("description").asText(); 221 mainService.reportThread(postId, currentUser, description); 222 } 223 } 224 225 @RequestMapping(value = "/markReportResolved/{postReportId}/", method = RequestMethod.GET) 226 public void markReportResolved(@PathVariable Long postReportId, @PathVariable String action, @CurrentSecurityContext SecurityContext context) { 227 Authentication authentication = context.getAuthentication(); 228 if (authentication != null && authentication.getPrincipal() instanceof CustomUserDetails currentUser) { 229 mainService.markReport(postReportId, action); 230 } 231 } 232 233 @RequestMapping(value = "/getAllPostReports", method = RequestMethod.GET) 234 public List<PostReport> getAllPostReports(@CurrentSecurityContext SecurityContext context) throws AuthenticationException{ 235 Authentication authentication = context.getAuthentication(); 236 if (authentication != null && authentication.getPrincipal() instanceof CustomUserDetails currentUser 237 && currentUser.getUserRole().equals(UserRole.MODERATOR)) { 238 return mainService.getAllPostReports(); 239 } else throw new AuthenticationException("Invalid role"); 240 } 241 242 127 243 } -
springapp/src/main/java/mk/profesori/springapp/Model/CustomUserDetails.java
rc68150f r3b6962d 29 29 @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "user_sequence") 30 30 private Long id; 31 private String fullName; // opcionalno, smee da e prazno31 private String fullName; 32 32 private String username; 33 33 private String email; 34 private String password; // TODO dont expose password in api34 private String password; // TODO 35 35 @Enumerated(EnumType.STRING) 36 36 private UserRole userRole; 37 37 private Boolean locked = false; 38 38 private Boolean enabled = false; 39 @OneToMany(mappedBy = "customUserDetails", cascade = CascadeType.ALL, fetch = FetchType.EAGER)39 @OneToMany(mappedBy = "customUserDetails", fetch = FetchType.EAGER, orphanRemoval = true) 40 40 private Set<ConfirmationToken> confirmationTokens = new HashSet<>(); 41 @OneToMany(mappedBy = "author", cascade = CascadeType.ALL, fetch = FetchType.EAGER)41 @OneToMany(mappedBy = "author", fetch = FetchType.EAGER, orphanRemoval = true) 42 42 private Set<Post> authoredPosts = new HashSet<>(); 43 43 private Integer karma = 0; 44 44 45 public Set<PostVote> getVotes() { 46 return votes; 45 @OneToMany(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true) 46 private Set<PostVote> votes = new HashSet<>(); 47 48 @OneToMany(mappedBy = "user", cascade = {CascadeType.PERSIST}) 49 private Set<PostReport> reportsSubmitted = new HashSet<>(); 50 @PreRemove 51 public void preRemove() { 52 reportsSubmitted.forEach(report -> { 53 report.setUser(null); 54 }); 47 55 } 48 49 public void setVotes(Set<PostVote> votes) {50 this.votes = votes;51 }52 53 @OneToMany(mappedBy = "user")54 private Set<PostVote> votes = new HashSet<>();55 56 56 57 public CustomUserDetails(String fullName, String username, String email, String password, UserRole userRole) { … … 115 116 } 116 117 118 public void setLocked(Boolean locked) { 119 this.locked = locked; 120 } 121 122 public Set<PostVote> getVotes() { 123 return votes; 124 } 125 126 public void setVotes(Set<PostVote> votes) { 127 this.votes = votes; 128 } 117 129 } -
springapp/src/main/java/mk/profesori/springapp/Model/Opinion.java
rc68150f r3b6962d 40 40 return targetProfessor; 41 41 } 42 43 42 public void setTargetProfessor(Professor targetProfessor) { 44 43 this.targetProfessor = targetProfessor; 45 44 } 45 46 46 } -
springapp/src/main/java/mk/profesori/springapp/Model/Post.java
rc68150f r3b6962d 1 1 package mk.profesori.springapp.Model; 2 2 3 import com.fasterxml.jackson.annotation.JsonIdentityInfo; 4 import com.voodoodyne.jackson.jsog.JSOGGenerator; 5 import lombok.NoArgsConstructor; 6 7 import javax.persistence.*; 3 8 import java.time.LocalDateTime; 4 9 import java.util.ArrayList; … … 6 11 import java.util.List; 7 12 import java.util.Set; 8 9 import javax.persistence.CascadeType;10 import javax.persistence.Column;11 import javax.persistence.DiscriminatorColumn;12 import javax.persistence.Entity;13 import javax.persistence.GeneratedValue;14 import javax.persistence.GenerationType;15 import javax.persistence.Id;16 import javax.persistence.Inheritance;17 import javax.persistence.DiscriminatorType;18 import javax.persistence.InheritanceType;19 import javax.persistence.JoinColumn;20 import javax.persistence.ManyToMany;21 import javax.persistence.ManyToOne;22 import javax.persistence.OneToMany;23 24 import com.fasterxml.jackson.annotation.JsonIdentityInfo;25 import com.voodoodyne.jackson.jsog.JSOGGenerator;26 27 import lombok.NoArgsConstructor;28 13 29 14 @Entity(name = "post") … … 59 44 private Post parent; 60 45 61 @OneToMany(mappedBy = "post" )46 @OneToMany(mappedBy = "post", cascade = CascadeType.ALL, orphanRemoval = true) 62 47 private Set<PostVote> votes = new HashSet<>(); 63 48 49 @OneToMany(mappedBy = "post", cascade={CascadeType.PERSIST}) 50 private Set<PostReport> reports = new HashSet<>(); 51 @PreRemove 52 public void preRemove() { 53 reports.forEach(report -> { 54 report.setPost(null); 55 report.setResolved(true); 56 }); 57 } 58 59 60 @OneToMany(mappedBy = "parent", cascade = CascadeType.ALL, orphanRemoval = true) 61 private List<Post> children = new ArrayList<>(); 62 63 // getters and setters 64 64 public Set<PostVote> getVotes() { 65 65 return votes; … … 69 69 this.votes = votes; 70 70 } 71 72 @OneToMany(mappedBy = "parent", cascade = CascadeType.ALL)73 private List<Post> children = new ArrayList<>();74 75 // getters and setters76 71 public Long getPostId() { 77 72 return postId; … … 169 164 } 170 165 166 171 167 } -
springapp/src/main/java/mk/profesori/springapp/Model/_Thread.java
rc68150f r3b6962d 41 41 } 42 42 43 public void setTargetSubject(Subject targetSubject) { 44 this.targetSubject = targetSubject; 45 } 43 46 } -
springapp/src/main/java/mk/profesori/springapp/Repository/CityRepository.java
rc68150f r3b6962d 11 11 public interface CityRepository extends CrudRepository<City, Long>{ 12 12 13 publicList<City> findAll();14 publicCity findByCityId(Long id);13 List<City> findAll(); 14 City findByCityId(Long id); 15 15 } -
springapp/src/main/java/mk/profesori/springapp/Repository/FacultyRepository.java
rc68150f r3b6962d 12 12 public interface FacultyRepository extends CrudRepository<Faculty, Long>{ 13 13 14 publicList<Faculty> findAll();15 publicFaculty findByFacultyId(Long id);16 publicList<Faculty> findByUniversity(University university);14 List<Faculty> findAll(); 15 Faculty findByFacultyId(Long id); 16 List<Faculty> findByUniversity(University university); 17 17 } -
springapp/src/main/java/mk/profesori/springapp/Repository/ProfessorRepository.java
rc68150f r3b6962d 13 13 public interface ProfessorRepository extends CrudRepository<Professor, Long>, JpaSpecificationExecutor<Professor> { 14 14 15 publicList<Professor> findAll();15 List<Professor> findAll(); 16 16 17 publicProfessor findByProfessorId(Long id);17 Professor findByProfessorId(Long id); 18 18 19 publicList<Professor> findByFaculty(Faculty faculty);19 List<Professor> findByFaculty(Faculty faculty); 20 20 21 publicList<Professor> findByProfessorNameContainingIgnoreCase(String name);21 List<Professor> findByProfessorNameContainingIgnoreCase(String name); 22 22 } -
springapp/src/main/java/mk/profesori/springapp/Repository/StudyProgrammeRepository.java
rc68150f r3b6962d 13 13 public interface StudyProgrammeRepository extends CrudRepository<StudyProgramme, Long>{ 14 14 15 publicList<StudyProgramme> findAll();16 publicStudyProgramme findByStudyProgrammeId(Long id);17 publicList<StudyProgramme> findByFaculty(Faculty faculty);15 List<StudyProgramme> findAll(); 16 StudyProgramme findByStudyProgrammeId(Long id); 17 List<StudyProgramme> findByFaculty(Faculty faculty); 18 18 } -
springapp/src/main/java/mk/profesori/springapp/Repository/SubjectRepository.java
rc68150f r3b6962d 8 8 @Repository 9 9 public interface SubjectRepository extends CrudRepository<Subject, Long> { 10 publicSubject findBySubjectId(Long id);10 Subject findBySubjectId(Long id); 11 11 } -
springapp/src/main/java/mk/profesori/springapp/Repository/UniversityRepository.java
rc68150f r3b6962d 12 12 public interface UniversityRepository extends CrudRepository<University, Long> { 13 13 14 publicList<University> findAll();14 List<University> findAll(); 15 15 16 publicUniversity findByUniversityId(Long id);16 University findByUniversityId(Long id); 17 17 18 publicList<University> findByCity(City city);18 List<University> findByCity(City city); 19 19 } -
springapp/src/main/java/mk/profesori/springapp/Security/SecurityConfiguration.java
rc68150f r3b6962d 37 37 @Override 38 38 public void addCorsMappings(CorsRegistry registry) { 39 registry.addMapping("/**").allowedOrigins("http://192.168.0.1 7:3000", "http://192.168.0.39:3000")39 registry.addMapping("/**").allowedOrigins("http://192.168.0.19:3000", "http://192.168.0.39:3000") 40 40 .allowCredentials(true); 41 41 } -
springapp/src/main/java/mk/profesori/springapp/Service/CustomUserDetailsService.java
rc68150f r3b6962d 43 43 userRepository.save(customUserDetails); 44 44 45 String token = createToken(customUserDetails); 46 47 return token; 45 return createToken(customUserDetails); 48 46 } 49 47 … … 60 58 } 61 59 62 public intenableUser(String email) {63 returnuserRepository.enableUser(email);60 public void enableUser(String email) { 61 userRepository.enableUser(email); 64 62 } 65 63 } -
springapp/src/main/java/mk/profesori/springapp/Service/MainService.java
rc68150f r3b6962d 3 3 import mk.profesori.springapp.Model.*; 4 4 import mk.profesori.springapp.Repository.*; 5 import org.springframework.security.core.userdetails.UsernameNotFoundException; 5 6 import org.springframework.stereotype.Service; 6 7 8 import java.time.LocalDateTime; 7 9 import java.util.ArrayList; 8 10 import java.util.List; … … 21 23 private final PostVoteRepository postVoteRepository; 22 24 private final UserRepository userRepository; 23 24 public MainService(ProfessorRepository professorRepository, StudyProgrammeRepository studyProgrammeRepository, FacultyRepository facultyRepository, UniversityRepository universityRepository, CityRepository cityRepository, OpinionRepository opinionRepository, _ThreadRepository _threadRepository, SubjectRepository subjectRepository, PostVoteRepository postVoteRepository, UserRepository userRepository) { 25 private final PostReportRepository postReportRepository; 26 27 public MainService(ProfessorRepository professorRepository, StudyProgrammeRepository studyProgrammeRepository, FacultyRepository facultyRepository, UniversityRepository universityRepository, CityRepository cityRepository, OpinionRepository opinionRepository, _ThreadRepository _threadRepository, SubjectRepository subjectRepository, PostVoteRepository postVoteRepository, UserRepository userRepository, PostReportRepository postReportRepository) { 25 28 this.professorRepository = professorRepository; 26 29 this.studyProgrammeRepository = studyProgrammeRepository; … … 33 36 this.postVoteRepository = postVoteRepository; 34 37 this.userRepository = userRepository; 38 this.postReportRepository = postReportRepository; 35 39 } 36 40 … … 183 187 targetPost.getAuthor().setKarma(targetPost.getAuthor().getKarma()+1); 184 188 userRepository.save(targetPost.getAuthor()); 185 186 189 } 187 190 public void downvote_Thread(Long postId, CustomUserDetails currentUser) { … … 192 195 userRepository.save(targetPost.getAuthor()); 193 196 } 197 198 public void deleteOpinion(Long postId) {opinionRepository.deleteById(postId);} 199 public void delete_Thread(Long postId) {_threadRepository.deleteById(postId);} 200 201 public void updateOpinion(String newContent, Long newTargetProfessorId, Long postId) { 202 Opinion opinionToUpdate = opinionRepository.findByPostId(postId); 203 204 opinionToUpdate.setContent(newContent); 205 206 Professor newTargetProfessor = professorRepository.findByProfessorId(newTargetProfessorId); 207 opinionToUpdate.setTargetProfessor(newTargetProfessor); //opcijava da ja dava samo kaj postovi so parentPost==null 208 for(Post p : opinionToUpdate.getChildren()) { 209 Opinion o = (Opinion) p; 210 o.setTargetProfessor(newTargetProfessor); 211 } 212 opinionToUpdate.setTimeLastEdited(LocalDateTime.now()); 213 opinionRepository.save(opinionToUpdate); 214 } 215 216 public void update_Thread(String newTitle, String newContent, Long newTargetSubjectId, Long newParentThreadId, Long postId) { 217 _Thread _threadToUpdate = _threadRepository.findByPostId(postId); 218 219 _threadToUpdate.setContent(newContent); 220 221 Subject newTargetSubject = subjectRepository.findBySubjectId(newTargetSubjectId); 222 _threadToUpdate.setTargetSubject(newTargetSubject); 223 224 if(newParentThreadId != null) { //samo ako e specificirano 225 _Thread newParentThread = _threadRepository.findByPostId(newParentThreadId); 226 227 if (_threadToUpdate.getParent() == null || _threadToUpdate.getParent().getPostId().equals(postId)) { 228 _threadToUpdate.setParent(newParentThread); 229 }//samo ako e naslovniot post ili directChild 230 } else if(_threadToUpdate.getParent() != null) { 231 _threadToUpdate.setParent(null); 232 } 233 234 if(_threadToUpdate.getParent() == null) { 235 _threadToUpdate.setTitle(newTitle); 236 } else { 237 _threadToUpdate.setTitle(null); 238 } 239 240 for(Post p : _threadToUpdate.getChildren()) { 241 _Thread t = (_Thread) p; 242 t.setTargetSubject(newTargetSubject); 243 } 244 _threadToUpdate.setTimeLastEdited(LocalDateTime.now()); 245 _threadRepository.save(_threadToUpdate); 246 } 247 248 public void lockUser(Long userId) { 249 CustomUserDetails user = userRepository.findById(userId).orElseThrow(() -> new UsernameNotFoundException("Invalid userId")); 250 user.setLocked(true); 251 userRepository.save(user); 252 } 253 254 public void deleteUser(Long userId) { 255 userRepository.deleteById(userId); 256 } 257 258 259 public void updateUserFullName(String newFullName, Long userId) { 260 CustomUserDetails user = userRepository.findById(userId).orElseThrow(() -> new UsernameNotFoundException("Invalid userId")); 261 user.setFullName(newFullName); 262 userRepository.save(user); 263 } 264 265 public void updateUserUsername(String newUsername, Long userId) { 266 CustomUserDetails user = userRepository.findById(userId).orElseThrow(() -> new UsernameNotFoundException("Invalid userId")); 267 user.setUsername(newUsername); 268 userRepository.save(user); 269 } 270 271 272 public void reportOpinion(Long postId, CustomUserDetails currentUser, String description) { 273 Post targetPost = opinionRepository.findByPostId(postId); 274 PostReport reportToAdd = new PostReport(currentUser, targetPost, description); 275 postReportRepository.save(reportToAdd); 276 } 277 278 public void markReport(Long postReportId, String action) { 279 PostReport report = postReportRepository.findByPostReportId(postReportId); 280 if (action.equals("resolve")) report.setResolved(true); 281 else if (action.equals("open")) report.setResolved(false); 282 } 283 284 public List<PostReport> getAllPostReports() { 285 return postReportRepository.findAll(); 286 } 287 288 public void reportThread(Long postId, CustomUserDetails currentUser, String description) { 289 Post targetPost = _threadRepository.findByPostId(postId); 290 PostReport reportToAdd = new PostReport(currentUser, targetPost, description); 291 postReportRepository.save(reportToAdd); 292 } 194 293 } -
springapp/src/main/java/mk/profesori/springapp/Service/RegistrationService.java
rc68150f r3b6962d 45 45 String tokenToResend = customUserDetailsService 46 46 .createToken(userRepository.findByEmail(request.getEmail()).get()); 47 String link = "http://192.168.0.1 7:8080/registration/confirm?token=" + tokenToResend;47 String link = "http://192.168.0.19:8080/registration/confirm?token=" + tokenToResend; 48 48 emailSender.send(request.getEmail(), emailSender.buildEmail(request.getUsername(), link)); 49 49 return tokenToResend; … … 66 66 UserRole.REGULAR)); 67 67 68 String link = "http://192.168.0.1 7:8080/registration/confirm?token=" + token;68 String link = "http://192.168.0.19:8080/registration/confirm?token=" + token; 69 69 70 70 emailSender.send(request.getEmail(), emailSender.buildEmail(request.getUsername(), link)); -
springapp/src/main/resources/application.properties
rc68150f r3b6962d 7 7 spring.jpa.show-sql=false 8 8 spring.jpa.properties.hibernate.format_sql=true 9 server.address=192.168.0.1 710 spring.mail.host= 192.168.0.399 server.address=192.168.0.19 10 spring.mail.host=localhost 11 11 spring.mail.username=mailuser 12 12 spring.mail.password=mailpass
Note:
See TracChangeset
for help on using the changeset viewer.