Changeset 62b653f
- Timestamp:
- 08/30/22 15:33:18 (2 years ago)
- Branches:
- main
- Children:
- cae16b5
- Parents:
- 2fcbde4
- Files:
-
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
reactapp/src/App.js
r2fcbde4 r62b653f 21 21 try { 22 22 const response = await axios.get( 23 "http://192.168.0.1 9:8080/secure/currentUser",23 "http://192.168.0.17:8080/secure/currentUser", 24 24 { withCredentials: true } 25 25 ); -
reactapp/src/Components/OpinionTree.js
r2fcbde4 r62b653f 8 8 OpinionReplyCardContentTime, 9 9 StyledFontAwesomeIcon, 10 VoteCount, 10 11 } from "./Styled/OpinionCard.style"; 11 12 import { solid } from "@fortawesome/fontawesome-svg-core/import.macro"; … … 37 38 const [postForModal, setPostForModal] = useState(null); 38 39 39 const handleLike = () => { 40 if (auth) { 40 const handleLike = async (post) => { 41 if ( 42 auth && 43 userLoaded && 44 !post.likes.some((e) => e.id === user.user.id) && 45 !post.dislikes.some((e) => e.id === user.user.id) 46 ) { 47 const response = await axios( 48 `http://192.168.0.17:8080/secure/professor/${professor.professorId}/upvoteOpinion/${post.postId}`, 49 { 50 method: "get", 51 withCredentials: true, 52 } 53 ); 54 55 window.location.reload(false); 56 } else { 41 57 return; 58 } 59 }; 60 61 const handleDislike = async (post) => { 62 if ( 63 auth && 64 auth && 65 userLoaded && 66 !post.likes.some((e) => e.id === user.user.id) && 67 !post.dislikes.some((e) => e.id === user.user.id) 68 ) { 69 const response = await axios( 70 `http://192.168.0.17:8080/secure/professor/${professor.professorId}/downvoteOpinion/${post.postId}`, 71 { 72 method: "get", 73 withCredentials: true, 74 } 75 ); 76 77 window.location.reload(false); 42 78 } else { 43 navigate("/login");44 }45 };46 47 const handleDislike = () => {48 if (auth) {49 79 return; 50 } else {51 navigate("/login");52 80 } 53 81 }; … … 74 102 75 103 const response = await axios( 76 `http://192.168.0.1 9:8080/secure/professor/${professor.professorId}/replyToOpinion/${postId}`,104 `http://192.168.0.17:8080/secure/professor/${professor.professorId}/replyToOpinion/${postId}`, 77 105 { 78 106 method: "post", … … 110 138 icon={solid("thumbs-up")} 111 139 right={50 + "px"} 112 color="greenyellow" 113 onClick={handleLike} 140 color={ 141 child.likes.some((e) => e.id === user.user.id) 142 ? "greenyellow" 143 : "darkgrey" 144 } 145 onClick={() => handleLike(child)} 114 146 /> 147 <VoteCount right={50 + "px"}>{child.likes.length}</VoteCount> 115 148 <StyledFontAwesomeIcon 116 149 icon={solid("thumbs-down")} 117 150 right={10 + "px"} 118 color="indianred" 119 onClick={handleDislike} 151 color={ 152 child.dislikes.some((e) => e.id === user.user.id) 153 ? "indianred" 154 : "darkgrey" 155 } 156 onClick={() => handleDislike(child)} 120 157 /> 158 <VoteCount right={10 + "px"}>{child.dislikes.length}</VoteCount> 121 159 <StyledFontAwesomeIcon 122 160 icon={solid("reply")} 123 161 right={90 + "px"} 124 color=" black"162 color="darkgrey" 125 163 onClick={() => handleReply(child)} 126 164 /> … … 166 204 icon={solid("thumbs-up")} 167 205 right={50 + "px"} 168 color="greenyellow" 169 onClick={handleLike} 206 color={ 207 opinion.likes.some((e) => e.id === user.user.id) 208 ? "greenyellow" 209 : "darkgrey" 210 } 211 onClick={() => handleLike(opinion)} 170 212 /> 213 <VoteCount right={50 + "px"}> 214 {opinion.likes.length} 215 </VoteCount> 171 216 <StyledFontAwesomeIcon 172 217 icon={solid("thumbs-down")} 173 218 right={10 + "px"} 174 color="indianred" 175 onClick={handleDislike} 219 color={ 220 opinion.dislikes.some((e) => e.id === user.user.id) 221 ? "indianred" 222 : "darkgrey" 223 } 224 onClick={() => handleDislike(opinion)} 176 225 /> 226 <VoteCount right={10 + "px"}> 227 {opinion.dislikes.length} 228 </VoteCount> 177 229 <StyledFontAwesomeIcon 178 230 icon={solid("reply")} 179 231 right={90 + "px"} 180 color=" black"232 color="darkgrey" 181 233 onClick={() => handleReply(opinion)} 182 234 /> -
reactapp/src/Components/Search.js
r2fcbde4 r62b653f 15 15 16 16 useEffect(() => { 17 const url = `http://192.168.0.1 9:8080/public/professors/nameContains/${transliterate(17 const url = `http://192.168.0.17:8080/public/professors/nameContains/${transliterate( 18 18 query 19 19 )}`; -
reactapp/src/Components/Styled/OpinionCard.style.js
r2fcbde4 r62b653f 52 52 53 53 export const StyledFontAwesomeIcon = styled(FontAwesomeIcon)` 54 color: darkgrey;54 color: ${(props) => props.color}; 55 55 display: block; 56 56 position: absolute; … … 64 64 } 65 65 `; 66 67 export const VoteCount = styled.p` 68 color: darkgrey; 69 display: block; 70 position: absolute; 71 top: 80%; 72 transform: translateY(-50%); 73 right: ${(props) => props.right}; 74 transition: 0.5s; 75 `; -
reactapp/src/Pages/Professor.js
r2fcbde4 r62b653f 36 36 37 37 useEffect(() => { 38 const url = `http://192.168.0.1 9:8080/public/professor/${params.professorId}`;38 const url = `http://192.168.0.17:8080/public/professor/${params.professorId}`; 39 39 40 40 const fetchData = async () => { … … 70 70 71 71 const response = await axios( 72 `http://192.168.0.1 9:8080/secure/professor/${professor.professorId}/addOpinion`,72 `http://192.168.0.17:8080/secure/professor/${professor.professorId}/addOpinion`, 73 73 { 74 74 method: "post", -
reactapp/src/api/axios.js
r2fcbde4 r62b653f 2 2 3 3 export default axios.create({ 4 baseURL: "http://192.168.0.1 9:8080",4 baseURL: "http://192.168.0.17:8080", 5 5 }); -
springapp/src/main/java/mk/profesori/springapp/Controller/PublicController.java
r2fcbde4 r62b653f 23 23 @RestController 24 24 @RequestMapping("/public") 25 @CrossOrigin(origins = { "http://192.168.0.1 9:3000", "http://192.168.0.24:3000" })25 @CrossOrigin(origins = { "http://192.168.0.17:3000", "http://192.168.0.24:3000" }) 26 26 public class PublicController { 27 27 -
springapp/src/main/java/mk/profesori/springapp/Controller/SecureController.java
r2fcbde4 r62b653f 25 25 @RestController 26 26 @RequestMapping("/secure") 27 @CrossOrigin(origins = { "http://192.168.0.1 9:3000", "http://192.168.0.24:3000" })27 @CrossOrigin(origins = { "http://192.168.0.17:3000", "http://192.168.0.24:3000" }) 28 28 public class SecureController { 29 29 … … 72 72 } 73 73 74 @RequestMapping(value = "/professor/{professorId}/upvoteOpinion/{postId}", method = RequestMethod.GET) 75 public void upvoteOpinion(@PathVariable Long professorId, 76 @PathVariable Long postId, @CurrentSecurityContext SecurityContext context) { 77 78 Authentication authentication = context.getAuthentication(); 79 80 if (authentication != null && authentication.getPrincipal() instanceof CustomUserDetails) { 81 CustomUserDetails currentUser = (CustomUserDetails) authentication.getPrincipal(); 82 mainService.upvoteOpinion(postId, currentUser); 83 } 84 } 85 86 @RequestMapping(value = "/professor/{professorId}/downvoteOpinion/{postId}", method = RequestMethod.GET) 87 public void downvoteOpinion(@PathVariable Long professorId, 88 @PathVariable Long postId, @CurrentSecurityContext SecurityContext context) { 89 90 Authentication authentication = context.getAuthentication(); 91 92 if (authentication != null && authentication.getPrincipal() instanceof CustomUserDetails) { 93 CustomUserDetails currentUser = (CustomUserDetails) authentication.getPrincipal(); 94 mainService.downvoteOpinion(postId, currentUser); 95 } 96 } 97 74 98 } -
springapp/src/main/java/mk/profesori/springapp/Model/CustomUserDetails.java
r2fcbde4 r62b653f 12 12 import javax.persistence.EnumType; 13 13 import javax.persistence.Enumerated; 14 import javax.persistence.FetchType; 14 15 import javax.persistence.GeneratedValue; 15 16 import javax.persistence.GenerationType; 16 17 import javax.persistence.Id; 18 import javax.persistence.JoinTable; 19 import javax.persistence.JoinColumn; 20 import javax.persistence.ManyToMany; 17 21 import javax.persistence.OneToMany; 18 22 import javax.persistence.SequenceGenerator; … … 50 54 private Boolean locked = false; 51 55 private Boolean enabled = false; 52 @OneToMany(mappedBy = "customUserDetails", cascade = CascadeType.ALL )56 @OneToMany(mappedBy = "customUserDetails", cascade = CascadeType.ALL, fetch = FetchType.EAGER) 53 57 private Set<ConfirmationToken> confirmationTokens = new HashSet<>(); 54 @OneToMany(mappedBy = "author", cascade = CascadeType.ALL )58 @OneToMany(mappedBy = "author", cascade = CascadeType.ALL, fetch = FetchType.EAGER) 55 59 private Set<Post> authoredPosts = new HashSet<>(); 56 private Integer karma; 60 private Integer karma = 0; 61 @ManyToMany(fetch = FetchType.EAGER) 62 @JoinTable(name = "post_like", joinColumns = @JoinColumn(name = "custom_user_details_id"), inverseJoinColumns = @JoinColumn(name = "post_id")) 63 Set<Post> likedPosts; 64 @ManyToMany(fetch = FetchType.EAGER) 65 @JoinTable(name = "post_dislike", joinColumns = @JoinColumn(name = "custom_user_details_id"), inverseJoinColumns = @JoinColumn(name = "post_id")) 66 Set<Post> dislikedPosts; 57 67 58 68 public CustomUserDetails(String fullName, String username, String email, String password, UserRole userRole) { … … 105 115 106 116 public Integer getKarma() { 107 Integer karma = 0; 108 for (Post post : this.authoredPosts) { 109 karma += post.getUpvoteCount() - post.getDownvoteCount(); 110 } 111 return karma; 117 return this.karma; 112 118 } 113 119 120 public void setKarma(Integer karma) { 121 this.karma = karma; 122 } 123 124 public Set<Post> getLikedPosts() { 125 return this.likedPosts; 126 } 127 128 public void setLikedPosts(Set<Post> likedPosts) { 129 this.likedPosts = likedPosts; 130 } 131 132 public Set<Post> getDislikedPosts() { 133 return this.dislikedPosts; 134 } 135 136 public void setDislikedPosts(Set<Post> dislikedPosts) { 137 this.likedPosts = dislikedPosts; 138 } 114 139 } -
springapp/src/main/java/mk/profesori/springapp/Model/Opinion.java
r2fcbde4 r62b653f 23 23 public Opinion(String title, String content, CustomUserDetails author, LocalDateTime timePosted, 24 24 LocalDateTime timeLastEdited, 25 Integer upvoteCount, Integer downvoteCount,Post parent, List<Post> children, Professor targetProfessor) {26 super(title, content, author, timePosted, timeLastEdited, upvoteCount, downvoteCount,parent, children);25 Post parent, List<Post> children, Professor targetProfessor) { 26 super(title, content, author, timePosted, timeLastEdited, parent, children); 27 27 this.targetProfessor = targetProfessor; 28 28 } … … 31 31 public Opinion(String title, String content, CustomUserDetails author, LocalDateTime timePosted, 32 32 LocalDateTime timeLastEdited, 33 Integer upvoteCount, Integer downvoteCount,List<Post> children, Professor targetProfessor) {34 super(title, content, author, timePosted, timeLastEdited, upvoteCount, downvoteCount,children);33 List<Post> children, Professor targetProfessor) { 34 super(title, content, author, timePosted, timeLastEdited, children); 35 35 this.targetProfessor = targetProfessor; 36 36 } -
springapp/src/main/java/mk/profesori/springapp/Model/Post.java
r2fcbde4 r62b653f 4 4 import java.util.ArrayList; 5 5 import java.util.List; 6 import java.util.Set; 6 7 7 8 import javax.persistence.CascadeType; … … 16 17 import javax.persistence.InheritanceType; 17 18 import javax.persistence.JoinColumn; 19 import javax.persistence.ManyToMany; 18 20 import javax.persistence.ManyToOne; 19 21 import javax.persistence.OneToMany; … … 52 54 private LocalDateTime timeLastEdited; 53 55 54 @Column(name = "upvote_count")55 private Integer upvoteCount;56 57 @Column(name = "downvote_count")58 private Integer downvoteCount;59 60 56 @ManyToOne 61 57 @JoinColumn(name = "parent_post_id", nullable = true) … … 64 60 @OneToMany(mappedBy = "parent", cascade = CascadeType.ALL) 65 61 private List<Post> children = new ArrayList<>(); 62 63 @ManyToMany(mappedBy = "likedPosts") 64 Set<CustomUserDetails> likes; 65 66 @ManyToMany(mappedBy = "dislikedPosts") 67 Set<CustomUserDetails> dislikes; 66 68 67 69 // getters and setters … … 114 116 } 115 117 116 public Integer getUpvoteCount() {117 return upvoteCount;118 }119 120 public void setUpvoteCount(Integer upvoteCount) {121 this.upvoteCount = upvoteCount;122 }123 124 public Integer getDownvoteCount() {125 return downvoteCount;126 }127 128 public void setDownvoteCount(Integer downvoteCount) {129 this.downvoteCount = downvoteCount;130 }131 132 118 public Post getParent() { 133 119 return parent; … … 146 132 } 147 133 134 public Set<CustomUserDetails> getLikes() { 135 return likes; 136 } 137 138 public void setLikes(Set<CustomUserDetails> likes) { 139 this.likes = likes; 140 } 141 142 public Set<CustomUserDetails> getDislikes() { 143 return dislikes; 144 } 145 146 public void setDislikes(Set<CustomUserDetails> dislikes) { 147 this.dislikes = dislikes; 148 } 149 148 150 // konstruktor so parent (koga e reply) 149 151 public Post(String title, String content, CustomUserDetails author, LocalDateTime timePosted, 150 152 LocalDateTime timeLastEdited, 151 Integer upvoteCount, Integer downvoteCount,Post parent, List<Post> children) {153 Post parent, List<Post> children) { 152 154 this.title = title; 153 155 this.content = content; … … 155 157 this.timePosted = LocalDateTime.now(); 156 158 this.timeLastEdited = LocalDateTime.now(); 157 this.upvoteCount = 0;158 this.downvoteCount = 0;159 159 this.parent = parent; 160 160 this.children = new ArrayList<>(); … … 164 164 public Post(String title, String content, CustomUserDetails author, LocalDateTime timePosted, 165 165 LocalDateTime timeLastEdited, 166 Integer upvoteCount, Integer downvoteCount,List<Post> children) {166 List<Post> children) { 167 167 this.title = title; 168 168 this.content = content; … … 170 170 this.timePosted = LocalDateTime.now(); 171 171 this.timeLastEdited = LocalDateTime.now(); 172 this.upvoteCount = 0;173 this.downvoteCount = 0;174 172 this.parent = null; 175 173 this.children = new ArrayList<>(); -
springapp/src/main/java/mk/profesori/springapp/Security/SecurityConfiguration.java
r2fcbde4 r62b653f 37 37 @Override 38 38 public void addCorsMappings(CorsRegistry registry) { 39 registry.addMapping("/**").allowedOrigins("http://192.168.0.1 9:3000", "http://192.168.0.24:3000")39 registry.addMapping("/**").allowedOrigins("http://192.168.0.17:3000", "http://192.168.0.24:3000") 40 40 .allowCredentials(true); 41 41 } -
springapp/src/main/java/mk/profesori/springapp/Service/ConfirmationTokenService.java
r2fcbde4 r62b653f 13 13 @AllArgsConstructor 14 14 public class ConfirmationTokenService { 15 15 16 16 private final ConfirmationTokenRepository confirmationTokenRepository; 17 17 -
springapp/src/main/java/mk/profesori/springapp/Service/CustomUserDetailsService.java
r2fcbde4 r62b653f 22 22 23 23 private final UserRepository userRepository; 24 24 25 @Autowired 25 public PasswordEncoder passwordEncoder() 26 { 26 public PasswordEncoder passwordEncoder() { 27 27 return new BCryptPasswordEncoder(); 28 28 } 29 29 30 private final static String USER_NOT_FOUND_MSG = "User with email %s not found"; 30 31 private final ConfirmationTokenService confirmationTokenService; … … 33 34 public UserDetails loadUserByUsername(String email) throws UsernameNotFoundException { 34 35 return userRepository.findByEmail(email).orElseThrow( 35 () -> new UsernameNotFoundException(String.format(USER_NOT_FOUND_MSG,email)) 36 ); 36 () -> new UsernameNotFoundException(String.format(USER_NOT_FOUND_MSG, email))); 37 37 } 38 38 … … 51 51 String token = UUID.randomUUID().toString(); 52 52 ConfirmationToken confirmationToken = new ConfirmationToken( 53 token, 54 LocalDateTime.now(), 55 LocalDateTime.now().plusMinutes(10), 56 customUserDetails 57 ); 58 53 token, 54 LocalDateTime.now(), 55 LocalDateTime.now().plusMinutes(10), 56 customUserDetails); 57 59 58 confirmationTokenService.saveConfirmationToken(confirmationToken); 60 59 return token; -
springapp/src/main/java/mk/profesori/springapp/Service/MainService.java
r2fcbde4 r62b653f 13 13 import mk.profesori.springapp.Repository.StudyProgrammeRepository; 14 14 import mk.profesori.springapp.Repository.UniversityRepository; 15 import mk.profesori.springapp.Repository.UserRepository; 15 16 import mk.profesori.springapp.Model.City; 16 17 import mk.profesori.springapp.Model.CustomUserDetails; … … 36 37 @Autowired 37 38 private OpinionRepository opinionRepository; 39 @Autowired 40 private UserRepository userRepository; 38 41 39 42 public List<Professor> getAllProfessors() { … … 138 141 139 142 Opinion opinionToAdd = new Opinion(title, content, currentUser, null, null, 140 null, null, null,targetProfessor);143 null, targetProfessor); 141 144 142 145 opinionRepository.save(opinionToAdd); … … 149 152 150 153 Opinion opinionToAdd = new Opinion(null, content, currentUser, null, null, 151 null, null,targetOpinion, null, targetProfessor);154 targetOpinion, null, targetProfessor); 152 155 opinionRepository.save(opinionToAdd); 153 156 … … 155 158 opinionRepository.save(targetOpinion); 156 159 } 160 161 public void upvoteOpinion(Long postId, CustomUserDetails currentUser) { 162 Opinion targetOpinion = opinionRepository.findByPostId(postId); 163 164 if (!targetOpinion.getLikes().contains(currentUser)) { 165 166 targetOpinion.getLikes().add(currentUser); 167 // opinionRepository.save(targetOpinion); 168 169 targetOpinion.getAuthor().setKarma(targetOpinion.getAuthor().getKarma() + 1); 170 userRepository.save(targetOpinion.getAuthor()); 171 172 currentUser.getLikedPosts().add(targetOpinion); 173 userRepository.save(currentUser); 174 } 175 } 176 177 public void downvoteOpinion(Long postId, CustomUserDetails currentUser) { 178 Opinion targetOpinion = opinionRepository.findByPostId(postId); 179 180 if (!targetOpinion.getDislikes().contains(currentUser)) { 181 182 targetOpinion.getDislikes().add(currentUser); 183 // opinionRepository.save(targetOpinion); 184 185 targetOpinion.getAuthor().setKarma(targetOpinion.getAuthor().getKarma() - 1); 186 userRepository.save(targetOpinion.getAuthor()); 187 188 currentUser.getDislikedPosts().add(targetOpinion); 189 userRepository.save(currentUser); 190 } 191 } 157 192 } -
springapp/src/main/java/mk/profesori/springapp/Service/RegistrationService.java
r2fcbde4 r62b653f 45 45 String tokenToResend = customUserDetailsService 46 46 .createToken(userRepository.findByEmail(request.getEmail()).get()); 47 String link = "http://192.168.0.1 9:8080/registration/confirm?token=" + tokenToResend;47 String link = "http://192.168.0.17: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 9:8080/registration/confirm?token=" + token;68 String link = "http://192.168.0.17:8080/registration/confirm?token=" + token; 69 69 70 70 emailSender.send(request.getEmail(), emailSender.buildEmail(request.getUsername(), link)); -
springapp/src/main/resources/application.properties
r2fcbde4 r62b653f 7 7 spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect 8 8 spring.jpa.properties.hibernate.format_sql=true 9 server.address=192.168.0.1 99 server.address=192.168.0.17 10 10 spring.mail.host=192.168.0.24 11 11 spring.mail.username=mailuser
Note:
See TracChangeset
for help on using the changeset viewer.