Changeset af801e3 for springapp/src
- Timestamp:
- 12/08/22 22:44:02 (2 years ago)
- Branches:
- main
- Children:
- a5aba17
- Parents:
- 3b6962d
- Location:
- springapp/src/main
- Files:
-
- 2 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
springapp/src/main/java/mk/profesori/springapp/Controller/PublicController.java
r3b6962d raf801e3 25 25 @RestController 26 26 @RequestMapping("/public") 27 @CrossOrigin(origins = { "http://192.168.0. 19:3000", "http://192.168.0.39:3000" })27 @CrossOrigin(origins = { "http://192.168.0.29:3000", "http://192.168.0.28:3000" }) 28 28 public class PublicController { 29 29 -
springapp/src/main/java/mk/profesori/springapp/Controller/SecureController.java
r3b6962d raf801e3 6 6 import mk.profesori.springapp.Model.UserRole; 7 7 import mk.profesori.springapp.Service.CustomUserDetailsService; 8 import mk.profesori.springapp.Service.DisallowedOperationException; 9 import mk.profesori.springapp.Service.IncompatiblePostId; 8 10 import mk.profesori.springapp.Service.MainService; 9 11 import org.apache.tomcat.websocket.AuthenticationException; … … 18 20 @RestController 19 21 @RequestMapping("/secure") 20 @CrossOrigin(origins = { "http://192.168.0. 19:3000", "http://192.168.0.39:3000" })22 @CrossOrigin(origins = { "http://192.168.0.29:3000", "http://192.168.0.28:3000" }) 21 23 public class SecureController { 22 24 … … 133 135 134 136 @RequestMapping(value = "/updateOpinion/{postId}", method = RequestMethod.PUT) 135 public voidupdateOpinion(@RequestBody ObjectNode objectNode, @PathVariable Long postId,137 public String updateOpinion(@RequestBody ObjectNode objectNode, @PathVariable Long postId, 136 138 @CurrentSecurityContext SecurityContext context) { 137 139 Authentication authentication = context.getAuthentication(); … … 140 142 String newContent = objectNode.get("newContent").asText(); 141 143 Long newTargetProfessorId = objectNode.get("newTargetProfessorId").asLong(); 142 mainService.updateOpinion(newContent, newTargetProfessorId, postId); 143 } 144 Long newParentPostId = objectNode.get("newParentPostId").asLong(); 145 try { 146 mainService.updateOpinion(newContent, newTargetProfessorId, newParentPostId, postId); 147 } catch (IncompatiblePostId | DisallowedOperationException e) { 148 return e.getMessage(); 149 } 150 } 151 152 return null; 144 153 } 145 154 146 155 @RequestMapping(value = "/updateThread/{postId}", method = RequestMethod.PUT) 147 public voidupdateThread(@RequestBody ObjectNode objectNode, @PathVariable Long postId,156 public String updateThread(@RequestBody ObjectNode objectNode, @PathVariable Long postId, 148 157 @CurrentSecurityContext SecurityContext context) { 149 158 Authentication authentication = context.getAuthentication(); … … 153 162 String newContent = objectNode.get("newContent").asText(); 154 163 Long newTargetSubjectId = objectNode.get("newTargetSubjectId").asLong(); 155 156 if (objectNode.has("newParentThreadId")) { 157 Long newParentThreadId = objectNode.get("newParentThreadId").asLong(); 164 Long newParentThreadId = objectNode.get("newParentThreadId").asLong(); 165 try { 158 166 mainService.update_Thread(newTitle, newContent, newTargetSubjectId, newParentThreadId, postId); 159 } else{160 mainService.update_Thread(newTitle, newContent, newTargetSubjectId, null, postId);167 } catch (IncompatiblePostId | DisallowedOperationException e) { 168 return e.getMessage(); 161 169 } 162 170 } 171 172 return null; 163 173 } 164 174 … … 223 233 } 224 234 225 @RequestMapping(value = "/markReportResolved/{postReportId}/ ", method = RequestMethod.GET)235 @RequestMapping(value = "/markReportResolved/{postReportId}/{action}", method = RequestMethod.GET) 226 236 public void markReportResolved(@PathVariable Long postReportId, @PathVariable String action, @CurrentSecurityContext SecurityContext context) { 227 237 Authentication authentication = context.getAuthentication(); 228 if (authentication != null && authentication.getPrincipal() instanceof CustomUserDetails currentUser) { 238 if (authentication != null && authentication.getPrincipal() instanceof CustomUserDetails currentUser && 239 currentUser.getUserRole().equals(UserRole.MODERATOR)) { 229 240 mainService.markReport(postReportId, action); 230 241 } -
springapp/src/main/java/mk/profesori/springapp/Security/SecurityConfiguration.java
r3b6962d raf801e3 37 37 @Override 38 38 public void addCorsMappings(CorsRegistry registry) { 39 registry.addMapping("/**").allowedOrigins("http://192.168.0. 19:3000", "http://192.168.0.39:3000")39 registry.addMapping("/**").allowedOrigins("http://192.168.0.29:3000", "http://192.168.0.28:3000") 40 40 .allowCredentials(true); 41 41 } -
springapp/src/main/java/mk/profesori/springapp/Service/MainService.java
r3b6962d raf801e3 141 141 public void addThread(String title, String content, Long subjectId, CustomUserDetails currentUser) { 142 142 Subject targetSubject = subjectRepository.findBySubjectId(subjectId); 143 144 _Thread _threadToAdd = new _Thread(title, content, currentUser, null, null, null, targetSubject); 143 String titleToSet = title.equals("") ? null : title; 144 145 _Thread _threadToAdd = new _Thread(titleToSet, content, currentUser, null, null, null, targetSubject); 145 146 _threadRepository.save(_threadToAdd); 146 147 } … … 199 200 public void delete_Thread(Long postId) {_threadRepository.deleteById(postId);} 200 201 201 public void updateOpinion(String newContent, Long newTargetProfessorId, Long postId) {202 public String updateOpinion(String newContent, Long newTargetProfessorId, Long newParentPostId, Long postId) { 202 203 Opinion opinionToUpdate = opinionRepository.findByPostId(postId); 203 204 … … 205 206 206 207 Professor newTargetProfessor = professorRepository.findByProfessorId(newTargetProfessorId); 207 opinionToUpdate.setTargetProfessor(newTargetProfessor); //opcijava da ja dava samo kaj postovi so parentPost==null 208 opinionToUpdate.setTargetProfessor(newTargetProfessor); 209 210 Opinion newParentOpinion = null; 211 if (newParentPostId != -1) { 212 newParentOpinion = opinionRepository.findByPostId(newParentPostId); 213 if (!newParentOpinion.getTargetProfessor().equals(newTargetProfessor)) 214 throw new IncompatiblePostId("Мислењето не припаѓа во специфицираната секција за дискусија."); 215 if (opinionToUpdate.getChildren().contains(newParentOpinion)) 216 throw new DisallowedOperationException("Мислењето не може да се постави како дете на негово дете (бесконечна рекурзија)"); 217 } 218 opinionToUpdate.setParent(newParentOpinion); 219 208 220 for(Post p : opinionToUpdate.getChildren()) { 209 221 Opinion o = (Opinion) p; … … 212 224 opinionToUpdate.setTimeLastEdited(LocalDateTime.now()); 213 225 opinionRepository.save(opinionToUpdate); 214 } 215 216 public void update_Thread(String newTitle, String newContent, Long newTargetSubjectId, Long newParentThreadId, Long postId) { 226 return null; 227 } 228 229 public String update_Thread(String newTitle, String newContent, Long newTargetSubjectId, Long newParentThreadId, Long postId) { 217 230 _Thread _threadToUpdate = _threadRepository.findByPostId(postId); 218 231 … … 222 235 _threadToUpdate.setTargetSubject(newTargetSubject); 223 236 224 if(newParentThreadId != null) { //samo ako e specificirano225 _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 directChild230 } else if(_threadToUpdate.getParent() != null) {231 _threadToUpdate.setParent(null);232 }237 _Thread newParentThread = null; 238 if(newParentThreadId != -1) { 239 newParentThread = _threadRepository.findByPostId(newParentThreadId); 240 if (!newParentThread.getTargetSubject().equals(newTargetSubject)) 241 throw new IncompatiblePostId("Мислењето не припаѓа во специфицираната секција за дискусија."); 242 if (_threadToUpdate.getChildren().contains(newParentThread)) 243 throw new DisallowedOperationException("Мислењето не може да се постави како дете на негово дете (бесконечна рекурзија)"); 244 } 245 _threadToUpdate.setParent(newParentThread); 233 246 234 247 if(_threadToUpdate.getParent() == null) { 235 248 _threadToUpdate.setTitle(newTitle); 236 249 } else { 237 _threadToUpdate.setTitle(null);238 250 _threadToUpdate.setTitle(null); 251 } 239 252 240 253 for(Post p : _threadToUpdate.getChildren()) { … … 244 257 _threadToUpdate.setTimeLastEdited(LocalDateTime.now()); 245 258 _threadRepository.save(_threadToUpdate); 259 return null; 246 260 } 247 261 … … 280 294 if (action.equals("resolve")) report.setResolved(true); 281 295 else if (action.equals("open")) report.setResolved(false); 296 postReportRepository.save(report); 282 297 } 283 298 -
springapp/src/main/java/mk/profesori/springapp/Service/RegistrationService.java
r3b6962d raf801e3 45 45 String tokenToResend = customUserDetailsService 46 46 .createToken(userRepository.findByEmail(request.getEmail()).get()); 47 String link = "http://192.168.0. 19:8080/registration/confirm?token=" + tokenToResend;47 String link = "http://192.168.0.29: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. 19:8080/registration/confirm?token=" + token;68 String link = "http://192.168.0.29:8080/registration/confirm?token=" + token; 69 69 70 70 emailSender.send(request.getEmail(), emailSender.buildEmail(request.getUsername(), link)); -
springapp/src/main/resources/application.properties
r3b6962d raf801e3 1 spring.datasource.url=jdbc:postgresql://localhost:5432/profesori.mk 2 spring.datasource.connectionProperties=useUnicode=true;characterEncoding=utf-8; 1 spring.datasource.url=jdbc:postgresql://localhost:5432/profesorimk 3 2 spring.datasource.username=postgres 4 spring.datasource.password= 1win73373 spring.datasource.password=baz@228 5 4 spring.jpa.hibernate.ddl-auto=update 6 5 spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect 7 6 spring.jpa.show-sql=false 8 7 spring.jpa.properties.hibernate.format_sql=true 9 server.address=192.168.0. 198 server.address=192.168.0.29 10 9 spring.mail.host=localhost 11 10 spring.mail.username=mailuser
Note:
See TracChangeset
for help on using the changeset viewer.